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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "support.h"
/**
* A testing support library to provide uniform reporting output
*/
static int opal_n_tests;
static int opal_n_success;
static int opal_n_failures;
static char *opal_description;
void test_init(const char *a)
{
/* local variables */
size_t len;
/* save the descriptive string */
len = strlen(a);
opal_description = (char *) malloc(len + 1);
assert(opal_description);
strcpy(opal_description, a);
/* initialize counters */
opal_n_tests = 0;
opal_n_success = 0;
opal_n_failures = 0;
return;
}
void test_success(void)
{
opal_n_tests++;
opal_n_success++;
}
void test_failure(const char *a)
{
opal_n_tests++;
opal_n_failures++;
fprintf(stderr, " Failure : ");
fprintf(stderr, "%s", a);
fprintf(stderr, "\n");
fflush(stderr);
}
int test_verify_str(const char *expected_result, const char *test_result)
{
size_t len_expect, len_result;
int return_value;
return_value = 1;
len_expect = expected_result ? strlen(expected_result) : 0;
len_result = test_result ? strlen(test_result) : 0;
if ((!(len_expect == len_result)) ||
(0 != strcmp(expected_result, test_result))) {
test_failure("Comparison failure");
fprintf(stderr, " Expected result: %s\n", expected_result);
fprintf(stderr, " Test result: %s\n", test_result);
fflush(stderr);
return_value = 0;
} else {
test_success();
}
return return_value;
}
int test_verify_int(int expected_result, int test_result)
{
int return_value;
return_value = 1;
if (expected_result != test_result) {
test_failure("Comparison failure");
fprintf(stderr, " Expected result: %d\n", expected_result);
fprintf(stderr, " Test result: %d\n", test_result);
fflush(stderr);
return_value = 0;
} else {
test_success();
}
return return_value;
}
int test_finalize(void)
{
int return_value;
return_value = 0;
if (opal_n_tests == opal_n_success) {
fprintf(stderr, "SUPPORT: OMPI Test Passed: %s: (%d tests)\n",
opal_description, opal_n_tests);
fflush(stderr);
} else {
fprintf(stderr,
"SUPPORT: OMPI Test failed: %s (%d of %d failed)\n",
opal_description, opal_n_failures, opal_n_tests);
fflush(stderr);
return_value = 1;
}
if (NULL != opal_description)
free(opal_description);
return return_value;
}
/* note this is for additional output that does NOT go to STDERR but STDOUT */
void test_comment (const char* userstr)
{
fprintf(stdout, "%s:%s\n", opal_description, userstr);
}
void test_fail_stop(const char *msg, int status)
{
test_failure(msg);
test_finalize();
exit(status);
}
|