summaryrefslogtreecommitdiff
blob: fb8592df372f710ddda9fd1dc46f67e54bc85feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
diff --git a/src/arping_test.c b/src/arping_test.c
index 438670b..0133fe7 100644
--- a/src/arping_test.c
+++ b/src/arping_test.c
@@ -40,35 +40,10 @@ extern libnet_t* libnet;
 extern int mock_libnet_lo_ok;
 extern int mock_libnet_null_ok;

-struct registered_test {
-        void* fn;
-        const char* name;
-};
-
-static int numtests = 0;
-static struct registered_test test_registry[1024];
-
-static int num_exit_tests = 0;
-static struct registered_test test_exit_registry[1024];
-
 int get_mac_addr(const char *in, char *out);
 void strip_newline(char* s);


-#define MYTEST(a) static void a(int);__attribute__((constructor)) \
-static void cons_##a() {                           \
-                test_registry[numtests].fn = a;    \
-                test_registry[numtests].name = #a; \
-                numtests++;                        \
-} START_TEST(a)
-
-#define MY_EXIT_TEST(a) static void a(int);__attribute__((constructor)) \
-static void cons_##a() {                                      \
-                test_exit_registry[num_exit_tests].fn = a;    \
-                test_exit_registry[num_exit_tests].name = #a; \
-                num_exit_tests++;                             \
-} START_TEST(a)
-
 /**
  *
  */
@@ -236,7 +211,7 @@ dump_packet(uint8_t* packet, int len)
         fprintf(stderr, "\n");
 }

-MYTEST(test_mkpacket)
+START_TEST(test_mkpacket)
 {
         uint8_t correct_packet[] = {
                 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
@@ -261,7 +236,7 @@ MYTEST(test_mkpacket)


 // Received uninteresting packet, should not record anything.
-MYTEST(pingip_uninteresting_packet)
+START_TEST(pingip_uninteresting_packet)
 {
         struct pcap_pkthdr pkthdr;
         uint8_t* packet;
@@ -389,7 +364,7 @@ MYTEST(pingip_uninteresting_packet)
 } END_TEST

 // Received reply that actually matches. Things should happen.
-MYTEST(pingip_interesting_packet)
+START_TEST(pingip_interesting_packet)
 {
         struct pcap_pkthdr pkthdr;
         extern uint8_t srcmac[ETH_ALEN];
@@ -449,7 +424,7 @@ MYTEST(pingip_interesting_packet)
                     "numrecvd not incremented second time");
 } END_TEST

-MYTEST(strip_newline_test)
+START_TEST(strip_newline_test)
 {
         const char *tests[][2] = {
                 {"", ""},
@@ -469,7 +444,7 @@ MYTEST(strip_newline_test)
         }
 } END_TEST

-MYTEST(get_mac_addr_success)
+START_TEST(get_mac_addr_success)
 {
         const char *tests[][2] = {
                 // Null.
@@ -501,7 +476,7 @@ MYTEST(get_mac_addr_success)
         }
 } END_TEST

-MYTEST(get_mac_addr_fail)
+START_TEST(get_mac_addr_fail)
 {
         const char *tests[] = {
                 "",
@@ -517,7 +492,7 @@ MYTEST(get_mac_addr_fail)
         }
 } END_TEST

-MY_EXIT_TEST(libnet_init_bad_nolo)
+START_TEST(libnet_init_bad_nolo)
 {
         // It'll only try lo if named interface fails.
         // So by accepting lo, we make sure it doesn't try lo.
@@ -525,27 +500,28 @@ MY_EXIT_TEST(libnet_init_bad_nolo)
         do_libnet_init("bad", 0);
 } END_TEST

-MY_EXIT_TEST(libnet_init_null_nolo_nonull)
+START_TEST(libnet_init_null_nolo_nonull)
 {
         mock_libnet_lo_ok = 0;
         mock_libnet_null_ok = 0;
         do_libnet_init(NULL, 0);
 } END_TEST

-MYTEST(libnet_init_good)
+START_TEST(libnet_init_good)
 {
         mock_libnet_lo_ok = 0; // Don't even try falling back to lo.
         do_libnet_init("good", 0);
         fail_if(libnet == NULL);
 } END_TEST

-MYTEST(libnet_init_null_nolo)
+START_TEST(libnet_init_null_nolo)
 {
         mock_libnet_lo_ok = 0;
         mock_libnet_null_ok = 1;
         do_libnet_init(NULL, 0);
         fail_if(libnet == NULL);
-} END_TEST
+}
+END_TEST

 static Suite*
 arping_suite(void)
@@ -553,17 +529,34 @@ arping_suite(void)
         int c;
         Suite* s = suite_create("Arping");

-        //tcase_add_checked_fixture (tc_core, setup, teardown);
-        for (c = 0; c < numtests; c++) {
-                TCase *tc_core = tcase_create(test_registry[c].name);
-                tcase_add_test(tc_core, test_registry[c].fn);
-                suite_add_tcase(s, tc_core);
-        }
-        for (c = 0; c < num_exit_tests; c++) {
-                TCase *tc_core = tcase_create(test_exit_registry[c].name);
-                tcase_add_exit_test(tc_core, test_exit_registry[c].fn, 1);
-                suite_add_tcase(s, tc_core);
-        }
+
+        TCase *tc_core;
+
+        // libcheck broke test registries, so have to resort to code duplication. :-(
+        // https://github.com/libcheck/check/pull/158/files
+#define SIGH_LIBCHECK(tn) \
+        tc_core = tcase_create(#tn);   \
+        tcase_add_test(tc_core, tn); \
+        suite_add_tcase(s, tc_core);
+
+        SIGH_LIBCHECK(libnet_init_null_nolo);
+        SIGH_LIBCHECK(test_mkpacket);
+        SIGH_LIBCHECK(pingip_uninteresting_packet);
+        SIGH_LIBCHECK(pingip_interesting_packet);
+        SIGH_LIBCHECK(strip_newline_test);
+        SIGH_LIBCHECK(get_mac_addr_success);
+        SIGH_LIBCHECK(get_mac_addr_fail);
+        SIGH_LIBCHECK(libnet_init_good);
+
+
+#define SIGH_LIBCHECK_EXIT(tn)          \
+        tc_core = tcase_create(#tn);   \
+        tcase_add_exit_test(tc_core, tn, 1);      \
+        suite_add_tcase(s, tc_core);
+
+        SIGH_LIBCHECK_EXIT(libnet_init_bad_nolo);
+        SIGH_LIBCHECK_EXIT(libnet_init_null_nolo_nonull);
+
         return s;
 }

@@ -577,6 +570,7 @@ main()
         number_failed = srunner_ntests_failed (sr);
         srunner_free (sr);
         return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+        return 0;
 }
 /* ---- Emacs Variables ----
  * Local Variables: