1
2
3
4
5
6
7
8
9
10 #ifndef BTL_USNIC_TEST_H
11 #define BTL_USNIC_TEST_H
12
13 #include "opal_config.h"
14
15 typedef int (*opal_btl_usnic_test_fn_t)(void *ctx);
16
17 #if OPAL_BTL_USNIC_UNIT_TESTS
18 # define test_out(...) fprintf(stderr, __VA_ARGS__)
19 # define check(a) \
20 do { \
21 if (!(a)) { \
22 test_out("%s:%d: check failed, '%s'\n", __func__, __LINE__, #a); \
23 return TEST_FAILED; \
24 } \
25 } while (0)
26 # define check_str_eq(a,b) \
27 do { \
28 const char *a_ = (a); \
29 const char *b_ = (b); \
30 if (0 != strcmp(a_,b_)) { \
31 test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", \
32 __func__, __LINE__, a_, b_); \
33 return TEST_FAILED; \
34 } \
35 } while (0)
36 # define check_int_eq(got, expected) \
37 do { \
38 if ((got) != (expected)) { \
39 test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", \
40 __func__, __LINE__, #got, #expected, (got)); \
41 return TEST_FAILED; \
42 } \
43 } while (0)
44
45
46 # define check_err_code(got, expected) \
47 check_int_eq(got, expected)
48 # define check_msg(a, msg) \
49 do { \
50 if (!(a)) { \
51 test_out("%s:%d: check failed, \"%s\" (%s)\n", \
52 __func__, __LINE__, #a, (msg)); \
53 return TEST_FAILED; \
54 } \
55 } while (0)
56
57 extern int opal_btl_usnic_num_tests_run;
58 extern int opal_btl_usnic_num_tests_passed;
59 extern int opal_btl_usnic_num_tests_failed;
60 extern int opal_btl_usnic_num_tests_skipped;
61
62 enum test_result {
63 TEST_PASSED = 0,
64 TEST_FAILED,
65 TEST_SKIPPED
66 };
67
68
69 # define USNIC_PASTE(a,b) USNIC_PASTE2(a,b)
70 # define USNIC_PASTE2(a,b) a ## b
71
72 # define USNIC_REGISTER_TEST(name, test_fn, ctx) \
73 __attribute__((__constructor__)) \
74 static void USNIC_PASTE(usnic_reg_ctor_,__LINE__)(void) \
75 { \
76 opal_btl_usnic_register_test(name, test_fn, ctx); \
77 } \
78
79 #else
80 # define test_out(...) do {} while(0)
81 # define USNIC_REGISTER_TEST(name, test_fn, ctx)
82 #endif
83
84
85
86 void opal_btl_usnic_run_tests(void);
87
88 void opal_btl_usnic_register_test(const char *name,
89 opal_btl_usnic_test_fn_t test_fn,
90 void *ctx);
91
92
93 void opal_btl_usnic_cleanup_tests(void);
94
95 #endif