File: btl_usnic_test.h

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (87 lines) | stat: -rw-r--r-- 4,607 bytes parent folder | download | duplicates (5)
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
/*
 * Copyright (c) 2014      Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#ifndef BTL_USNIC_TEST_H
#define BTL_USNIC_TEST_H

#include "opal_config.h"

typedef int (*opal_btl_usnic_test_fn_t)(void *ctx);

#if OPAL_BTL_USNIC_UNIT_TESTS
#    define test_out(...) fprintf(stderr, __VA_ARGS__)
#    define check(a)                                                             \
        do {                                                                     \
            if (!(a)) {                                                          \
                test_out("%s:%d: check failed, '%s'\n", __func__, __LINE__, #a); \
                return TEST_FAILED;                                              \
            }                                                                    \
        } while (0)
#    define check_str_eq(a, b)                                                                   \
        do {                                                                                     \
            const char *a_ = (a);                                                                \
            const char *b_ = (b);                                                                \
            if (0 != strcmp(a_, b_)) {                                                           \
                test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", __func__, __LINE__, a_, b_); \
                return TEST_FAILED;                                                              \
            }                                                                                    \
        } while (0)
#    define check_int_eq(got, expected)                                                         \
        do {                                                                                    \
            if ((got) != (expected)) {                                                          \
                test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", __func__, __LINE__, \
                         #got, #expected, (got));                                               \
                return TEST_FAILED;                                                             \
            }                                                                                   \
        } while (0)
/* just use check_int_eq for now, no public error code to string routine
 * exists (opal_err2str is static) */
#    define check_err_code(got, expected) check_int_eq(got, expected)
#    define check_msg(a, msg)                                                                  \
        do {                                                                                   \
            if (!(a)) {                                                                        \
                test_out("%s:%d: check failed, \"%s\" (%s)\n", __func__, __LINE__, #a, (msg)); \
                return TEST_FAILED;                                                            \
            }                                                                                  \
        } while (0)

extern int opal_btl_usnic_num_tests_run;
extern int opal_btl_usnic_num_tests_passed;
extern int opal_btl_usnic_num_tests_failed;
extern int opal_btl_usnic_num_tests_skipped;

enum test_result { TEST_PASSED = 0, TEST_FAILED, TEST_SKIPPED };

/* let us actually paste __LINE__ with other tokens */
#    define USNIC_PASTE(a, b)  USNIC_PASTE2(a, b)
#    define USNIC_PASTE2(a, b) a##b
/* A helper macro to de-clutter test registration. */
#    define USNIC_REGISTER_TEST(name, test_fn, ctx)                                               \
        __attribute__((__constructor__)) static void USNIC_PASTE(usnic_reg_ctor_, __LINE__)(void) \
        {                                                                                         \
            opal_btl_usnic_register_test(name, test_fn, ctx);                                     \
        }

#else /* !OPAL_BTL_USNIC_UNIT_TESTS */
#    define test_out(...) \
        do {              \
        } while (0)
#    define USNIC_REGISTER_TEST(name, test_fn, ctx)
#endif

/* Run all registered tests.  Typically called by an external utility that
 * dlopens the usnic BTL shared object.  See run_usnic_tests.c. */
void opal_btl_usnic_run_tests(void);

void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx);

/* should be called once, at component close time */
void opal_btl_usnic_cleanup_tests(void);

#endif /* BTL_USNIC_TEST_H */