root/opal/mca/btl/usnic/btl_usnic_test.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 2014      Cisco Systems, Inc.  All rights reserved.
   3  * $COPYRIGHT$
   4  *
   5  * Additional copyrights may follow
   6  *
   7  * $HEADER$
   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 /* just use check_int_eq for now, no public error code to string routine
  45  * exists (opal_err2str is static) */
  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 /* let us actually paste __LINE__ with other tokens */
  69 #  define USNIC_PASTE(a,b) USNIC_PASTE2(a,b)
  70 #  define USNIC_PASTE2(a,b) a ## b
  71 /* A helper macro to de-clutter test registration. */
  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 /* !OPAL_BTL_USNIC_UNIT_TESTS */
  80 #  define test_out(...) do {} while(0)
  81 #  define USNIC_REGISTER_TEST(name, test_fn, ctx)
  82 #endif
  83 
  84 /* Run all registered tests.  Typically called by an external utility that
  85  * dlopens the usnic BTL shared object.  See run_usnic_tests.c. */
  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 /* should be called once, at component close time */
  93 void opal_btl_usnic_cleanup_tests(void);
  94 
  95 #endif /* BTL_USNIC_TEST_H */

/* [<][>][^][v][top][bottom][index][help] */