Skip to content

Commit

Permalink
ctdb-tests: Iterate protocol tests internally
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Amitay Isaacs <[email protected]>

Autobuild-User(master): Amitay Isaacs <[email protected]>
Autobuild-Date(master): Mon Feb 14 04:32:29 UTC 2022 on sn-devel-184
  • Loading branch information
martin-schwenke authored and Amitay Isaacs committed Feb 14, 2022
1 parent 2329305 commit 17d792e
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 147 deletions.
17 changes: 7 additions & 10 deletions ctdb/event/event_protocol_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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)();

Expand All @@ -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;
}
22 changes: 2 additions & 20 deletions ctdb/tests/UNIT/cunit/event_protocol_test_001.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions ctdb/tests/UNIT/cunit/protocol_test_001.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions ctdb/tests/UNIT/cunit/protocol_test_002.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions ctdb/tests/UNIT/cunit/protocol_test_012.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 2 additions & 61 deletions ctdb/tests/UNIT/cunit/protocol_test_101.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions ctdb/tests/UNIT/cunit/protocol_test_111.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions ctdb/tests/src/protocol_basic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
Expand All @@ -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;
}
11 changes: 5 additions & 6 deletions ctdb/tests/src/protocol_ctdb_compat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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)();
Expand All @@ -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;
}
32 changes: 12 additions & 20 deletions ctdb/tests/src/protocol_ctdb_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down Expand Up @@ -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[] = {
Expand All @@ -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)();
Expand Down Expand Up @@ -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;
}
11 changes: 5 additions & 6 deletions ctdb/tests/src/protocol_types_compat_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
Expand Down Expand Up @@ -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;
}
11 changes: 5 additions & 6 deletions ctdb/tests/src/protocol_types_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,8 @@ static void test_ctdb_rec_buffer_read_write(void)
talloc_free(mem_ctx);
}

int main(int argc, char *argv[])
static void protocol_types_test(void)
{
if (argc == 2) {
int seed = atoi(argv[1]);
srandom(seed);
}

TEST_FUNC(ctdb_tdb_data)();
TEST_FUNC(ctdb_tdb_datan)();
TEST_FUNC(ctdb_latency_counter)();
Expand Down Expand Up @@ -190,6 +185,10 @@ int main(int argc, char *argv[])
TEST_FUNC(sock_packet_header)();

test_ctdb_rec_buffer_read_write();
}

int main(int argc, const char *argv[])
{
protocol_test_iterate(argc, argv, protocol_types_test);
return 0;
}

0 comments on commit 17d792e

Please sign in to comment.