diff options
author | Trond Norbye <trond.norbye@gmail.com> | 2011-07-07 11:30:55 +0200 |
---|---|---|
committer | Trond Norbye <trond.norbye@gmail.com> | 2011-07-11 16:22:38 +0200 |
commit | 3ec9a61a4d66525605d481df604a0cdfd5525a92 (patch) | |
tree | d161a57a65ee9e9f173a7449b5704842ed024ff1 | |
parent | 5eaf559e3417d63312eb67bcec5f0640dd47d858 (diff) | |
download | memcached-3ec9a61a4d66525605d481df604a0cdfd5525a92.tar.gz |
Extend the test api with prepare and cleanup
You might want to run code before and after the engine is started or
stopped. These entry functions allows you to do so.
-rw-r--r-- | include/memcached/engine_testapp.h | 20 | ||||
-rw-r--r-- | programs/engine_testapp.c | 38 |
2 files changed, 45 insertions, 13 deletions
diff --git a/include/memcached/engine_testapp.h b/include/memcached/engine_testapp.h index 9a56f4b..caa4785 100644 --- a/include/memcached/engine_testapp.h +++ b/include/memcached/engine_testapp.h @@ -33,13 +33,29 @@ struct test_harness { void (*time_travel)(int offset); }; -typedef struct test { +typedef struct test engine_test_t; + +struct test { const char *name; enum test_result(*tfun)(ENGINE_HANDLE *, ENGINE_HANDLE_V1 *); bool(*test_setup)(ENGINE_HANDLE *, ENGINE_HANDLE_V1 *); bool(*test_teardown)(ENGINE_HANDLE *, ENGINE_HANDLE_V1 *); const char *cfg; -} engine_test_t; + /** + * You might want to prepare the environment for running + * the test <em>before</em> the engine is loaded. + * @param test the test about to be started + * @return An appropriate "status" code + */ + enum test_result (*prepare)(engine_test_t *test); + + /** + * You might want to clean up after the test + * @param test the test that just finished + * @param th result of the test + */ + void (*cleanup)(engine_test_t *test, enum test_result result); +}; typedef engine_test_t* (*GET_TESTS)(void); diff --git a/programs/engine_testapp.c b/programs/engine_testapp.c index cd2e9d3..dded5ae 100644 --- a/programs/engine_testapp.c +++ b/programs/engine_testapp.c @@ -647,21 +647,37 @@ static enum test_result run_test(engine_test_t test, const char *engine, const c pid_t pid = fork(); if (pid == 0) { #endif - /* Start the engines and go */ - start_your_engines(engine, test.cfg ? test.cfg : default_cfg, true); - if (test.test_setup != NULL) { - if (!test.test_setup(handle, handle_v1)) { - fprintf(stderr, "Failed to run setup for test %s\n", test.name); - return FAIL; + if (test.prepare != NULL) { + if ((ret = test.prepare(&test)) == SUCCESS) { + ret = PENDING; } } - ret = test.tfun(handle, handle_v1); - if (test.test_teardown != NULL) { - if (!test.test_teardown(handle, handle_v1)) { - fprintf(stderr, "WARNING: Failed to run teardown for test %s\n", test.name); + + if (ret == PENDING) { + /* Start the engines and go */ + start_your_engines(engine, test.cfg ? test.cfg : default_cfg, true); + if (test.test_setup != NULL) { + if (!test.test_setup(handle, handle_v1)) { + fprintf(stderr, "Failed to run setup for test %s\n", test.name); +#if !defined(USE_GCOV) && !defined(WIN32) + exit((int)ret); +#else + return FAIL; +#endif + } + } + ret = test.tfun(handle, handle_v1); + if (test.test_teardown != NULL) { + if (!test.test_teardown(handle, handle_v1)) { + fprintf(stderr, "WARNING: Failed to run teardown for test %s\n", test.name); + } + } + destroy_engine(false); + + if (test.cleanup) { + test.cleanup(&test, ret); } } - destroy_engine(false); #if !defined(USE_GCOV) && !defined(WIN32) exit((int)ret); } else if (pid == (pid_t)-1) { |