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
- "/usr"
- "example"
- "tests"
+ - "test/lib/catch.hpp"
fixes:
- "src/libmemcachedinternal::src/libmemcached"
# 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()
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)
${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*")
--- /dev/null
+#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<size_t *>(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<size_t *>(context);
+ REQUIRE(*bigger <= memcached_server_port(server));
+ *bigger = memcached_server_port(server);
+ }
+ return MEMCACHED_SUCCESS;
+}
+
#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<size_t *>(context);
- *counter = *counter + 1;
-
- return MEMCACHED_SUCCESS;
-}
+#include "test/fixtures/callbacks.hpp"
TEST_CASE("memcached_behavior") {
auto test = MemcachedCluster::network();
#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()};
#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<size_t *>(context);
- *counter = *counter + 1;
-
- return MEMCACHED_SUCCESS;
-}
+#include "test/fixtures/callbacks.hpp"
#define NUM_KEYS 1024
array<string, NUM_KEYS> str;
array<char *, NUM_KEYS> chr;
array<size_t, NUM_KEYS> len;
-
+
for (auto i = 0; i < NUM_KEYS; ++i) {
str[i] = random_ascii_string(12) + to_string(i);
chr[i] = str[i].data();
#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<size_t *>(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<string, NUM_KEYS> str;
array<char *, NUM_KEYS> chr;
array<size_t, NUM_KEYS> 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();
** 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);
/*
#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<size_t *>(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;
#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
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<int>(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
}
#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<size_t *>(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") {
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));
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));
+ }
}
}
#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();
}
}
+ // see sasl.cpp for getpid2 test
SECTION("getpid") {
auto test = MemcachedCluster::network();
memcached_return_t rc;
REQUIRE(memcached_fatal(rc));
}
+ // see sasl.cpp for ping2 test
SECTION("ping") {
auto test = MemcachedCluster::network();
auto memc = &test.memc;