Skip to contentSkip to conversation

test_bpf: add module parameter test_type

PATCH New Tiezhu Yang 1 participant 1 message Sep 30, 2021

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

PATCH v2 1/1 test_bpf: add module parameter test_type

From: Tiezhu Yang <[email protected]>

After commit 9298e63eafea ("bpf/tests: Add exhaustive tests of ALU operand magnitudes"), when modprobe test_bpf.ko with jit on mips64, there exists segment fault due to the following reason:

test_bpf: #616 ALU64_MOV_X: all register value magnitudes jited:1 Break instruction in kernel code[#1]

It seems that the related jit implementations of some test cases in test_bpf() have problems. At this moment, I do not care about the segment fault while I just want to verify the test cases of tail calls.

Based on the above background and motivation, add the following module parameter test_type to the test_bpf.ko:
test_type=<string>: only the specified type will be run, the string can be "test_bpf", "test_tail_calls" or "test_skb_segment".

This is useful to only test the corresponding test type when specify the valid test_type string.

Any invalid test type will result in -EINVAL being returned and no tests being run. If the test_type is not specified or specified as empty string, it does not change the current logic, all of the test cases will be run.

---

v2:
-- Fix typo in the commit message
-- Use my private email to send

 lib/test_bpf.c | 48 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 15 deletions(-)
lib/test_bpf.c +33 -15
index 21ea1ab..9428fec 100644
@@ -11866,6 +11866,9 @@ module_param(test_id, int, 0);
 static int test_range[2] = { 0, ARRAY_SIZE(tests) - 1 };
 module_param_array(test_range, int, NULL, 0);
 
+static char test_type[32];
+module_param_string(test_type, test_type, sizeof(test_type), 0);
+
 static __init int find_test_index(const char *test_name)
 {
 	int i;
@@ -12518,24 +12521,39 @@ static int __init test_bpf_init(void)
 	struct bpf_array *progs = NULL;
 	int ret;
 
-	ret = prepare_bpf_tests();
-	if (ret < 0)
-		return ret;
+	if (strlen(test_type) &&
+	    strcmp(test_type, "test_bpf") &&
+	    strcmp(test_type, "test_tail_calls") &&
+	    strcmp(test_type, "test_skb_segment")) {
+		pr_err("test_bpf: invalid test_type '%s' specified.\n", test_type);
+		return -EINVAL;
+	}
+
+	if (!strlen(test_type) || !strcmp(test_type, "test_bpf")) {
+		ret = prepare_bpf_tests();
+		if (ret < 0)
+			return ret;
+
+		ret = test_bpf();
+		destroy_bpf_tests();
+		if (ret)
+			return ret;
+	}
 
-	ret = test_bpf();
-	destroy_bpf_tests();
-	if (ret)
-		return ret;
+	if (!strlen(test_type) || !strcmp(test_type, "test_tail_calls")) {
+		ret = prepare_tail_call_tests(&progs);
+		if (ret)
+			return ret;
+		ret = test_tail_calls(progs);
+		destroy_tail_call_tests(progs);
+		if (ret)
+			return ret;
+	}
 
-	ret = prepare_tail_call_tests(&progs);
-	if (ret)
-		return ret;
-	ret = test_tail_calls(progs);
-	destroy_tail_call_tests(progs);
-	if (ret)
-		return ret;
+	if (!strlen(test_type) || !strcmp(test_type, "test_skb_segment"))
+		return test_skb_segment();
 
-	return test_skb_segment();
+	return 0;
 }
 
 static void __exit test_bpf_exit(void)
Signature · 1 line
2.1.0