1
1

added changes to make more uniform in reporting

This commit was SVN r1910.
Этот коммит содержится в:
Laura Casswell 2004-08-05 19:52:01 +00:00
родитель 06686b08d4
Коммит 8167336e65
2 изменённых файлов: 33 добавлений и 32 удалений

Просмотреть файл

@ -16,14 +16,6 @@
fprintf(error_out, "This is suppossed to throw error \n"); \ fprintf(error_out, "This is suppossed to throw error \n"); \
fprintf(error_out, "================================ \n") fprintf(error_out, "================================ \n")
#define TEST_AND_REPORT(res,str) \
if( res == 0 ) test_success(); \
else test_failure(str);
#define NEG_TEST_AND_REPORT(res,str) \
if( res != 0 ) test_success(); \
else test_failure(str);
static void test_bitmap_set(ompi_bitmap_t *bm); static void test_bitmap_set(ompi_bitmap_t *bm);
static void test_bitmap_clear(ompi_bitmap_t *bm); static void test_bitmap_clear(ompi_bitmap_t *bm);
static void test_bitmap_is_set(ompi_bitmap_t *bm); static void test_bitmap_is_set(ompi_bitmap_t *bm);
@ -130,7 +122,7 @@ void test_bitmap_set(ompi_bitmap_t *bm) {
/* invalid bit */ /* invalid bit */
PRINT_VALID_ERR; PRINT_VALID_ERR;
result = set_bit(bm, -1); result = set_bit(bm, -1);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_set_bit"); TEST_AND_REPORT(result, ERR_CODE,"ompi_bitmap_set_bit");
} }
@ -147,10 +139,10 @@ void test_bitmap_clear(ompi_bitmap_t *bm) {
/* invalid bit */ /* invalid bit */
PRINT_VALID_ERR; PRINT_VALID_ERR;
result = clear_bit(bm, -1); result = clear_bit(bm, -1);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_clear_bit"); TEST_AND_REPORT(result, ERR_CODE,"ompi_bitmap_clear_bit");
PRINT_VALID_ERR; PRINT_VALID_ERR;
result = clear_bit(bm, 142); result = clear_bit(bm, 142);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_clear_bit"); TEST_AND_REPORT(result, ERR_CODE,"ompi_bitmap_clear_bit");
} }
@ -167,13 +159,13 @@ void test_bitmap_is_set(ompi_bitmap_t *bm)
PRINT_VALID_ERR; PRINT_VALID_ERR;
result = is_set_bit(bm, 1122); result = is_set_bit(bm, 1122);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_is_set_bit"); TEST_AND_REPORT(result,ERR_CODE,"ompi_bitmap_is_set_bit");
PRINT_VALID_ERR; PRINT_VALID_ERR;
is_set_bit(bm, -33); is_set_bit(bm, -33);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_is_set_bit"); TEST_AND_REPORT(result,ERR_CODE,"ompi_bitmap_is_set_bit");
PRINT_VALID_ERR; PRINT_VALID_ERR;
is_set_bit(bm, -1); is_set_bit(bm, -1);
NEG_TEST_AND_REPORT(result,"ompi_bitmap_is_set_bit"); TEST_AND_REPORT(result,ERR_CODE,"ompi_bitmap_is_set_bit");
} }
@ -184,52 +176,52 @@ void test_bitmap_find_and_set(ompi_bitmap_t *bm)
ompi_bitmap_clear_all_bits(bm); ompi_bitmap_clear_all_bits(bm);
result = find_and_set(bm, 0); result = find_and_set(bm, 0);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 1); result = find_and_set(bm, 1);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 2); result = find_and_set(bm, 2);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
result = find_and_set(bm, 3); result = find_and_set(bm, 3);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
result = ompi_bitmap_set_bit(bm, 5); result = ompi_bitmap_set_bit(bm, 5);
result = find_and_set(bm, 4); result = find_and_set(bm, 4);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
result = ompi_bitmap_set_bit(bm, 6); result = ompi_bitmap_set_bit(bm, 6);
result = ompi_bitmap_set_bit(bm, 7); result = ompi_bitmap_set_bit(bm, 7);
/* Setting beyond a char boundary */ /* Setting beyond a char boundary */
result = find_and_set(bm, 8); result = find_and_set(bm, 8);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
ompi_bitmap_set_bit(bm, 9); ompi_bitmap_set_bit(bm, 9);
result = find_and_set(bm, 10); result = find_and_set(bm, 10);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
/* Setting beyond the current size of bitmap */ /* Setting beyond the current size of bitmap */
ompi_bitmap_set_all_bits(bm); ompi_bitmap_set_all_bits(bm);
bsize = bm->array_size * SIZE_OF_CHAR; bsize = bm->array_size * SIZE_OF_CHAR;
result = find_and_set(bm, bsize); result = find_and_set(bm, bsize);
TEST_AND_REPORT(result,"ompi_bitmap_find_and_set_first_unset_bit"); TEST_AND_REPORT(result, 0, "ompi_bitmap_find_and_set_first_unset_bit");
} }
void test_bitmap_clear_all(ompi_bitmap_t *bm) void test_bitmap_clear_all(ompi_bitmap_t *bm)
{ {
int result = clear_all(bm); int result = clear_all(bm);
TEST_AND_REPORT(result, " error in ompi_bitmap_clear_all_bits"); TEST_AND_REPORT(result, 0, " error in ompi_bitmap_clear_all_bits");
} }
void test_bitmap_set_all(ompi_bitmap_t *bm) void test_bitmap_set_all(ompi_bitmap_t *bm)
{ {
int result = set_all(bm); int result = set_all(bm);
TEST_AND_REPORT(result, " error in ompi_bitmap_set_ala_bitsl"); TEST_AND_REPORT(result, 0, " error in ompi_bitmap_set_ala_bitsl");
} }
void test_bitmap_find_size(ompi_bitmap_t *bm) void test_bitmap_find_size(ompi_bitmap_t *bm)
{ {
int result = find_size(bm); int result = find_size(bm);
TEST_AND_REPORT(result, " error in ompi_bitmap_size"); TEST_AND_REPORT(result, 0, " error in ompi_bitmap_size");
} }

Просмотреть файл

@ -8,6 +8,8 @@
#include "class/ompi_object.h" #include "class/ompi_object.h"
#include "class/ompi_hash_table.h" #include "class/ompi_hash_table.h"
static FILE *error_out=NULL;
char *num_keys[] = { char *num_keys[] = {
"1234", "1234", "1234", "1234",
"5678", "5678", "5678", "5678",
@ -59,7 +61,7 @@ static void validate_table(ompi_hash_table_t *table, char *keys[], int is_numeri
static void test_htable(ompi_hash_table_t *table) static void test_htable(ompi_hash_table_t *table)
{ {
int j; int j;
printf("\nTesting integer keys...\n"); fprintf(error_out, "\nTesting integer keys...\n");
for ( j = 0; num_keys[j]; j += 2) for ( j = 0; num_keys[j]; j += 2)
{ {
ompi_hash_table_set_value_uint32(table, atoi(num_keys[j]), num_keys[j+1]); ompi_hash_table_set_value_uint32(table, atoi(num_keys[j]), num_keys[j+1]);
@ -70,7 +72,7 @@ static void test_htable(ompi_hash_table_t *table)
ompi_hash_table_remove_all(table); ompi_hash_table_remove_all(table);
test_verify_int(0, ompi_hash_table_get_size(table)); test_verify_int(0, ompi_hash_table_get_size(table));
printf("\nTesting string keys...\n"); fprintf(error_out, "\nTesting string keys...\n");
for ( j = 0; str_keys[j]; j += 2) for ( j = 0; str_keys[j]; j += 2)
{ {
ompi_hash_table_set_value_ptr(table, str_keys[j], strlen(str_keys[j]), str_keys[j+1]); ompi_hash_table_set_value_ptr(table, str_keys[j], strlen(str_keys[j]), str_keys[j+1]);
@ -81,7 +83,7 @@ static void test_htable(ompi_hash_table_t *table)
ompi_hash_table_remove_all(table); ompi_hash_table_remove_all(table);
test_verify_int(0, ompi_hash_table_get_size(table)); test_verify_int(0, ompi_hash_table_get_size(table));
printf("\nTesting collision resolution...\n"); fprintf(error_out, "\nTesting collision resolution...\n");
/* All of the string keys in keys array should /* All of the string keys in keys array should
have the same hash value. */ have the same hash value. */
for ( j = 0; perm_keys[j]; j += 2) for ( j = 0; perm_keys[j]; j += 2)
@ -95,7 +97,7 @@ static void test_htable(ompi_hash_table_t *table)
ompi_hash_table_remove_all(table); ompi_hash_table_remove_all(table);
test_verify_int(0, ompi_hash_table_get_size(table)); test_verify_int(0, ompi_hash_table_get_size(table));
printf("\n\n"); fprintf(error_out, "\n\n");
} }
@ -106,10 +108,10 @@ static void test_dynamic(void)
table = OBJ_NEW(ompi_hash_table_t); table = OBJ_NEW(ompi_hash_table_t);
if ( NULL == table ) if ( NULL == table )
{ {
printf("Error: Unable to create hash table.\n"); fprintf(error_out, "Error: Unable to create hash table.\n");
exit(-1); exit(-1);
} }
printf("Testing with dynamically created table...\n"); fprintf(error_out, "Testing with dynamically created table...\n");
ompi_hash_table_init(table, 4); ompi_hash_table_init(table, 4);
test_htable(table); test_htable(table);
@ -124,7 +126,7 @@ static void test_static(void)
OBJ_CONSTRUCT(&table, ompi_hash_table_t); OBJ_CONSTRUCT(&table, ompi_hash_table_t);
ompi_hash_table_init(&table, 128); ompi_hash_table_init(&table, 128);
printf("Testing with statically created table...\n"); fprintf(error_out, "Testing with statically created table...\n");
test_htable(&table); test_htable(&table);
OBJ_DESTRUCT(&table); OBJ_DESTRUCT(&table);
@ -136,6 +138,13 @@ int main(int argc, char **argv)
/* local variables */ /* local variables */
test_init("ompi_hash_table_t"); test_init("ompi_hash_table_t");
#ifdef STANDALONE
error_out = stderr;
#else
error_out = fopen( "./ompi_hash_table_test_out.txt", "w" );
if( error_out == NULL ) error_out = stderr;
#endif
test_dynamic(); test_dynamic();
test_static(); test_static();