[SCM] Samba Shared Repository - branch master updated
Amitay Isaacs
amitay at samba.org
Mon Feb 14 04:33:02 UTC 2022
The branch, master has been updated
via 17d792e9aa3 ctdb-tests: Iterate protocol tests internally
via 2329305019d ctdb-tests: Add iteration support for protocol tests
from 331c435ce52 ctdb-tests: Add a test for stalled node triggering election
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 17d792e9aa38c3d8a2211c7b8ee3e2d88b438922
Author: Martin Schwenke <martin at meltin.net>
Date: Tue Jan 4 12:19:49 2022 +1100
ctdb-tests: Iterate protocol tests internally
Instead of repeatedly running a test binary.
Run time for these tests reduces from ~90s to ~75s.
When run under valgrind, the run time for protocol_test_001.sh reduces
from ~390s to <1s.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
Autobuild-Date(master): Mon Feb 14 04:32:29 UTC 2022 on sn-devel-184
commit 2329305019d2b8521c1ceed76c9a703a1b745e86
Author: Martin Schwenke <martin at meltin.net>
Date: Tue Jan 4 12:18:33 2022 +1100
ctdb-tests: Add iteration support for protocol tests
The current method of repeatedly running a binary has huge overhead,
especially with valgrind.
protocol_test_iterate_tag() allows output that is usually used for
hinting where a test failure occurred to be replaced with a tag
stored in a buffer, which is printed on test failure.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Reviewed-by: Amitay Isaacs <amitay at gmail.com>
-----------------------------------------------------------------------
Summary of changes:
ctdb/event/event_protocol_test.c | 17 +++---
ctdb/tests/UNIT/cunit/event_protocol_test_001.sh | 22 +-------
ctdb/tests/UNIT/cunit/protocol_test_001.sh | 4 +-
ctdb/tests/UNIT/cunit/protocol_test_002.sh | 4 +-
ctdb/tests/UNIT/cunit/protocol_test_012.sh | 4 +-
ctdb/tests/UNIT/cunit/protocol_test_101.sh | 63 +--------------------
ctdb/tests/UNIT/cunit/protocol_test_111.sh | 4 +-
ctdb/tests/src/protocol_basic_test.c | 11 ++--
ctdb/tests/src/protocol_common_basic.c | 70 ++++++++++++++++++++++++
ctdb/tests/src/protocol_common_basic.h | 5 ++
ctdb/tests/src/protocol_ctdb_compat_test.c | 11 ++--
ctdb/tests/src/protocol_ctdb_test.c | 32 ++++-------
ctdb/tests/src/protocol_types_compat_test.c | 11 ++--
ctdb/tests/src/protocol_types_test.c | 11 ++--
14 files changed, 122 insertions(+), 147 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ctdb/event/event_protocol_test.c b/ctdb/event/event_protocol_test.c
index 7f939f881cf..8f34fa5b68d 100644
--- a/ctdb/event/event_protocol_test.c
+++ b/ctdb/event/event_protocol_test.c
@@ -311,8 +311,7 @@ static void TEST_FUNC(NAME)(uint32_t cmd) \
size_t buflen, np; \
int ret; \
\
- printf("%s %u\n", #NAME, cmd); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %u\n", #NAME, cmd); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
FILL_FUNC(NAME)(mem_ctx, &c1, cmd); \
@@ -340,8 +339,7 @@ static void TEST_FUNC(NAME)(uint32_t cmd) \
size_t buflen, len; \
int ret; \
\
- printf("%s %u\n", #NAME, cmd); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %u\n", #NAME, cmd); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
fill_ctdb_event_header(&h1); \
@@ -379,15 +377,10 @@ EVENT_PROTOCOL1_TEST(struct ctdb_event_reply, ctdb_event_reply_data);
EVENT_PROTOCOL2_TEST(struct ctdb_event_request, ctdb_event_request);
EVENT_PROTOCOL2_TEST(struct ctdb_event_reply, ctdb_event_reply);
-int main(int argc, const char **argv)
+static void event_protocol_test(void)
{
uint32_t cmd;
- if (argc == 2) {
- int seed = atoi(argv[1]);
- srandom(seed);
- }
-
TEST_FUNC(ctdb_event_script)();
TEST_FUNC(ctdb_event_script_list)();
@@ -410,6 +403,10 @@ int main(int argc, const char **argv)
for (cmd=1; cmd<CTDB_EVENT_CMD_MAX; cmd++) {
TEST_FUNC(ctdb_event_reply)(cmd);
}
+}
+int main(int argc, const char **argv)
+{
+ protocol_test_iterate(argc, argv, event_protocol_test);
return 0;
}
diff --git a/ctdb/tests/UNIT/cunit/event_protocol_test_001.sh b/ctdb/tests/UNIT/cunit/event_protocol_test_001.sh
index d1a7778c77f..8d5f932aaa0 100755
--- a/ctdb/tests/UNIT/cunit/event_protocol_test_001.sh
+++ b/ctdb/tests/UNIT/cunit/event_protocol_test_001.sh
@@ -2,24 +2,6 @@
. "${TEST_SCRIPTS_DIR}/unit.sh"
-last_command=3
+ok_null
-generate_output ()
-{
- for i in $(seq 1 $last_command) ; do
- echo "$1 $i"
- done
-}
-
-output=$(
- generate_output "ctdb_event_request_data"
- generate_output "ctdb_event_reply_data"
- generate_output "ctdb_event_request"
- generate_output "ctdb_event_reply"
-)
-
-ok "$output"
-
-for i in $(seq 1 100) ; do
- unit_test event_protocol_test $i
-done
+unit_test event_protocol_test 1 100
diff --git a/ctdb/tests/UNIT/cunit/protocol_test_001.sh b/ctdb/tests/UNIT/cunit/protocol_test_001.sh
index 62c1086a03d..7f68c483220 100755
--- a/ctdb/tests/UNIT/cunit/protocol_test_001.sh
+++ b/ctdb/tests/UNIT/cunit/protocol_test_001.sh
@@ -4,6 +4,4 @@
ok_null
-for i in $(seq 1 1000) ; do
- unit_test protocol_basic_test $i
-done
+unit_test protocol_basic_test 1 1000
diff --git a/ctdb/tests/UNIT/cunit/protocol_test_002.sh b/ctdb/tests/UNIT/cunit/protocol_test_002.sh
index 41afda5e9d3..51e05133de0 100755
--- a/ctdb/tests/UNIT/cunit/protocol_test_002.sh
+++ b/ctdb/tests/UNIT/cunit/protocol_test_002.sh
@@ -4,6 +4,4 @@
ok_null
-for i in $(seq 1 1000) ; do
- unit_test protocol_types_test $i
-done
+unit_test protocol_types_test 1 1000
diff --git a/ctdb/tests/UNIT/cunit/protocol_test_012.sh b/ctdb/tests/UNIT/cunit/protocol_test_012.sh
index 6137ac5773b..b9fd4926f2e 100755
--- a/ctdb/tests/UNIT/cunit/protocol_test_012.sh
+++ b/ctdb/tests/UNIT/cunit/protocol_test_012.sh
@@ -4,6 +4,4 @@
ok_null
-for i in $(seq 1 1000) ; do
- unit_test protocol_types_compat_test $i
-done
+unit_test protocol_types_compat_test 1 1000
diff --git a/ctdb/tests/UNIT/cunit/protocol_test_101.sh b/ctdb/tests/UNIT/cunit/protocol_test_101.sh
index e62cd071487..f944c6bd7f2 100755
--- a/ctdb/tests/UNIT/cunit/protocol_test_101.sh
+++ b/ctdb/tests/UNIT/cunit/protocol_test_101.sh
@@ -2,65 +2,6 @@
. "${TEST_SCRIPTS_DIR}/unit.sh"
-last_control=158
+ok_null
-generate_control_output ()
-{
- for i in $(seq 0 $last_control) ; do
- echo "$1 $i"
- done
-}
-
-srvid_list="\
- f002000000000000 \
- f100000000000000 \
- f101000000000000 \
- f200000000000000 \
- f300000000000000 \
- f301000000000000 \
- f400000000000000 \
- f500000000000000 \
- f700000000000000 \
- f701000000000000 \
- f800000000000000 \
- f801000000000000 \
- f802000000000000 \
- f900000000000000 \
- fa00000000000000 \
- fb00000000000000 \
- fb01000000000000 \
- fb03000000000000 \
- fb04000000000000 \
- fc00000000000000 \
-"
-
-generate_message_output ()
-{
- for i in $srvid_list ; do
- echo "$1 $i"
- done
-}
-
-output=$(
- echo "ctdb_req_header"
- echo "ctdb_req_call"
- echo "ctdb_reply_call"
- echo "ctdb_reply_error"
- echo "ctdb_req_dmaster"
- echo "ctdb_reply_dmaster"
- generate_control_output "ctdb_req_control_data"
- generate_control_output "ctdb_reply_control_data"
- generate_control_output "ctdb_req_control"
- generate_control_output "ctdb_reply_control"
- generate_message_output "ctdb_message_data"
- generate_message_output "ctdb_req_message"
- echo "ctdb_req_message_data"
- echo "ctdb_req_keepalive"
- echo "ctdb_req_tunnel"
-)
-
-ok "$output"
-
-for i in $(seq 1 100) ; do
- unit_test protocol_ctdb_test $i
-done
+unit_test protocol_ctdb_test 1 100
diff --git a/ctdb/tests/UNIT/cunit/protocol_test_111.sh b/ctdb/tests/UNIT/cunit/protocol_test_111.sh
index 72f7c122a54..28d190cdcce 100755
--- a/ctdb/tests/UNIT/cunit/protocol_test_111.sh
+++ b/ctdb/tests/UNIT/cunit/protocol_test_111.sh
@@ -4,6 +4,4 @@
ok_null
-for i in $(seq 1 100) ; do
- unit_test protocol_ctdb_compat_test $i
-done
+unit_test protocol_ctdb_compat_test 1 100
diff --git a/ctdb/tests/src/protocol_basic_test.c b/ctdb/tests/src/protocol_basic_test.c
index 215c0829854..7046718bc18 100644
--- a/ctdb/tests/src/protocol_basic_test.c
+++ b/ctdb/tests/src/protocol_basic_test.c
@@ -78,13 +78,8 @@ static void test_ctdb_padding(void)
assert(np == buflen);
}
-int main(int argc, char *argv[])
+static void protocol_basic_test(void)
{
- if (argc == 2) {
- int seed = atoi(argv[1]);
- srandom(seed);
- }
-
TEST_FUNC(ctdb_uint8)();
TEST_FUNC(ctdb_uint16)();
TEST_FUNC(ctdb_int32)();
@@ -102,6 +97,10 @@ int main(int argc, char *argv[])
TEST_FUNC(ctdb_timeval)();
test_ctdb_padding();
+}
+int main(int argc, const char *argv[])
+{
+ protocol_test_iterate(argc, argv, protocol_basic_test);
return 0;
}
diff --git a/ctdb/tests/src/protocol_common_basic.c b/ctdb/tests/src/protocol_common_basic.c
index b8b82fd298c..668fb46cfb3 100644
--- a/ctdb/tests/src/protocol_common_basic.c
+++ b/ctdb/tests/src/protocol_common_basic.c
@@ -229,3 +229,73 @@ void verify_ctdb_timeval(struct timeval *p1, struct timeval *p2)
assert(p1->tv_usec == p2->tv_usec);
}
+static unsigned int seed;
+static char protocol_test_iterate_buf[1024];
+
+static void protocol_test_iterate_abort_handler(int sig)
+{
+ struct sigaction act = {
+ .sa_handler = SIG_DFL,
+ };
+
+ fprintf(stderr, "Failed with seed: %d\n", seed);
+ if (protocol_test_iterate_buf[0] != '\0') {
+ fprintf(stderr, " tag: %s\n", protocol_test_iterate_buf);
+ }
+ sigaction(SIGABRT, &act, NULL);
+ abort();
+}
+
+void protocol_test_iterate_tag(const char *fmt, ...)
+{
+ va_list ap;
+ int count;
+
+ va_start(ap,fmt);
+ count = vsnprintf(protocol_test_iterate_buf,
+ sizeof(protocol_test_iterate_buf),
+ fmt,
+ ap);
+ va_end(ap);
+
+ assert(count >= 0);
+ protocol_test_iterate_buf[sizeof(protocol_test_iterate_buf) - 1] = '\0';
+}
+
+void protocol_test_iterate(int argc,
+ const char *argv[],
+ void (*test_func)(void))
+{
+ struct sigaction act = {
+ .sa_handler = protocol_test_iterate_abort_handler,
+ };
+ unsigned int min, max;
+
+ if (argc == 2 || argc == 3) {
+ min = atoi(argv[1]);
+
+ if (argc == 3) {
+ max = atoi(argv[2]);
+ if (min >= max) {
+ fprintf(stderr,
+ "%s: min must be less than max\n",
+ argv[0]);
+ exit(1);
+ }
+
+ } else {
+ max = min;
+ }
+ } else {
+ fprintf(stderr, "usage: %s min [max]\n", argv[0]);
+ exit(1);
+ }
+
+ sigaction(SIGABRT, &act, NULL);
+
+ for (seed = min; seed <= max ; seed++) {
+ srandom(seed);
+
+ test_func();
+ }
+}
diff --git a/ctdb/tests/src/protocol_common_basic.h b/ctdb/tests/src/protocol_common_basic.h
index 0f32a0813db..22a11b38de5 100644
--- a/ctdb/tests/src/protocol_common_basic.h
+++ b/ctdb/tests/src/protocol_common_basic.h
@@ -165,6 +165,11 @@ void verify_ctdb_pid(pid_t *p1, pid_t *p2);
void fill_ctdb_timeval(struct timeval *p);
void verify_ctdb_timeval(struct timeval *p1, struct timeval *p2);
+void protocol_test_iterate_tag(const char *fmt, ...) PRINTF_ATTRIBUTE(1,0);
+void protocol_test_iterate(int argc,
+ const char *argv[],
+ void (*test_func)(void));
+
#endif /* __CTDB_PROTOCOL_COMMON_BASIC_H__ */
diff --git a/ctdb/tests/src/protocol_ctdb_compat_test.c b/ctdb/tests/src/protocol_ctdb_compat_test.c
index 1c236361128..fc9f82e8230 100644
--- a/ctdb/tests/src/protocol_ctdb_compat_test.c
+++ b/ctdb/tests/src/protocol_ctdb_compat_test.c
@@ -1212,7 +1212,7 @@ COMPAT_CTDB4_TEST(struct ctdb_req_tunnel, ctdb_req_tunnel, CTDB_REQ_TUNNEL);
#define NUM_CONTROLS 151
-int main(int argc, char *argv[])
+static void protocol_ctdb_compat_test(void)
{
uint32_t opcode;
uint64_t test_srvid[] = {
@@ -1239,11 +1239,6 @@ int main(int argc, char *argv[])
};
unsigned int i;
- if (argc == 2) {
- int seed = atoi(argv[1]);
- srandom(seed);
- }
-
COMPAT_TEST_FUNC(ctdb_req_header)();
COMPAT_TEST_FUNC(ctdb_req_call)();
@@ -1266,6 +1261,10 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_req_keepalive)();
COMPAT_TEST_FUNC(ctdb_req_tunnel)();
+}
+int main(int argc, const char *argv[])
+{
+ protocol_test_iterate(argc, argv, protocol_ctdb_compat_test);
return 0;
}
diff --git a/ctdb/tests/src/protocol_ctdb_test.c b/ctdb/tests/src/protocol_ctdb_test.c
index 1650c633800..f6fb5134a00 100644
--- a/ctdb/tests/src/protocol_ctdb_test.c
+++ b/ctdb/tests/src/protocol_ctdb_test.c
@@ -46,8 +46,7 @@ static void TEST_FUNC(NAME)(void) \
size_t pkt_len, buflen, np; \
int ret; \
\
- printf("%s\n", #NAME); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s\n", #NAME); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
FILL_FUNC(NAME)(&c1); \
@@ -77,8 +76,7 @@ static void TEST_FUNC(NAME)(uint32_t opcode) \
size_t pkt_len, buflen, np; \
int ret; \
\
- printf("%s %u\n", #NAME, opcode); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %u\n", #NAME, opcode); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
FILL_FUNC(NAME)(mem_ctx, &c1, opcode); \
@@ -108,8 +106,7 @@ static void TEST_FUNC(NAME)(uint64_t srvid) \
size_t pkt_len, buflen, np; \
int ret; \
\
- printf("%s %"PRIx64"\n", #NAME, srvid); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %"PRIx64"\n", #NAME, srvid); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
FILL_FUNC(NAME)(mem_ctx, &c1, srvid); \
@@ -140,8 +137,7 @@ static void TEST_FUNC(NAME)(void) \
size_t pkt_len, buflen, len; \
int ret; \
\
- printf("%s\n", #NAME); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s\n", #NAME); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
fill_ctdb_req_header(&h1); \
@@ -176,8 +172,7 @@ static void TEST_FUNC(NAME)(uint32_t opcode) \
size_t pkt_len, buflen, len; \
int ret; \
\
- printf("%s %u\n", #NAME, opcode); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %u\n", #NAME, opcode); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
fill_ctdb_req_header(&h1); \
@@ -212,8 +207,7 @@ static void TEST_FUNC(NAME)(uint32_t opcode) \
size_t pkt_len, buflen, len; \
int ret; \
\
- printf("%s %u\n", #NAME, opcode); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %u\n", #NAME, opcode); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
fill_ctdb_req_header(&h1); \
@@ -248,8 +242,7 @@ static void TEST_FUNC(NAME)(uint64_t srvid) \
size_t pkt_len, buflen, len; \
int ret; \
\
- printf("%s %"PRIx64"\n", #NAME, srvid); \
- fflush(stdout); \
+ protocol_test_iterate_tag("%s %"PRIx64"\n", #NAME, srvid); \
mem_ctx = talloc_new(NULL); \
assert(mem_ctx != NULL); \
fill_ctdb_req_header(&h1); \
@@ -304,7 +297,7 @@ PROTOCOL_CTDB4_TEST(struct ctdb_req_keepalive, ctdb_req_keepalive,
CTDB_REQ_KEEPALIVE);
PROTOCOL_CTDB4_TEST(struct ctdb_req_tunnel, ctdb_req_tunnel, CTDB_REQ_TUNNEL);
-int main(int argc, char *argv[])
+static void protocol_ctdb_test(void)
{
uint32_t opcode;
uint64_t test_srvid[] = {
@@ -331,11 +324,6 @@ int main(int argc, char *argv[])
};
size_t i;
- if (argc == 2) {
- int seed = atoi(argv[1]);
- srandom(seed);
- }
-
TEST_FUNC(ctdb_req_header)();
TEST_FUNC(ctdb_req_call)();
@@ -368,6 +356,10 @@ int main(int argc, char *argv[])
TEST_FUNC(ctdb_req_keepalive)();
TEST_FUNC(ctdb_req_tunnel)();
+}
+int main(int argc, const char *argv[])
+{
+ protocol_test_iterate(argc, argv, protocol_ctdb_test);
return 0;
}
diff --git a/ctdb/tests/src/protocol_types_compat_test.c b/ctdb/tests/src/protocol_types_compat_test.c
index 59aef825b72..140ea86078c 100644
--- a/ctdb/tests/src/protocol_types_compat_test.c
+++ b/ctdb/tests/src/protocol_types_compat_test.c
@@ -2317,13 +2317,8 @@ COMPAT_TYPE1_TEST(struct ctdb_g_lock, ctdb_g_lock);
COMPAT_TYPE3_TEST(struct ctdb_g_lock_list, ctdb_g_lock_list);
-int main(int argc, char *argv[])
+static void protocol_types_compat_test(void)
{
- if (argc == 2) {
- int seed = atoi(argv[1]);
- srandom(seed);
- }
-
COMPAT_TEST_FUNC(ctdb_statistics)();
COMPAT_TEST_FUNC(ctdb_vnn_map)();
COMPAT_TEST_FUNC(ctdb_dbid_map)();
@@ -2367,6 +2362,10 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_server_id)();
COMPAT_TEST_FUNC(ctdb_g_lock)();
COMPAT_TEST_FUNC(ctdb_g_lock_list)();
+}
+int main(int argc, const char *argv[])
+{
+ protocol_test_iterate(argc, argv, protocol_types_compat_test);
return 0;
}
diff --git a/ctdb/tests/src/protocol_types_test.c b/ctdb/tests/src/protocol_types_test.c
--
Samba Shared Repository
More information about the samba-cvs
mailing list