#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <time.h>
#include <fnmatch.h>
-#include "server.h"
+#include <stdint.h>
#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);
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;
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:
fprintf(stderr, "Unknown return value\n");
abort();
}
-
}
void create_core(void)
{
- if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL && fork() == 0)
- abort();
+ if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL)
+ {
+ pid_t pid= fork();
+
+ if (pid == 0)
+ {
+ abort();
+ }
+ else
+ {
+ while (waitpid(pid, NULL, 0) != pid)
+ {
+ ;
+ }
+ }
+ }
}
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];
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++)
{
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)
}
- if (next->pre)
+ if (next->pre && world.runner->pre)
{
return_code= world.runner->pre(next->pre, world_ptr);
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)
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;
}
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);
- return 0;
+ return stats.failed == 0 ? 0 : 1;
}