From 7d4431a659781dcd0f36d6cb36379e1e5dab68b0 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 11 Jan 2010 12:50:35 -0800 Subject: [PATCH] New stats output for collection information. --- tests/test.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++-- tests/test.h | 12 ++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/tests/test.c b/tests/test.c index ee6f94dc..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); @@ -143,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++) { @@ -215,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; } @@ -236,9 +276,36 @@ 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) { diff --git a/tests/test.h b/tests/test.h index 7385763d..d5be8c30 100644 --- a/tests/test.h +++ b/tests/test.h @@ -82,9 +82,15 @@ struct world_st { test_callback_create_fn create; test_callback_fn destroy; - /* This is called a the beginning of any collection run. */ + /* This is called a the beginning of any test run. */ test_callback_fn test_startup; + /* This is called a the beginning of any collection run. */ + test_callback_fn collection_startup; + + /* This is called a the beginning of any collection run. */ + test_callback_fn collection_shutdown; + /* This called on a test if the test requires a flush call (the bool is from test_st) */ test_callback_fn flush; @@ -113,6 +119,10 @@ struct world_st { @note world_stats_st is a simple structure for tracking test successes. */ typedef struct { + uint32_t collection_success; + uint32_t collection_skipped; + uint32_t collection_failed; + uint32_t collection_total; uint32_t success; uint32_t skipped; uint32_t failed; -- 2.30.2