From: Michael Wallner Date: Tue, 13 Oct 2020 15:16:19 +0000 (+0200) Subject: testing: bin/memaslap X-Git-Tag: 1.1.0-beta1~236^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a93908cc9c40eef179d33a89fc011e2e3c54c438;p=awesomized%2Flibmemcached testing: bin/memaslap --- diff --git a/src/bin/memaslap.c b/src/bin/memaslap.c index c94ead2d..77f74b36 100644 --- a/src/bin/memaslap.c +++ b/src/bin/memaslap.c @@ -1,5 +1,5 @@ /* - * memslap + * memaslap * * (c) Copyright 2009, Schooner Information Technology, Inc. * All rights reserved. @@ -41,7 +41,7 @@ ms_stats_t ms_stats; /* global statistic structure */ ms_statistic_t ms_statistic; -#define PROGRAM_NAME "memslap" +#define PROGRAM_NAME "memaslap" #define PROGRAM_DESCRIPTION \ "Generates workload against memcached servers." @@ -120,7 +120,7 @@ static int ms_check_para(void); static void ms_statistic_init(void); static void ms_stats_init(void); static void ms_print_statistics(int in_time); -static void ms_print_memslap_stats(struct timeval *start_time, +static void ms_print_memaslap_stats(struct timeval *start_time, struct timeval *end_time); static void ms_monitor_slap_mode(void); @@ -131,7 +131,7 @@ static void ms_monitor_slap_mode(void); * @param description, description of this process * @param long_options, global options array */ -static __attribute__((noreturn)) void ms_help_command(const char *command_name, const char *description) +static void ms_help_command(const char *command_name, const char *description) { char *help_message= NULL; @@ -139,7 +139,7 @@ static __attribute__((noreturn)) void ms_help_command(const char *command_name, printf(" %s\n\n", description); printf( "Usage:\n" - " memslap -hV | -s servers [-F config_file] [-t time | -x exe_num] [...]\n\n" + " memaslap -hV | -s servers [-F config_file] [-t time | -x exe_num] [...]\n\n" "Options:\n"); for (int x= 0; long_options[x].name; x++) @@ -155,15 +155,13 @@ static __attribute__((noreturn)) void ms_help_command(const char *command_name, printf( "\nExamples:\n" - " memslap -s 127.0.0.1:11211 -S 5s\n" - " memslap -s 127.0.0.1:11211 -t 2m -v 0.2 -e 0.05 -b\n" - " memslap -s 127.0.0.1:11211 -F config -t 2m -w 40k -S 20s -o 0.2\n" - " memslap -s 127.0.0.1:11211 -F config -t 2m -T 4 -c 128 -d 20 -P 40k\n" - " memslap -s 127.0.0.1:11211 -F config -t 2m -d 50 -a -n 40\n" - " memslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m\n" - " memslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m -p 2\n\n"); - - exit(0); + " memaslap -s 127.0.0.1:11211 -S 5s\n" + " memaslap -s 127.0.0.1:11211 -t 2m -v 0.2 -e 0.05 -b\n" + " memaslap -s 127.0.0.1:11211 -F config -t 2m -w 40k -S 20s -o 0.2\n" + " memaslap -s 127.0.0.1:11211 -F config -t 2m -T 4 -c 128 -d 20 -P 40k\n" + " memaslap -s 127.0.0.1:11211 -F config -t 2m -d 50 -a -n 40\n" + " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m\n" + " memaslap -s 127.0.0.1:11211,127.0.0.1:11212 -F config -t 2m -p 2\n\n"); } /* ms_help_command */ @@ -295,7 +293,7 @@ static const char *ms_lookup_help(ms_options_t option) case OPT_UDP: return - "UDP support, default memslap uses TCP, TCP port and UDP port of\n" + "UDP support, by default memaslap uses TCP; TCP port and UDP port of\n" " server must be same."; case OPT_EXPIRE: @@ -442,6 +440,7 @@ static void ms_options_parse(int argc, char *argv[]) case OPT_HELP: /* --help or -h */ ms_help_command(PROGRAM_NAME, PROGRAM_DESCRIPTION); + exit(0); break; case OPT_SERVERS: /* --servers or -s */ @@ -660,7 +659,7 @@ static int ms_check_para() } else { - fprintf(stderr, "No Servers provided\n\n"); + fprintf(stderr, "No servers provided\n\n"); return -1; } } @@ -717,11 +716,11 @@ static void ms_print_statistics(int in_time) } /* ms_print_statistics */ -/* used to print the states of memslap */ -static void ms_print_memslap_stats(struct timeval *start_time, +/* used to print the states of memaslap */ +static void ms_print_memaslap_stats(struct timeval *start_time, struct timeval *end_time) { - char buf[1024]; + char buf[0x2000]; char *pos= buf; pos+= snprintf(pos, @@ -808,11 +807,11 @@ static void ms_print_memslap_stats(struct timeval *start_time, ms_stats.bytes_written + ms_stats.bytes_read) / 1024 / 1024 / ((double)time_diff / 1000000)); - assert(pos <= buf); + assert(pos <= (buf + sizeof(buf))); - fprintf(stdout, "%s", buf); + fwrite(buf, 1, pos - buf, stdout); fflush(stdout); -} /* ms_print_memslap_stats */ +} /* ms_print_memaslap_stats */ /* the loop of the main thread, wait the work threads to complete */ @@ -892,7 +891,7 @@ static void ms_monitor_slap_mode() gettimeofday(&end_time, NULL); } - ms_print_memslap_stats(&start_time, &end_time); + ms_print_memaslap_stats(&start_time, &end_time); } /* ms_monitor_slap_mode */ diff --git a/src/bin/memaslap/ms_conn.c b/src/bin/memaslap/ms_conn.c index 71353d5b..39f284b0 100644 --- a/src/bin/memaslap/ms_conn.c +++ b/src/bin/memaslap/ms_conn.c @@ -826,7 +826,7 @@ static int ms_network_connect(ms_conn_t *c, if (error != EAI_SYSTEM) fprintf(stderr, "getaddrinfo(): %s.\n", gai_strerror(error)); else - perror("getaddrinfo()\n"); + perror("getaddrinfo()"); return -1; } @@ -1169,7 +1169,7 @@ static int ms_ascii_process_line(ms_conn_t *c, char *command) { printf("<%d ERROR %s\n", c->sfd, strerror(errno)); } - c->currcmd.key_prefix= *(uint64_t *)tokens[KEY_TOKEN].value; + memcpy(&c->currcmd.key_prefix, tokens[KEY_TOKEN].value, sizeof(c->currcmd.key_prefix)); /* * We read the \r\n into the string since not doing so is more diff --git a/src/bin/memaslap/ms_setting.c b/src/bin/memaslap/ms_setting.c index 6cb367a3..289466e0 100644 --- a/src/bin/memaslap/ms_setting.c +++ b/src/bin/memaslap/ms_setting.c @@ -320,7 +320,7 @@ static void ms_no_config_file() if (fd == NULL) { fprintf(stderr, "Could not create default configure file %s\n", userpath); - perror(strerror(errno)); + perror("fopen"); exit(1); } fprintf(fd, "%s", DEFAULT_CONGIF_STR); @@ -843,7 +843,7 @@ static void ms_init_random_block() */ static void ms_print_setting() { - fprintf(stdout, "servers : %s\n", ms_setting.srv_str); + fprintf(stdout, "servers: %s\n", ms_setting.srv_str); fprintf(stdout, "threads count: %d\n", ms_setting.nthreads); fprintf(stdout, "concurrency: %d\n", ms_setting.nconns); if (ms_setting.run_time > 0) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ebb39afe..9ea8cd2c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,6 +8,10 @@ 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) diff --git a/test/conf.h.in b/test/conf.h.in index 91843964..40101a63 100644 --- a/test/conf.h.in +++ b/test/conf.h.in @@ -1,5 +1,6 @@ #pragma once +#cmakedefine HAVE_MEMASLAP 1 #cmakedefine HAVE_PIPE2 1 #cmakedefine HAVE_SOCK_NONBLOCK 1 #cmakedefine HAVE_SOCK_CLOEXEC 1 diff --git a/test/tests/bin/memaslap.cpp b/test/tests/bin/memaslap.cpp new file mode 100644 index 00000000..e2c61829 --- /dev/null +++ b/test/tests/bin/memaslap.cpp @@ -0,0 +1,55 @@ +#include "test/lib/common.hpp" +#include "test/lib/Shell.hpp" +#include "test/lib/MemcachedCluster.hpp" + +#if HAVE_MEMASLAP + +using Catch::Matchers::Contains; + +TEST_CASE("bin/memaslap") { + Shell sh{string{TESTING_ROOT "/../src/bin"}}; + + SECTION("no servers provided") { + string output; + REQUIRE_FALSE(sh.run("memaslap", output)); + REQUIRE_THAT(output, Contains("No servers provided\n")); + } + + SECTION("--help") { + string output; + + REQUIRE(sh.run("memaslap --help", output)); + REQUIRE_THAT(output, Contains("memaslap")); + REQUIRE_THAT(output, Contains("v1")); + /* FIXME + REQUIRE_THAT(output, Contains("help")); + REQUIRE_THAT(output, Contains("version")); + REQUIRE_THAT(output, Contains("option")); + */ + REQUIRE_THAT(output, Contains("--")); + REQUIRE_THAT(output, Contains("=")); + } + + SECTION("with servers") { + auto test = MemcachedCluster::network(); + auto examples = { + " -t 2s -S 1s", + " -t 2s -v 0.2 -e 0.05 -b", + " -t 2s -w 40k -S 20s -o 0.2", + " -t 2s -T 4 -c 128 -d 20 -P 40k", + " -t 2s -d 50 -a -n 10", + }; + string servers{"-s "}; + + for (const auto &server : test.cluster.getServers()) { + servers += "127.0.0.1:" + to_string(get(server.getSocketOrPort())) + ","; + } + for (const auto args : examples) { + string output; + INFO(args); + REQUIRE(sh.run("memaslap " + servers + args, output)); + REQUIRE_THAT(output, Contains("TPS")); + } + } +} +#endif // HAVE_MEMASLAP