This source file includes following definitions.
- test_init
- test_success
- test_failure
- test_verify_str
- test_verify_int
- test_finalize
- test_comment
- test_fail_stop
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include "opal_config.h"
21 #include <stdlib.h>
22 #include <string.h>
23 #include <assert.h>
24 #include <stdio.h>
25
26 #include "support.h"
27
28
29
30
31
32 static int opal_n_tests;
33 static int opal_n_success;
34 static int opal_n_failures;
35 static char *opal_description;
36
37 void test_init(const char *a)
38 {
39
40 size_t len;
41
42
43 len = strlen(a);
44 opal_description = (char *) malloc(len + 1);
45 assert(opal_description);
46
47 strcpy(opal_description, a);
48
49
50 opal_n_tests = 0;
51 opal_n_success = 0;
52 opal_n_failures = 0;
53
54 return;
55
56 }
57
58
59 void test_success(void)
60 {
61 opal_n_tests++;
62 opal_n_success++;
63 }
64
65
66 void test_failure(const char *a)
67 {
68 opal_n_tests++;
69 opal_n_failures++;
70
71 fprintf(stderr, " Failure : ");
72 fprintf(stderr, "%s", a);
73 fprintf(stderr, "\n");
74 fflush(stderr);
75 }
76
77
78 int test_verify_str(const char *expected_result, const char *test_result)
79 {
80 size_t len_expect, len_result;
81 int return_value;
82
83 return_value = 1;
84 len_expect = expected_result ? strlen(expected_result) : 0;
85 len_result = test_result ? strlen(test_result) : 0;
86
87 if ((!(len_expect == len_result)) ||
88 (0 != strcmp(expected_result, test_result))) {
89 test_failure("Comparison failure");
90 fprintf(stderr, " Expected result: %s\n", expected_result);
91 fprintf(stderr, " Test result: %s\n", test_result);
92 fflush(stderr);
93 return_value = 0;
94 } else {
95 test_success();
96 }
97
98 return return_value;
99 }
100
101
102 int test_verify_int(int expected_result, int test_result)
103 {
104 int return_value;
105
106 return_value = 1;
107 if (expected_result != test_result) {
108 test_failure("Comparison failure");
109 fprintf(stderr, " Expected result: %d\n", expected_result);
110 fprintf(stderr, " Test result: %d\n", test_result);
111 fflush(stderr);
112 return_value = 0;
113 } else {
114 test_success();
115 }
116
117 return return_value;
118 }
119
120
121 int test_finalize(void)
122 {
123 int return_value;
124
125 return_value = 0;
126
127 if (opal_n_tests == opal_n_success) {
128 fprintf(stderr, "SUPPORT: OMPI Test Passed: %s: (%d tests)\n",
129 opal_description, opal_n_tests);
130 fflush(stderr);
131 } else {
132 fprintf(stderr,
133 "SUPPORT: OMPI Test failed: %s (%d of %d failed)\n",
134 opal_description, opal_n_failures, opal_n_tests);
135 fflush(stderr);
136 return_value = 1;
137 }
138
139 if (NULL != opal_description)
140 free(opal_description);
141
142 return return_value;
143 }
144
145
146
147 void test_comment (const char* userstr)
148 {
149 fprintf(stdout, "%s:%s\n", opal_description, userstr);
150 }
151
152
153 void test_fail_stop(const char *msg, int status)
154 {
155 test_failure(msg);
156 test_finalize();
157 exit(status);
158 }