X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ftest.c;h=ff6bca680966e1125041e57a6efa737ba415a1b8;hb=7d4431a659781dcd0f36d6cb36379e1e5dab68b0;hp=a10cc47655097d86383328880d5257e421c8d02b;hpb=9ce1a0267694910094f492bd204d2166290a2427;p=m6w6%2Flibmemcached diff --git a/tests/test.c b/tests/test.c index a10cc476..ff6bca68 100644 --- a/tests/test.c +++ b/tests/test.c @@ -19,11 +19,18 @@ #include #include #include +#include #include "test.h" static void world_stats_print(world_stats_st *stats) { + fputc('\n', stderr); + fprintf(stderr, "Total Collections\t\t\t\t%u\n", stats->collection_total); + fprintf(stderr, "\tFailed Collections\t\t\t%u\n", stats->collection_failed); + fprintf(stderr, "\tSkipped Collections\t\t\t%u\n", stats->collection_skipped); + fprintf(stderr, "\tSucceeded Collections\t\t%u\n", stats->collection_success); + fputc('\n', stderr); fprintf(stderr, "Total\t\t\t\t%u\n", stats->total); fprintf(stderr, "\tFailed\t\t\t%u\n", stats->failed); fprintf(stderr, "\tSkipped\t\t\t%u\n", stats->skipped); @@ -32,7 +39,7 @@ static void world_stats_print(world_stats_st *stats) static long int timedif(struct timeval a, struct timeval b) { - register int us, s; + long us, s; us = (int)(a.tv_usec - b.tv_usec); us /= 1000; @@ -57,7 +64,6 @@ const char *test_strerror(test_return_t code) fprintf(stderr, "Unknown return value\n"); abort(); } - } void create_core(void) @@ -125,9 +131,16 @@ int main(int argc, char *argv[]) collection= world.collections; if (world.create) - world_ptr= world.create(); + { + test_return_t error; + world_ptr= world.create(&error); + if (error != TEST_SUCCESS) + exit(1); + } else + { world_ptr= NULL; + } if (argc > 1) collection_to_run= argv[1]; @@ -137,13 +150,41 @@ int main(int argc, char *argv[]) for (next= collection; next->name; next++) { + test_return_t collection_rc= TEST_SUCCESS; test_st *run; + bool failed= false; + bool skipped= false; run= next->tests; if (collection_to_run && fnmatch(collection_to_run, next->name, 0)) continue; - fprintf(stderr, "\n%s\n\n", next->name); + stats.collection_total++; + + if (world.collection_startup) + { + collection_rc= world.test_startup(world_ptr); + } + + switch (collection_rc) + { + case TEST_SUCCESS: + fprintf(stderr, "\n%s\n\n", next->name); + break; + case TEST_FAILURE: + fprintf(stderr, "\n%s [ failed ]\n\n", next->name); + stats.failed++; + continue; + case TEST_SKIPPED: + fprintf(stderr, "\n%s [ skipping ]\n\n", next->name); + stats.skipped++; + continue; + case TEST_MEMORY_ALLOCATION_FAILURE: + case TEST_MAXIMUM_RETURN: + default: + assert(0); + break; + } for (x= 0; run->name; run++) { @@ -155,9 +196,9 @@ int main(int argc, char *argv[]) fprintf(stderr, "Testing %s", run->name); - if (world.collection_startup) + if (world.test_startup) { - world.collection_startup(world_ptr); + world.test_startup(world_ptr); } if (run->requires_flush && world.flush) @@ -209,13 +250,18 @@ error: break; case TEST_FAILURE: stats.failed++; + failed= true; break; case TEST_SKIPPED: stats.skipped++; + skipped= true; break; case TEST_MEMORY_ALLOCATION_FAILURE: + fprintf(stderr, "Exhausted memory, quitting\n"); + abort(); case TEST_MAXIMUM_RETURN: default: + assert(0); // Coding error. break; } @@ -230,12 +276,48 @@ error: break; } } + + if (failed) + { + stats.collection_failed++; + } + + if (skipped) + { + stats.collection_skipped++; + } + + if (! failed && ! skipped) + { + stats.collection_success++; + } + + if (world.collection_shutdown) + { + world.collection_shutdown(world_ptr); + } } - fprintf(stderr, "All tests completed successfully\n\n"); + if (stats.collection_failed || stats.collection_skipped) + { + fprintf(stderr, "Some test failures and/or skipped test occurred.\n\n"); + } + else + { + fprintf(stderr, "All tests completed successfully\n\n"); + } if (world.destroy) - world.destroy(world_ptr); + { + test_return_t error; + error= world.destroy(world_ptr); + + if (error != TEST_SUCCESS) + { + fprintf(stderr, "Failure during shutdown.\n"); + stats.failed++; // We do this to make our exit code return 1 + } + } world_stats_print(&stats);