File: btl_usnic_test.c

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 (121 lines) | stat: -rw-r--r-- 2,921 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
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
/*
 * Copyright (c) 2014      Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include <stdio.h>

#include "opal/class/opal_list.h"

#include "btl_usnic.h"
#include "btl_usnic_test.h"

int opal_btl_usnic_num_tests_run = 0;
int opal_btl_usnic_num_tests_passed = 0;
int opal_btl_usnic_num_tests_failed = 0;
int opal_btl_usnic_num_tests_skipped = 0;

struct test_info {
    opal_list_item_t li;
    char *name;
    opal_btl_usnic_test_fn_t test_fn;
    void *ctx;
};

#if OPAL_BTL_USNIC_UNIT_TESTS
static bool initialized = false;
static opal_list_t all_tests;

void opal_btl_usnic_cleanup_tests(void)
{
    opal_list_item_t *li;
    struct test_info *info;

    if (initialized) {
        while (NULL != (li = opal_list_remove_first(&all_tests))) {
            info = container_of(li, struct test_info, li);
            free(info);
        }
        OBJ_DESTRUCT(&all_tests);
    }
    initialized = false;
}

static void init_test_infra(void)
{
    if (!initialized) {
        OBJ_CONSTRUCT(&all_tests, opal_list_t);
        initialized = true;
    }
}

void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx)
{
    struct test_info *info = malloc(sizeof(*info));
    assert(info != NULL);

    OBJ_CONSTRUCT(&info->li, opal_list_item_t);

    init_test_infra();

    info->name = strdup(name);
    info->test_fn = test_fn;
    info->ctx = ctx;

    opal_list_append(&all_tests, &info->li);
}

void opal_btl_usnic_run_tests(void)
{
    struct test_info *info;
    enum test_result result;

    if (!OPAL_BTL_USNIC_UNIT_TESTS) {
        test_out("unit tests disabled in this build, doing nothing!\n");
        return;
    }
    test_out("STARTING TESTS\n");

    OPAL_LIST_FOREACH (info, &all_tests, struct test_info) {
        test_out("running test '%s'... ", info->name);
        result = info->test_fn(info->ctx);

        ++opal_btl_usnic_num_tests_run;
        switch (result) {
        case TEST_PASSED:
            ++opal_btl_usnic_num_tests_passed;
            test_out("PASSED\n");
            break;
        case TEST_FAILED:
            ++opal_btl_usnic_num_tests_failed;
            test_out("FAILED\n");
            break;
        case TEST_SKIPPED:
            ++opal_btl_usnic_num_tests_skipped;
            test_out("SKIPPED\n");
            break;
        }
    }

    test_out("FINISHED TESTS (%d passed, %d failed, %d skipped)\n", opal_btl_usnic_num_tests_passed,
             opal_btl_usnic_num_tests_failed, opal_btl_usnic_num_tests_skipped);
}

#else /* !OPAL_BTL_USNIC_UNIT_TESTS */

void opal_btl_usnic_register_test(const char *name, opal_btl_usnic_test_fn_t test_fn, void *ctx)
{
    abort(); /* never should be called */
}

void opal_btl_usnic_run_tests(void)
{
    test_out("unit tests disabled in this build, doing nothing!\n");
    return;
}

#endif /* !OPAL_BTL_USNIC_UNIT_TESTS */