From: Michael Wallner Date: Tue, 20 Oct 2020 12:17:07 +0000 (+0200) Subject: testing X-Git-Tag: 1.1.0-beta1~190 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7883b530881983213dffaa6c71ace9204bedb82a;p=awesomized%2Flibmemcached testing --- diff --git a/CMake/_Include.cmake b/CMake/_Include.cmake index a1bd2e49..8a33f964 100644 --- a/CMake/_Include.cmake +++ b/CMake/_Include.cmake @@ -39,6 +39,9 @@ if(ENABLE_MEMASLAP) check_stdatomic() check_dependency(LIBEVENT event event.h) check_decl(getline stdio.h) + if(LIBEVENT AND HAVE_C_STDATOMIC) + set(HAVE_MEMASLAP 1) + endif() endif() ## dtrace diff --git a/codecov.yml b/codecov.yml index bbcc1412..66e2537f 100644 --- a/codecov.yml +++ b/codecov.yml @@ -4,6 +4,7 @@ ignore: - "/usr" - "example" - "tests" + - "test/lib/catch.hpp" fixes: - "src/libmemcachedinternal::src/libmemcached" diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 0894b247..a8d79732 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -24,22 +24,20 @@ target_link_libraries(memslap PRIVATE Threads::Threads) # memaslap is special -if(ENABLE_MEMASLAP) - if(LIBEVENT AND HAVE_C_STDATOMIC) - add_executable(memaslap memaslap.c - memaslap/ms_conn.c - memaslap/ms_setting.c - memaslap/ms_sigsegv.c - memaslap/ms_stats.c - memaslap/ms_task.c - memaslap/ms_thread.c) - target_include_directories(memaslap PRIVATE memaslap ${LIBEVENT_INCLUDEDIR}) - target_link_libraries(memaslap PRIVATE libclient_common ${LIBEVENT_LIBRARIES} Threads::Threads) - if(CMAKE_INSTALL_RPATH) - set_target_properties(${CLIENT} PROPERTIES - INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR}) - endif() - install(TARGETS memaslap - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +if(HAVE_MEMASLAP) + add_executable(memaslap memaslap.c + memaslap/ms_conn.c + memaslap/ms_setting.c + memaslap/ms_sigsegv.c + memaslap/ms_stats.c + memaslap/ms_task.c + memaslap/ms_thread.c) + target_include_directories(memaslap PRIVATE memaslap ${LIBEVENT_INCLUDEDIR}) + target_link_libraries(memaslap PRIVATE libclient_common ${LIBEVENT_LIBRARIES} Threads::Threads) + if(CMAKE_INSTALL_RPATH) + set_target_properties(${CLIENT} PROPERTIES + INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR}) endif() + install(TARGETS memaslap + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 118dbc44..d364ac31 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,10 +14,6 @@ check_decl(pipe2 unistd.h) check_decl(SOCK_NONBLOCK sys/socket.h) check_decl(SOCK_CLOEXEC sys/socket.h) -if(ENABLE_MEMASLAP AND LIBEVENT AND HAVE_C_STDATOMIC) - set(HAVE_MEMASLAP 1) -endif() - file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) set(TESTING_ROOT ${CMAKE_CURRENT_BINARY_DIR}) set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) @@ -31,6 +27,9 @@ target_include_directories(runtests PRIVATE ${CMAKE_BINARY_DIR}/src) target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcachedutil) add_dependencies(runtests ${CLIENTS}) +if(HAVE_MEMASLAP) + add_dependencies(runtests memaslap) +endif() catch_discover_tests(runtests TEST_SPEC "lib*") diff --git a/test/fixtures/callbacks.hpp b/test/fixtures/callbacks.hpp new file mode 100644 index 00000000..52bab4c7 --- /dev/null +++ b/test/fixtures/callbacks.hpp @@ -0,0 +1,52 @@ +#include "test/lib/common.hpp" +#include "libmemcached/common.h" +#include "libmemcachedutil/common.h" + +static inline memcached_return_t ping_callback(const memcached_st *, const memcached_instance_st *instance, void *) { + memcached_return_t rc; + + REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), &rc)); + REQUIRE(rc == MEMCACHED_SUCCESS); + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t ping2_callback(const memcached_st *, const memcached_instance_st *instance, void *) { + memcached_return_t rc; + + REQUIRE(libmemcached_util_ping2(memcached_server_name(instance), memcached_server_port(instance), "memcached", "memcached", &rc)); + REQUIRE(rc == MEMCACHED_SUCCESS); + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { + auto *counter= reinterpret_cast(context); + *counter = *counter + 1; + + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t delete_trigger(memcached_st *, const char *, size_t) { + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t read_through_trigger(memcached_st *, char *, size_t, memcached_result_st *result) { + return memcached_result_set_value(result, S("updated by read through trigger")); +} + +static inline memcached_return_t clone_callback(memcached_st *, memcached_st *) { + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t cleanup_callback(memcached_st *) { + return MEMCACHED_SUCCESS; +} + +static inline memcached_return_t server_sort_callback(const memcached_st *, const memcached_instance_st *server, void *context) { + if (context) { + auto bigger = reinterpret_cast(context); + REQUIRE(*bigger <= memcached_server_port(server)); + *bigger = memcached_server_port(server); + } + return MEMCACHED_SUCCESS; +} + diff --git a/test/tests/memcached/behavior.cpp b/test/tests/memcached/behavior.cpp index 3cfef229..655265e9 100644 --- a/test/tests/memcached/behavior.cpp +++ b/test/tests/memcached/behavior.cpp @@ -1,12 +1,6 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" - -static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { - auto *counter = reinterpret_cast(context); - *counter = *counter + 1; - - return MEMCACHED_SUCCESS; -} +#include "test/fixtures/callbacks.hpp" TEST_CASE("memcached_behavior") { auto test = MemcachedCluster::network(); diff --git a/test/tests/memcached/callbacks.cpp b/test/tests/memcached/callbacks.cpp index 476842ff..fa8b58cf 100644 --- a/test/tests/memcached/callbacks.cpp +++ b/test/tests/memcached/callbacks.cpp @@ -1,21 +1,6 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" - -static memcached_return_t delete_trigger(memcached_st *, const char *, size_t) { - return MEMCACHED_SUCCESS; -} - -static memcached_return_t read_through_trigger(memcached_st *, char *, size_t, memcached_result_st *result) { - return memcached_result_set_value(result, S("updated by read through trigger")); -} - -static memcached_return_t clone_callback(memcached_st *, memcached_st *) { - return MEMCACHED_SUCCESS; -} - -static memcached_return_t cleanup_callback(memcached_st *) { - return MEMCACHED_SUCCESS; -} +#include "test/fixtures/callbacks.hpp" TEST_CASE("memcached_callbacks") { auto test{MemcachedCluster::mixed()}; diff --git a/test/tests/memcached/regression/lp_000-434-843.cpp b/test/tests/memcached/regression/lp_000-434-843.cpp index dc839d53..76c74be0 100644 --- a/test/tests/memcached/regression/lp_000-434-843.cpp +++ b/test/tests/memcached/regression/lp_000-434-843.cpp @@ -1,12 +1,6 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" - -static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { - auto *counter= reinterpret_cast(context); - *counter = *counter + 1; - - return MEMCACHED_SUCCESS; -} +#include "test/fixtures/callbacks.hpp" #define NUM_KEYS 1024 @@ -26,7 +20,7 @@ TEST_CASE("memcached_regression_lp434843") { array str; array chr; array len; - + for (auto i = 0; i < NUM_KEYS; ++i) { str[i] = random_ascii_string(12) + to_string(i); chr[i] = str[i].data(); diff --git a/test/tests/memcached/regression/lp_000-447-342.cpp b/test/tests/memcached/regression/lp_000-447-342.cpp index bd37f484..3ab5112f 100644 --- a/test/tests/memcached/regression/lp_000-447-342.cpp +++ b/test/tests/memcached/regression/lp_000-447-342.cpp @@ -1,27 +1,20 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" - +#include "test/fixtures/callbacks.hpp" #include "libmemcached/instance.hpp" -static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { - auto *counter= reinterpret_cast(context); - *counter = *counter + 1; - - return MEMCACHED_SUCCESS; -} - #define NUM_KEYS 100U TEST_CASE("memcached_regression_lp447342") { auto test = MemcachedCluster::network(); auto memc = &test.memc; - + REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2)); - + array str; array chr; array len; - + for (auto i = 0U; i < NUM_KEYS; ++i) { str[i] = random_ascii_string(random_num(12, 16)) + to_string(i); chr[i] = str[i].data(); @@ -42,16 +35,16 @@ TEST_CASE("memcached_regression_lp447342") { ** as an example for your own code, please note that you shouldn't need ** to do this ;-) */ - + memcached_quit(memc); - + REQUIRE_SUCCESS(memcached_mget(memc, chr.data(), len.data(), NUM_KEYS)); size_t counter = 0; memcached_execute_fn cb[] = {&callback_counter}; REQUIRE_SUCCESS(memcached_fetch_execute(memc, cb, &counter, 1)); REQUIRE(counter == NUM_KEYS); - + memcached_quit(memc); /* diff --git a/test/tests/memcached/regression/lp_000-490-486.cpp b/test/tests/memcached/regression/lp_000-490-486.cpp index 1731d2d0..5ec31793 100644 --- a/test/tests/memcached/regression/lp_000-490-486.cpp +++ b/test/tests/memcached/regression/lp_000-490-486.cpp @@ -1,15 +1,9 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" +#include "test/fixtures/callbacks.hpp" #define NUM_KEYS 20480U -static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) { - auto *counter= reinterpret_cast(context); - *counter = *counter + 1; - - return MEMCACHED_SUCCESS; -} - TEST_CASE("memcached_regression_lp490486") { MemcachedCluster test{Cluster{Server{MEMCACHED_BINARY, {"-p", random_port_string}}, 1}}; auto memc = &test.memc; diff --git a/test/tests/memcached/sasl.cpp b/test/tests/memcached/sasl.cpp index 318a8f93..2753d942 100644 --- a/test/tests/memcached/sasl.cpp +++ b/test/tests/memcached/sasl.cpp @@ -1,6 +1,7 @@ #include "test/lib/common.hpp" #include "test/lib/Shell.hpp" #include "test/lib/MemcachedCluster.hpp" +#include "test/fixtures/callbacks.hpp" TEST_CASE("memcached_sasl") { #if !LIBMEMCACHED_WITH_SASL_SUPPORT @@ -27,6 +28,24 @@ TEST_CASE("memcached_sasl") { REQUIRE_SUCCESS(memcached_set_sasl_auth_data(memc, "username", "password")); REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0)); + + SECTION("getpid2") { + memcached_return_t rc; + + for (auto &server : test.cluster.getServers()) { + REQUIRE(server.getPid() == libmemcached_util_getpid2("localhost", get(server.getSocketOrPort()), "memcached", "memcached", &rc)); + REQUIRE_SUCCESS(rc); + } + + REQUIRE(-1 == libmemcached_util_getpid2("localhost", 1, "foo", "bar", &rc)); + REQUIRE(memcached_fatal(rc)); + } + + SECTION("ping2") { + memcached_server_fn fptr[] = {&ping2_callback}; + + REQUIRE_SUCCESS(memcached_server_cursor(memc, fptr, nullptr, 1)); + } } #endif } diff --git a/test/tests/memcached/servers.cpp b/test/tests/memcached/servers.cpp index 6c66fdbd..248421b2 100644 --- a/test/tests/memcached/servers.cpp +++ b/test/tests/memcached/servers.cpp @@ -1,18 +1,6 @@ #include "test/lib/common.hpp" - #include "test/lib/MemcachedCluster.hpp" - -static memcached_return_t server_display_function(const memcached_st *, - const memcached_instance_st * server, - void *context) -{ - if (context) { - auto bigger = reinterpret_cast(context); - REQUIRE(*bigger <= memcached_server_port(server)); - *bigger = memcached_server_port(server); - } - return MEMCACHED_SUCCESS; -} +#include "test/fixtures/callbacks.hpp" TEST_CASE("memcached_servers") { SECTION("memcached_servers_parse") { @@ -60,10 +48,10 @@ TEST_CASE("memcached_servers") { auto local_memc = *memc; LoneReturnMatcher test{local_memc}; size_t bigger = 0; /* Prime the value for the test_true in server_display_function */ - memcached_server_fn callbacks[1]{server_display_function}; + memcached_server_fn callbacks[1]{server_sort_callback}; REQUIRE_SUCCESS(memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1)); - + SECTION("variation 1") { for (uint32_t x = 0; x < 7; x++) { REQUIRE_SUCCESS(memcached_server_add_with_weight(local_memc, "localhost", random_port(), 0)); diff --git a/test/tests/memcached/simple.cpp b/test/tests/memcached/simple.cpp index 19f1ff02..6856d63e 100644 --- a/test/tests/memcached/simple.cpp +++ b/test/tests/memcached/simple.cpp @@ -74,5 +74,9 @@ TEST_CASE("memcached_simple") { DYNAMIC_SECTION("verbosity (buffered=" << buffered << ",binary=" << binary << ")") { REQUIRE_SUCCESS(memcached_verbosity(memc, 0)); } + + DYNAMIC_SECTION("version (buffered=" << buffered << ",binary=" << binary << ")") { + REQUIRE_SUCCESS(memcached_version(memc)); + } } } diff --git a/test/tests/memcached/util.cpp b/test/tests/memcached/util.cpp index 35a76b7e..3256fced 100644 --- a/test/tests/memcached/util.cpp +++ b/test/tests/memcached/util.cpp @@ -1,17 +1,10 @@ #include "test/lib/common.hpp" #include "test/lib/MemcachedCluster.hpp" +#include "test/fixtures/callbacks.hpp" #include "libmemcached/instance.hpp" #include "libmemcachedutil/common.h" -static memcached_return_t ping_callback(const memcached_st *, const memcached_instance_st *instance, void *) { - memcached_return_t rc; - - REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), &rc)); - REQUIRE(rc == MEMCACHED_SUCCESS); - return MEMCACHED_SUCCESS; -} - TEST_CASE("memcached_util") { SECTION("version_check") { auto test = MemcachedCluster::mixed(); @@ -43,6 +36,7 @@ TEST_CASE("memcached_util") { } } + // see sasl.cpp for getpid2 test SECTION("getpid") { auto test = MemcachedCluster::network(); memcached_return_t rc; @@ -56,6 +50,7 @@ TEST_CASE("memcached_util") { REQUIRE(memcached_fatal(rc)); } + // see sasl.cpp for ping2 test SECTION("ping") { auto test = MemcachedCluster::network(); auto memc = &test.memc;