Skip to content

Commit 7883b53

Browse files
committed
testing
1 parent f875439 commit 7883b53

14 files changed

+115
-96
lines changed

CMake/_Include.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if(ENABLE_MEMASLAP)
3939
check_stdatomic()
4040
check_dependency(LIBEVENT event event.h)
4141
check_decl(getline stdio.h)
42+
if(LIBEVENT AND HAVE_C_STDATOMIC)
43+
set(HAVE_MEMASLAP 1)
44+
endif()
4245
endif()
4346

4447
## dtrace

codecov.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ignore:
44
- "/usr"
55
- "example"
66
- "tests"
7+
- "test/lib/catch.hpp"
78

89
fixes:
910
- "src/libmemcachedinternal::src/libmemcached"

src/bin/CMakeLists.txt

+15-17
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@ target_link_libraries(memslap PRIVATE Threads::Threads)
2424

2525
# memaslap is special
2626

27-
if(ENABLE_MEMASLAP)
28-
if(LIBEVENT AND HAVE_C_STDATOMIC)
29-
add_executable(memaslap memaslap.c
30-
memaslap/ms_conn.c
31-
memaslap/ms_setting.c
32-
memaslap/ms_sigsegv.c
33-
memaslap/ms_stats.c
34-
memaslap/ms_task.c
35-
memaslap/ms_thread.c)
36-
target_include_directories(memaslap PRIVATE memaslap ${LIBEVENT_INCLUDEDIR})
37-
target_link_libraries(memaslap PRIVATE libclient_common ${LIBEVENT_LIBRARIES} Threads::Threads)
38-
if(CMAKE_INSTALL_RPATH)
39-
set_target_properties(${CLIENT} PROPERTIES
40-
INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR})
41-
endif()
42-
install(TARGETS memaslap
43-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
27+
if(HAVE_MEMASLAP)
28+
add_executable(memaslap memaslap.c
29+
memaslap/ms_conn.c
30+
memaslap/ms_setting.c
31+
memaslap/ms_sigsegv.c
32+
memaslap/ms_stats.c
33+
memaslap/ms_task.c
34+
memaslap/ms_thread.c)
35+
target_include_directories(memaslap PRIVATE memaslap ${LIBEVENT_INCLUDEDIR})
36+
target_link_libraries(memaslap PRIVATE libclient_common ${LIBEVENT_LIBRARIES} Threads::Threads)
37+
if(CMAKE_INSTALL_RPATH)
38+
set_target_properties(${CLIENT} PROPERTIES
39+
INSTALL_RPATH ${CMAKE_INSTALL_RPATH}/../${CMAKE_INSTALL_LIBDIR})
4440
endif()
41+
install(TARGETS memaslap
42+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
4543
endif()

test/CMakeLists.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ check_decl(pipe2 unistd.h)
1414
check_decl(SOCK_NONBLOCK sys/socket.h)
1515
check_decl(SOCK_CLOEXEC sys/socket.h)
1616

17-
if(ENABLE_MEMASLAP AND LIBEVENT AND HAVE_C_STDATOMIC)
18-
set(HAVE_MEMASLAP 1)
19-
endif()
20-
2117
file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
2218
set(TESTING_ROOT ${CMAKE_CURRENT_BINARY_DIR})
2319
set_source_files_properties(main.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
@@ -31,6 +27,9 @@ target_include_directories(runtests PRIVATE
3127
${CMAKE_BINARY_DIR}/src)
3228
target_link_libraries(runtests PRIVATE libhashkit libmemcachedinternal libmemcachedutil)
3329
add_dependencies(runtests ${CLIENTS})
30+
if(HAVE_MEMASLAP)
31+
add_dependencies(runtests memaslap)
32+
endif()
3433

3534
catch_discover_tests(runtests
3635
TEST_SPEC "lib*")

test/fixtures/callbacks.hpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "test/lib/common.hpp"
2+
#include "libmemcached/common.h"
3+
#include "libmemcachedutil/common.h"
4+
5+
static inline memcached_return_t ping_callback(const memcached_st *, const memcached_instance_st *instance, void *) {
6+
memcached_return_t rc;
7+
8+
REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), &rc));
9+
REQUIRE(rc == MEMCACHED_SUCCESS);
10+
return MEMCACHED_SUCCESS;
11+
}
12+
13+
static inline memcached_return_t ping2_callback(const memcached_st *, const memcached_instance_st *instance, void *) {
14+
memcached_return_t rc;
15+
16+
REQUIRE(libmemcached_util_ping2(memcached_server_name(instance), memcached_server_port(instance), "memcached", "memcached", &rc));
17+
REQUIRE(rc == MEMCACHED_SUCCESS);
18+
return MEMCACHED_SUCCESS;
19+
}
20+
21+
static inline memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) {
22+
auto *counter= reinterpret_cast<size_t *>(context);
23+
*counter = *counter + 1;
24+
25+
return MEMCACHED_SUCCESS;
26+
}
27+
28+
static inline memcached_return_t delete_trigger(memcached_st *, const char *, size_t) {
29+
return MEMCACHED_SUCCESS;
30+
}
31+
32+
static inline memcached_return_t read_through_trigger(memcached_st *, char *, size_t, memcached_result_st *result) {
33+
return memcached_result_set_value(result, S("updated by read through trigger"));
34+
}
35+
36+
static inline memcached_return_t clone_callback(memcached_st *, memcached_st *) {
37+
return MEMCACHED_SUCCESS;
38+
}
39+
40+
static inline memcached_return_t cleanup_callback(memcached_st *) {
41+
return MEMCACHED_SUCCESS;
42+
}
43+
44+
static inline memcached_return_t server_sort_callback(const memcached_st *, const memcached_instance_st *server, void *context) {
45+
if (context) {
46+
auto bigger = reinterpret_cast<size_t *>(context);
47+
REQUIRE(*bigger <= memcached_server_port(server));
48+
*bigger = memcached_server_port(server);
49+
}
50+
return MEMCACHED_SUCCESS;
51+
}
52+

test/tests/memcached/behavior.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3-
4-
static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) {
5-
auto *counter = reinterpret_cast<size_t *>(context);
6-
*counter = *counter + 1;
7-
8-
return MEMCACHED_SUCCESS;
9-
}
3+
#include "test/fixtures/callbacks.hpp"
104

115
TEST_CASE("memcached_behavior") {
126
auto test = MemcachedCluster::network();

test/tests/memcached/callbacks.cpp

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3-
4-
static memcached_return_t delete_trigger(memcached_st *, const char *, size_t) {
5-
return MEMCACHED_SUCCESS;
6-
}
7-
8-
static memcached_return_t read_through_trigger(memcached_st *, char *, size_t, memcached_result_st *result) {
9-
return memcached_result_set_value(result, S("updated by read through trigger"));
10-
}
11-
12-
static memcached_return_t clone_callback(memcached_st *, memcached_st *) {
13-
return MEMCACHED_SUCCESS;
14-
}
15-
16-
static memcached_return_t cleanup_callback(memcached_st *) {
17-
return MEMCACHED_SUCCESS;
18-
}
3+
#include "test/fixtures/callbacks.hpp"
194

205
TEST_CASE("memcached_callbacks") {
216
auto test{MemcachedCluster::mixed()};

test/tests/memcached/regression/lp_000-434-843.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3-
4-
static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) {
5-
auto *counter= reinterpret_cast<size_t *>(context);
6-
*counter = *counter + 1;
7-
8-
return MEMCACHED_SUCCESS;
9-
}
3+
#include "test/fixtures/callbacks.hpp"
104

115
#define NUM_KEYS 1024
126

@@ -26,7 +20,7 @@ TEST_CASE("memcached_regression_lp434843") {
2620
array<string, NUM_KEYS> str;
2721
array<char *, NUM_KEYS> chr;
2822
array<size_t, NUM_KEYS> len;
29-
23+
3024
for (auto i = 0; i < NUM_KEYS; ++i) {
3125
str[i] = random_ascii_string(12) + to_string(i);
3226
chr[i] = str[i].data();

test/tests/memcached/regression/lp_000-447-342.cpp

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3-
3+
#include "test/fixtures/callbacks.hpp"
44
#include "libmemcached/instance.hpp"
55

6-
static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) {
7-
auto *counter= reinterpret_cast<size_t *>(context);
8-
*counter = *counter + 1;
9-
10-
return MEMCACHED_SUCCESS;
11-
}
12-
136
#define NUM_KEYS 100U
147

158
TEST_CASE("memcached_regression_lp447342") {
169
auto test = MemcachedCluster::network();
1710
auto memc = &test.memc;
18-
11+
1912
REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2));
20-
13+
2114
array<string, NUM_KEYS> str;
2215
array<char *, NUM_KEYS> chr;
2316
array<size_t, NUM_KEYS> len;
24-
17+
2518
for (auto i = 0U; i < NUM_KEYS; ++i) {
2619
str[i] = random_ascii_string(random_num(12, 16)) + to_string(i);
2720
chr[i] = str[i].data();
@@ -42,16 +35,16 @@ TEST_CASE("memcached_regression_lp447342") {
4235
** as an example for your own code, please note that you shouldn't need
4336
** to do this ;-)
4437
*/
45-
38+
4639
memcached_quit(memc);
47-
40+
4841
REQUIRE_SUCCESS(memcached_mget(memc, chr.data(), len.data(), NUM_KEYS));
4942

5043
size_t counter = 0;
5144
memcached_execute_fn cb[] = {&callback_counter};
5245
REQUIRE_SUCCESS(memcached_fetch_execute(memc, cb, &counter, 1));
5346
REQUIRE(counter == NUM_KEYS);
54-
47+
5548
memcached_quit(memc);
5649

5750
/*

test/tests/memcached/regression/lp_000-490-486.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3+
#include "test/fixtures/callbacks.hpp"
34

45
#define NUM_KEYS 20480U
56

6-
static memcached_return_t callback_counter(const memcached_st *, memcached_result_st *, void *context) {
7-
auto *counter= reinterpret_cast<size_t *>(context);
8-
*counter = *counter + 1;
9-
10-
return MEMCACHED_SUCCESS;
11-
}
12-
137
TEST_CASE("memcached_regression_lp490486") {
148
MemcachedCluster test{Cluster{Server{MEMCACHED_BINARY, {"-p", random_port_string}}, 1}};
159
auto memc = &test.memc;

test/tests/memcached/sasl.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/Shell.hpp"
33
#include "test/lib/MemcachedCluster.hpp"
4+
#include "test/fixtures/callbacks.hpp"
45

56
TEST_CASE("memcached_sasl") {
67
#if !LIBMEMCACHED_WITH_SASL_SUPPORT
@@ -27,6 +28,24 @@ TEST_CASE("memcached_sasl") {
2728

2829
REQUIRE_SUCCESS(memcached_set_sasl_auth_data(memc, "username", "password"));
2930
REQUIRE_RC(MEMCACHED_AUTH_FAILURE, memcached_set(memc, S(__func__), S(__func__), 0, 0));
31+
32+
SECTION("getpid2") {
33+
memcached_return_t rc;
34+
35+
for (auto &server : test.cluster.getServers()) {
36+
REQUIRE(server.getPid() == libmemcached_util_getpid2("localhost", get<int>(server.getSocketOrPort()), "memcached", "memcached", &rc));
37+
REQUIRE_SUCCESS(rc);
38+
}
39+
40+
REQUIRE(-1 == libmemcached_util_getpid2("localhost", 1, "foo", "bar", &rc));
41+
REQUIRE(memcached_fatal(rc));
42+
}
43+
44+
SECTION("ping2") {
45+
memcached_server_fn fptr[] = {&ping2_callback};
46+
47+
REQUIRE_SUCCESS(memcached_server_cursor(memc, fptr, nullptr, 1));
48+
}
3049
}
3150
#endif
3251
}

test/tests/memcached/servers.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
#include "test/lib/common.hpp"
2-
32
#include "test/lib/MemcachedCluster.hpp"
4-
5-
static memcached_return_t server_display_function(const memcached_st *,
6-
const memcached_instance_st * server,
7-
void *context)
8-
{
9-
if (context) {
10-
auto bigger = reinterpret_cast<size_t *>(context);
11-
REQUIRE(*bigger <= memcached_server_port(server));
12-
*bigger = memcached_server_port(server);
13-
}
14-
return MEMCACHED_SUCCESS;
15-
}
3+
#include "test/fixtures/callbacks.hpp"
164

175
TEST_CASE("memcached_servers") {
186
SECTION("memcached_servers_parse") {
@@ -60,10 +48,10 @@ TEST_CASE("memcached_servers") {
6048
auto local_memc = *memc;
6149
LoneReturnMatcher test{local_memc};
6250
size_t bigger = 0; /* Prime the value for the test_true in server_display_function */
63-
memcached_server_fn callbacks[1]{server_display_function};
51+
memcached_server_fn callbacks[1]{server_sort_callback};
6452

6553
REQUIRE_SUCCESS(memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1));
66-
54+
6755
SECTION("variation 1") {
6856
for (uint32_t x = 0; x < 7; x++) {
6957
REQUIRE_SUCCESS(memcached_server_add_with_weight(local_memc, "localhost", random_port(), 0));

test/tests/memcached/simple.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ TEST_CASE("memcached_simple") {
7474
DYNAMIC_SECTION("verbosity (buffered=" << buffered << ",binary=" << binary << ")") {
7575
REQUIRE_SUCCESS(memcached_verbosity(memc, 0));
7676
}
77+
78+
DYNAMIC_SECTION("version (buffered=" << buffered << ",binary=" << binary << ")") {
79+
REQUIRE_SUCCESS(memcached_version(memc));
80+
}
7781
}
7882
}

test/tests/memcached/util.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#include "test/lib/common.hpp"
22
#include "test/lib/MemcachedCluster.hpp"
3+
#include "test/fixtures/callbacks.hpp"
34

45
#include "libmemcached/instance.hpp"
56
#include "libmemcachedutil/common.h"
67

7-
static memcached_return_t ping_callback(const memcached_st *, const memcached_instance_st *instance, void *) {
8-
memcached_return_t rc;
9-
10-
REQUIRE(libmemcached_util_ping(memcached_server_name(instance), memcached_server_port(instance), &rc));
11-
REQUIRE(rc == MEMCACHED_SUCCESS);
12-
return MEMCACHED_SUCCESS;
13-
}
14-
158
TEST_CASE("memcached_util") {
169
SECTION("version_check") {
1710
auto test = MemcachedCluster::mixed();
@@ -43,6 +36,7 @@ TEST_CASE("memcached_util") {
4336
}
4437
}
4538

39+
// see sasl.cpp for getpid2 test
4640
SECTION("getpid") {
4741
auto test = MemcachedCluster::network();
4842
memcached_return_t rc;
@@ -56,6 +50,7 @@ TEST_CASE("memcached_util") {
5650
REQUIRE(memcached_fatal(rc));
5751
}
5852

53+
// see sasl.cpp for ping2 test
5954
SECTION("ping") {
6055
auto test = MemcachedCluster::network();
6156
auto memc = &test.memc;

0 commit comments

Comments
 (0)