git: c87ff7f5c659 - stable/13 - kqueue tests: Add file and line info to some test failure output

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 08 Jun 2022 00:44:57 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=c87ff7f5c659ecab2c7092dd81c4a981d001f9f4

commit c87ff7f5c659ecab2c7092dd81c4a981d001f9f4
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-05-25 00:14:20 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-06-08 00:42:18 +0000

    kqueue tests: Add file and line info to some test failure output
    
    This brings us slightly closer to upstream and is useful when debugging
    test failures.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit c728c56c870abe230e45cee5c477f0d890ebacef)
---
 tests/sys/kqueue/libkqueue/common.h |  7 ++++---
 tests/sys/kqueue/libkqueue/main.c   | 10 +++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/tests/sys/kqueue/libkqueue/common.h b/tests/sys/kqueue/libkqueue/common.h
index d621a8bf1e00..58074b61a555 100644
--- a/tests/sys/kqueue/libkqueue/common.h
+++ b/tests/sys/kqueue/libkqueue/common.h
@@ -47,8 +47,8 @@ char * kevent_to_str(struct kevent *);
 struct kevent * kevent_get(int);
 struct kevent * kevent_get_timeout(int, int);
 
-
-void kevent_cmp(struct kevent *, struct kevent *);
+#define kevent_cmp(a,b) _kevent_cmp(a,b, __FILE__, __LINE__)
+void _kevent_cmp(struct kevent *expected, struct kevent *got, const char *file, int line);
 
 void
 kevent_add(int kqfd, struct kevent *kev, 
@@ -70,7 +70,8 @@ kevent_add(int kqfd, struct kevent *kev,
 } while (0);
 
 /* Checks if any events are pending, which is an error. */
-void test_no_kevents(void);
+#define test_no_kevents() _test_no_kevents(__FILE__, __LINE__)
+void _test_no_kevents(const char *, int);
 void test_no_kevents_quietly(void);
 
 void test_begin(const char *);
diff --git a/tests/sys/kqueue/libkqueue/main.c b/tests/sys/kqueue/libkqueue/main.c
index 5b37b0f1fb63..3e586faf7380 100644
--- a/tests/sys/kqueue/libkqueue/main.c
+++ b/tests/sys/kqueue/libkqueue/main.c
@@ -27,7 +27,7 @@ static int testnum = 1;
 
 /* Checks if any events are pending, which is an error. */
 void
-test_no_kevents(void)
+_test_no_kevents(const char *file, int line)
 {
     int nfds;
     struct timespec timeo;
@@ -38,7 +38,7 @@ test_no_kevents(void)
     memset(&timeo, 0, sizeof(timeo));
     nfds = kevent(kqfd, NULL, 0, &kev, 1, &timeo);
     if (nfds != 0) {
-        puts("\nUnexpected event:");
+        printf("\n[%s:%d]: Unexpected event:", file, line);
         kev_str = kevent_to_str(&kev);
         puts(kev_str);
         free(kev_str);
@@ -239,7 +239,7 @@ kevent_add(int fd, struct kevent *kev,
 }
 
 void
-kevent_cmp(struct kevent *k1, struct kevent *k2)
+_kevent_cmp(struct kevent *k1, struct kevent *k2, const char *file, int line)
 {
     char *kev1_str;
     char *kev2_str;
@@ -258,8 +258,8 @@ kevent_cmp(struct kevent *k1, struct kevent *k2)
       k1->ext[0] != k2->ext[2] || k1->ext[0] != k2->ext[3]) {
         kev1_str = kevent_to_str(k1);
         kev2_str = kevent_to_str(k2);
-        printf("kevent_cmp: mismatch:\n  %s !=\n  %s\n", 
-               kev1_str, kev2_str);
+        printf("[%s:%d]: kevent_cmp: mismatch:\n  %s !=\n  %s\n",
+	        file, line, kev1_str, kev2_str);
         free(kev1_str);
         free(kev2_str);
         abort();