X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ftest.c;h=ff6bca680966e1125041e57a6efa737ba415a1b8;hb=7d4431a659781dcd0f36d6cb36379e1e5dab68b0;hp=793bcbd7264d08af68112aefa033e4e931af0980;hpb=c47100252c635d42edd69c3a99dd63b665b01e45;p=m6w6%2Flibmemcached diff --git a/tests/test.c b/tests/test.c index 793bcbd7..ff6bca68 100644 --- a/tests/test.c +++ b/tests/test.c @@ -19,12 +19,18 @@ #include #include #include -#include "server.h" +#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); @@ -33,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; @@ -42,7 +48,7 @@ static long int timedif(struct timeval a, struct timeval b) return s + us; } -static const char *test_strerror(test_return_t code) +const char *test_strerror(test_return_t code) { switch (code) { case TEST_SUCCESS: @@ -58,7 +64,6 @@ static const char *test_strerror(test_return_t code) fprintf(stderr, "Unknown return value\n"); abort(); } - } void create_core(void) @@ -126,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]; @@ -138,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++) { @@ -156,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) @@ -172,7 +212,7 @@ int main(int argc, char *argv[]) } - if (next->pre) + if (next->pre && world.runner->pre) { return_code= world.runner->pre(next->pre, world_ptr); @@ -187,9 +227,9 @@ int main(int argc, char *argv[]) gettimeofday(&end_time, NULL); load_time= timedif(end_time, start_time); - if (next->post) + if (next->post && world.runner->post) { - (void) world.runner->pre(next->pre, world_ptr); + (void) world.runner->post(next->post, world_ptr); } if (world.post_run) @@ -210,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; } @@ -231,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);