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

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

DEFINITIONS

This source file includes following definitions.
  1. opal_btl_usnic_cleanup_tests
  2. init_test_infra
  3. opal_btl_usnic_register_test
  4. opal_btl_usnic_run_tests
  5. opal_btl_usnic_register_test
  6. opal_btl_usnic_run_tests

   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 #include <stdio.h>
  11 
  12 #include "opal/class/opal_list.h"
  13 
  14 #include "btl_usnic.h"
  15 #include "btl_usnic_test.h"
  16 
  17 int opal_btl_usnic_num_tests_run = 0;
  18 int opal_btl_usnic_num_tests_passed = 0;
  19 int opal_btl_usnic_num_tests_failed = 0;
  20 int opal_btl_usnic_num_tests_skipped = 0;
  21 
  22 struct test_info {
  23     opal_list_item_t li;
  24     char *name;
  25     opal_btl_usnic_test_fn_t test_fn;
  26     void *ctx;
  27 };
  28 
  29 #if OPAL_BTL_USNIC_UNIT_TESTS
  30 static bool initialized = false;
  31 static opal_list_t all_tests;
  32 
  33 void opal_btl_usnic_cleanup_tests(void)
  34 {
  35     opal_list_item_t *li;
  36     struct test_info *info;
  37 
  38     if (initialized) {
  39         while (NULL != (li = opal_list_remove_first(&all_tests))) {
  40             info = container_of(li, struct test_info, li);
  41             free(info);
  42         }
  43         OBJ_DESTRUCT(&all_tests);
  44     }
  45     initialized = false;
  46 }
  47 
  48 static void init_test_infra(void)
  49 {
  50     if (!initialized) {
  51         OBJ_CONSTRUCT(&all_tests, opal_list_t);
  52         initialized = true;
  53     }
  54 }
  55 
  56 void opal_btl_usnic_register_test(const char *name,
  57                                   opal_btl_usnic_test_fn_t test_fn,
  58                                   void *ctx)
  59 {
  60     struct test_info *info = malloc(sizeof(*info));
  61     assert(info != NULL);
  62 
  63     OBJ_CONSTRUCT(&info->li, opal_list_item_t);
  64 
  65     init_test_infra();
  66 
  67     info->name = strdup(name);
  68     info->test_fn = test_fn;
  69     info->ctx = ctx;
  70 
  71     opal_list_append(&all_tests, &info->li);
  72 }
  73 
  74 void opal_btl_usnic_run_tests(void)
  75 {
  76     struct test_info *info;
  77     enum test_result result;
  78 
  79     if (!OPAL_BTL_USNIC_UNIT_TESTS) {
  80         test_out("unit tests disabled in this build, doing nothing!\n");
  81         return;
  82     }
  83     test_out("STARTING TESTS\n");
  84 
  85     OPAL_LIST_FOREACH(info, &all_tests, struct test_info) {
  86         test_out("running test '%s'... ", info->name);
  87         result = info->test_fn(info->ctx);
  88 
  89         ++opal_btl_usnic_num_tests_run;
  90         switch (result) {
  91             case TEST_PASSED:
  92                 ++opal_btl_usnic_num_tests_passed;
  93                 test_out("PASSED\n");
  94                 break;
  95             case TEST_FAILED:
  96                 ++opal_btl_usnic_num_tests_failed;
  97                 test_out("FAILED\n");
  98                 break;
  99             case TEST_SKIPPED:
 100                 ++opal_btl_usnic_num_tests_skipped;
 101                 test_out("SKIPPED\n");
 102                 break;
 103         }
 104     }
 105 
 106     test_out("FINISHED TESTS (%d passed, %d failed, %d skipped)\n",
 107              opal_btl_usnic_num_tests_passed,
 108              opal_btl_usnic_num_tests_failed,
 109              opal_btl_usnic_num_tests_skipped);
 110 }
 111 
 112 #else /* !OPAL_BTL_USNIC_UNIT_TESTS */
 113 
 114 void opal_btl_usnic_register_test(const char *name,
 115                                   opal_btl_usnic_test_fn_t test_fn,
 116                                   void *ctx)
 117 {
 118     abort(); /* never should be called */
 119 }
 120 
 121 void opal_btl_usnic_run_tests(void)
 122 {
 123     test_out("unit tests disabled in this build, doing nothing!\n");
 124     return;
 125 }
 126 
 127 #endif /* !OPAL_BTL_USNIC_UNIT_TESTS */

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