From 02fa1c85c842e175225f74b0e213a5600d4c03cf Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 15 Jan 2010 13:26:02 -0800 Subject: [PATCH] Refactor test framework to run pre/post just once. --- libmemcached/common.h | 2 +- tests/libmemcached_world.h | 32 ++++++++++++++++++++++++++++---- tests/mem_functions.c | 3 ++- tests/test.c | 33 +++++++++++++++++++++------------ 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/libmemcached/common.h b/libmemcached/common.h index 6dc6936f..895c5a40 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -172,7 +172,7 @@ static inline memcached_return_t memcached_validate_key_length(size_t key_length on the system it returns false but sets errno to 0. Otherwise on failure errno is set. */ -static inline memcached_ternary_t test_cork(memcached_server_st *ptr, bool enable) +static inline memcached_ternary_t test_cork(memcached_server_st *ptr, int enable) { #ifdef CORK if (ptr->type != MEMCACHED_CONNECTION_TCP) diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 4652b246..45927a23 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -149,6 +149,30 @@ static test_return_t _runner_default(libmemcached_test_callback_fn func, libmemc } } +static test_return_t _pre_runner_default(libmemcached_test_callback_fn func, libmemcached_test_container_st *container) +{ + if (func) + { + return func(container->parent); + } + else + { + return TEST_SUCCESS; + } +} + +static test_return_t _post_runner_default(libmemcached_test_callback_fn func, libmemcached_test_container_st *container) +{ + if (func) + { + return func(container->parent); + } + else + { + return TEST_SUCCESS; + } +} + #ifdef __cplusplus } #endif @@ -156,17 +180,17 @@ static test_return_t _runner_default(libmemcached_test_callback_fn func, libmemc #ifdef __cplusplus static world_runner_st defualt_libmemcached_runner= { + reinterpret_cast(_pre_runner_default), reinterpret_cast(_runner_default), - reinterpret_cast(_runner_default), - reinterpret_cast(_runner_default) + reinterpret_cast(_post_runner_default) }; #else static world_runner_st defualt_libmemcached_runner= { + (test_callback_runner_fn)_pre_runner_default, (test_callback_runner_fn)_runner_default, - (test_callback_runner_fn)_runner_default, - (test_callback_runner_fn)_runner_default + (test_callback_runner_fn)_post_runner_default }; #endif diff --git a/tests/mem_functions.c b/tests/mem_functions.c index fa1ecbd8..6fa1995a 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -4893,8 +4893,9 @@ static test_return_t hsieh_avaibility_test (memcached_st *memc) expected_rc= MEMCACHED_SUCCESS; #endif memcached_return_t rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, - (uint64_t)MEMCACHED_HASH_HSIEH); + (uint64_t)MEMCACHED_HASH_HSIEH); test_true(rc == expected_rc); + return TEST_SUCCESS; } diff --git a/tests/test.c b/tests/test.c index 903ad4ee..b177f64f 100644 --- a/tests/test.c +++ b/tests/test.c @@ -186,6 +186,15 @@ int main(int argc, char *argv[]) collection_rc= world.collection.startup(world_ptr); + if (collection_rc != TEST_SUCCESS) + goto skip_pre; + + if (next->pre) + { + collection_rc= world.runner->pre(next->pre, world_ptr); + } + +skip_pre: switch (collection_rc) { case TEST_SUCCESS: @@ -193,12 +202,12 @@ int main(int argc, char *argv[]) break; case TEST_FAILURE: fprintf(stderr, "\n%s [ failed ]\n\n", next->name); - stats.failed++; - continue; + stats.collection_failed++; + goto cleanup; case TEST_SKIPPED: fprintf(stderr, "\n%s [ skipping ]\n\n", next->name); - stats.skipped++; - continue; + stats.collection_skipped++; + goto cleanup; case TEST_MEMORY_ALLOCATION_FAILURE: case TEST_MAXIMUM_RETURN: default: @@ -206,6 +215,7 @@ int main(int argc, char *argv[]) break; } + for (x= 0; run->name; run++) { struct timeval start_time, end_time; @@ -234,6 +244,7 @@ int main(int argc, char *argv[]) // Runner code { +#if 0 if (next->pre && world.runner->pre) { return_code= world.runner->pre(next->pre, world_ptr); @@ -243,16 +254,19 @@ int main(int argc, char *argv[]) goto error; } } +#endif gettimeofday(&start_time, NULL); return_code= world.runner->run(run->test_fn, world_ptr); gettimeofday(&end_time, NULL); load_time= timedif(end_time, start_time); +#if 0 if (next->post && world.runner->post) { (void) world.runner->post(next->post, world_ptr); } +#endif } if (world.test.post_run) @@ -260,7 +274,6 @@ int main(int argc, char *argv[]) world.test.post_run(world_ptr); } -error: stats.total++; fprintf(stderr, "\t\t\t\t\t"); @@ -300,20 +313,16 @@ error: } } - if (failed) - { - stats.collection_failed++; - } - - if (skipped) + if (next->post && world.runner->post) { - stats.collection_skipped++; + (void) world.runner->post(next->post, world_ptr); } if (! failed && ! skipped) { stats.collection_success++; } +cleanup: world.collection.shutdown(world_ptr); } -- 2.30.2