Skip to contentSkip to conversation

selftests/bpf: refactor prog_tests logging and test execution

PATCH Applied Mykola Lysenko 3 participants 3 messages Apr 18, 2022 – Apr 19, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/bpf: refactor prog_tests logging and test execution

This is a pre-req to add separate logging for each subtest in test_progs.

Move all the mutable test data to the test_result struct. Move per-test init/de-init into the run_one_test function. Consolidate data aggregation and final log output in calculate_and_print_summary function.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.

Also, add prog_tests_framework.c test to verify some of the counting logic.

As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution.

---
 .../selftests/bpf/prog_tests/bpf_mod_race.c   |   4 +-
 .../bpf/prog_tests/prog_tests_framework.c     |  56 +++
 tools/testing/selftests/bpf/test_progs.c      | 327 +++++++-----------
 tools/testing/selftests/bpf/test_progs.h      |  35 +-
 4 files changed, 202 insertions(+), 220 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c
tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c +2 -2
index d43f548c572c..a4d0cc9d3367 100644
@@ -36,13 +36,13 @@ struct test_config {
 	void (*bpf_destroy)(void *);
 };
 
-enum test_state {
+enum bpf_test_state {
 	_TS_INVALID,
 	TS_MODULE_LOAD,
 	TS_MODULE_LOAD_FAIL,
 };
 
-static _Atomic enum test_state state = _TS_INVALID;
+static _Atomic enum bpf_test_state state = _TS_INVALID;
 
 static int sys_finit_module(int fd, const char *param_values, int flags)
 {
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c new file +56 -0

56 lines not on this page · raw message

tools/testing/selftests/bpf/test_progs.c +117 -210

572 lines not on this page · raw message

tools/testing/selftests/bpf/test_progs.h +27 -8
index 6a8d68bb459e..0a102ce460d6 100644
@@ -64,6 +64,25 @@ struct test_selector {
 	int num_set_len;
 };
 
+struct test_state {
+	bool tested;
+	bool force_log;
+
+	int error_cnt;
+	int skip_cnt;
+	int subtest_skip_cnt;
+	int sub_succ_cnt;
+
+	char *subtest_name;
+	int subtest_num;
+
+	/* store counts before subtest started */
+	int old_error_cnt;
+
+	size_t log_cnt;
+	char *log_buf;
+};
+
 struct test_env {
 	struct test_selector test_selector;
 	struct test_selector subtest_selector;
@@ -76,12 +95,11 @@ struct test_env {
 	bool get_test_cnt;
 	bool list_test_names;
 
-	struct prog_test_def *test; /* current running tests */
+	struct prog_test_def *test; /* current running test */
+	struct test_state *test_state; /* current running test result */
 
 	FILE *stdout;
 	FILE *stderr;
-	char *log_buf;
-	size_t log_cnt;
 	int nr_cpus;
 
 	int succ_cnt; /* successful tests */
@@ -126,11 +144,12 @@ struct msg {
 
 extern struct test_env env;
 
-extern void test__force_log();
-extern bool test__start_subtest(const char *name);
-extern void test__skip(void);
-extern void test__fail(void);
-extern int test__join_cgroup(const char *path);
+void test__force_log(void);
+bool test__start_subtest(const char *name);
+void test__end_subtest(void);
+void test__skip(void);
+void test__fail(void);
+int test__join_cgroup(const char *path);
 
 #define PRINT_FAIL(format...)                                                  \
 	({                                                                     \
Signature · 1 line
2.30.2
#1 lore raw
Quoted 15 lines · Mykola Lysenko

This is a pre-req to add separate logging for each subtest in test_progs.

Move all the mutable test data to the test_result struct. Move per-test init/de-init into the run_one_test function. Consolidate data aggregation and final log output in calculate_and_print_summary function.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.

Also, add prog_tests_framework.c test to verify some of the counting logic.

Quoted 6 lines

As part of verification, confirmed that number of reported tests is the same before and after the change for both parallel and sequential test execution.

---

I've added %-3d to test number output so that it's a bit more aligned:

#178 test_global_funcs:OK
#173 tcp_hdr_options:OK
#50 d_path:OK
#132 send_signal:OK
#23 btf_map_in_map:OK
#10 bpf_iter:OK
#184 test_skb_pkt_end:OK
#185 test_strncmp:OK
#46 core_reloc_btfgen:SKIP

And applied to bpf-next, thanks. Looking forward to subtest logging improvements!

Quoted 7 lines
 .../selftests/bpf/prog_tests/bpf_mod_race.c   |   4 +-
 .../bpf/prog_tests/prog_tests_framework.c     |  56 +++
 tools/testing/selftests/bpf/test_progs.c      | 327 +++++++-----------
 tools/testing/selftests/bpf/test_progs.h      |  35 +-
 4 files changed, 202 insertions(+), 220 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c

[...]

tools/testing/selftests/bpf/test_progs.c static void restore_netns(void) · line 209

Quoted 9 lines

/* A bunch of tests set custom affinity per-thread and/or per-process. Reset

tools/testing/selftests/bpf/test_progs.c +1 -1
@@ -219,72 +205,79 @@ static void restore_netns(void)
 void test__end_subtest(void)
 {
        struct prog_test_def *test = env.test;
-       int sub_error_cnt = test->error_cnt - test->old_error_cnt;
+       struct test_state *state = env.test_state;
 

this empty lines was breaking variable declaration block into two separate blocks, I've removed an empty line here

Quoted 4 lines
tools/testing/selftests/bpf/test_progs.c +1 -1
-       dump_test_log(test, sub_error_cnt);
+       int sub_error_cnt = state->error_cnt - state->old_error_cnt;
 
        fprintf(stdout, "#%d/%d %s/%s:%s\n",

[...]

#2 lore raw
In reply to Mykola Lysenko
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 11 lines · On Mon, 18 Apr 2022 15:25:07 -0700 you wrote:

This is a pre-req to add separate logging for each subtest in test_progs.

Move all the mutable test data to the test_result struct. Move per-test init/de-init into the run_one_test function. Consolidate data aggregation and final log output in calculate_and_print_summary function.
As a side effect, this patch fixes double counting of errors for subtests and possible duplicate output of subtest log on failures.

Quoted 1 line

[...]

Here is the summary with links:
- [v2,bpf-next] selftests/bpf: refactor prog_tests logging and test execution

    https://git.kernel.org/bpf/bpf-next/c/2324257dbd68

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html