From d38a24defa282f8c05835c16ad1633ffb528d82c Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 11 Jan 2010 15:28:18 -0800 Subject: [PATCH] Updated test framework. --- tests/include.am | 77 +++++++++++++++++---------- tests/libmemcached_world.h | 33 ++++++++++-- tests/{function.c => mem_functions.c} | 3 ++ 3 files changed, 79 insertions(+), 34 deletions(-) rename tests/{function.c => mem_functions.c} (99%) diff --git a/tests/include.am b/tests/include.am index b13674ec..259da130 100644 --- a/tests/include.am +++ b/tests/include.am @@ -4,37 +4,41 @@ TESTS_LDADDS = libmemcached/libmemcached.la +VALGRIND_COMMAND= $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes + +DEBUG_COMMAND= $(LIBTOOL) --mode=execute gdb + if BUILD_LIBMEMCACHEDUTIL TESTS_LDADDS+= libmemcached/libmemcachedutil.la endif EXTRA_DIST+= \ - tests/r/memcat.res \ - tests/r/memcp.res \ - tests/r/memrm.res \ - tests/r/memslap.res \ - tests/r/memstat.res \ - tests/t/memcat.test \ - tests/t/memcp.test \ - tests/t/memrm.test \ - tests/t/memslap.test \ - tests/t/memstat.test + tests/r/memcat.res \ + tests/r/memcp.res \ + tests/r/memrm.res \ + tests/r/memslap.res \ + tests/r/memstat.res \ + tests/t/memcat.test \ + tests/t/memcp.test \ + tests/t/memrm.test \ + tests/t/memslap.test \ + tests/t/memstat.test noinst_HEADERS+= \ - tests/hash_results.h \ - tests/ketama_test_cases.h \ - tests/ketama_test_cases_spy.h \ - tests/libmemcached_world.h \ - tests/server.h \ - tests/test.h + tests/hash_results.h \ + tests/ketama_test_cases.h \ + tests/ketama_test_cases_spy.h \ + tests/libmemcached_world.h \ + tests/server.h \ + tests/test.h noinst_PROGRAMS+= \ - tests/atomsmasher \ - tests/startservers \ - tests/testapp \ - tests/testhashkit \ - tests/testplus \ - tests/udptest + tests/atomsmasher \ + tests/startservers \ + tests/testapp \ + tests/testhashkit \ + tests/testplus \ + tests/udptest noinst_LTLIBRARIES+= tests/libserver.la tests_libserver_la_SOURCES= tests/server.c @@ -43,7 +47,7 @@ noinst_LTLIBRARIES+= tests/libtest.la tests_libtest_la_SOURCES= tests/test.c tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) -tests_testapp_SOURCES= tests/function.c +tests_testapp_SOURCES= tests/mem_functions.c tests_testapp_LDADD= \ clients/libgenexec.la \ tests/libserver.la \ @@ -83,10 +87,10 @@ client-record: sh tests/t/memslap.test > tests/r/memslap.res sh tests/t/memstat.test > tests/r/memstat.res -test: test-docs tests/testapp tests/testplus library_test memcapable libmhashkit_test +test: test-docs tests/testplus library_test memcapable libmhashkit_test echo "Tests completed" -library_test: +library_test: tests/testapp tests/testapp libmhashkit_test: libhashkit @@ -115,16 +119,31 @@ clients: cat tests/Xumemc.pid | xargs kill rm tests/Xumemc.pid +MEM_COMMAND= tests/testapp $(COLLECTION) $(SUITE) + +HASH_COMMAND= tests/testhashkit $(COLLECTION) $(SUITE) + +test-mem: + $(MEM_COMMAND) + +test-hash: + $(HASH_COMMAND) + gdb-mem: - $(LIBTOOL) --mode=execute gdb tests/testapp + $(DEBUG_COMMAND) $(MEM_COMMAND) gdb-hash: - $(LIBTOOL) --mode=execute gdb tests/testhashkit + $(DEBUG_COMMAND) $(HASH_COMMAND) + +valgrind-mem: + $(VALGRIND_COMMAND) $(MEM_COMMAND) + +valgrind-hash: + $(VALGRIND_COMMAND) $(HASH_COMMAND) PHONY += valgrind -valgrind: - $(LIBTOOL) --mode=execute valgrind --leak-check=yes --show-reachable=yes tests/testapp +valgrind: tests/testapp tests/testhashkit valgrind-mem valgrind-hash PHONY += cachegrind CLEANFILES += tests/cachegrind.out diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 10cca65f..4092d951 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -17,6 +17,7 @@ extern "C" { typedef struct { server_startup_st construct; + memcached_st *parent; memcached_st *memc; } libmemcached_test_container_st; @@ -32,6 +33,12 @@ test_return_t world_destroy(libmemcached_test_container_st *); static libmemcached_test_container_st global_container; +/** + @note generic shutdown/startup for libmemcached tests. +*/ +test_return_t world_container_startup(libmemcached_test_container_st *container); +test_return_t world_container_shutdown(libmemcached_test_container_st *container); + libmemcached_test_container_st *world_create(test_return_t *error) { memset(&global_container, 0, sizeof(global_container)); @@ -51,19 +58,34 @@ libmemcached_test_container_st *world_create(test_return_t *error) return &global_container; } - -test_return_t world_test_startup(libmemcached_test_container_st *container) +test_return_t world_container_startup(libmemcached_test_container_st *container) { memcached_return_t rc; - container->memc= memcached_create(NULL); - test_truth((container->memc != NULL)); + container->parent= memcached_create(NULL); + test_truth((container->parent != NULL)); - rc= memcached_server_push(container->memc, container->construct.servers); + rc= memcached_server_push(container->parent, container->construct.servers); test_truth(rc == MEMCACHED_SUCCESS); return TEST_SUCCESS; } +test_return_t world_container_shutdown(libmemcached_test_container_st *container) +{ + memcached_free(container->parent); + container->parent= NULL; + + return TEST_SUCCESS; +} + +test_return_t world_test_startup(libmemcached_test_container_st *container) +{ + container->memc= memcached_clone(NULL, container->parent); + test_truth((container->memc != NULL)); + + return TEST_SUCCESS; +} + test_return_t world_flush(libmemcached_test_container_st *container) { memcached_flush(container->memc, 0); @@ -97,6 +119,7 @@ test_return_t world_on_error(test_return_t test_state, libmemcached_test_contain { (void)test_state; memcached_free(container->memc); + container->memc= NULL; return TEST_SUCCESS; } diff --git a/tests/function.c b/tests/mem_functions.c similarity index 99% rename from tests/function.c rename to tests/mem_functions.c index f0b10af0..06a1b544 100644 --- a/tests/function.c +++ b/tests/mem_functions.c @@ -5824,5 +5824,8 @@ void get_world(world_st *world) world->test.post_run= (test_callback_fn)world_post_run; world->test.on_error= (test_callback_error_fn)world_on_error; + world->collection.startup= (test_callback_fn)world_container_startup; + world->collection.shutdown= (test_callback_fn)world_container_shutdown; + world->runner= &defualt_libmemcached_runner; } -- 2.30.2