[PATCHv2 bpf-next 3/7] selftests/bpf: Do not unload bpf_testmod in load_bpf_testmod

Jiri Olsa
2023-01-30T08:56:27Z

Do not unload bpf_testmod in load_bpf_testmod, instead call
unload_bpf_testmod separatelly.

This way we will be able use un/load_bpf_testmod functions
in other tests that un/load bpf_testmod module.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/testing/selftests/bpf/test_progs.c | 11 ++++++++---
tools/testing/selftests/bpf/testing_helpers.c | 3 ---
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index a150c35516ef..9ca718c84890 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1592,9 +1592,14 @@ int main(int argc, char **argv)
env.stderr = stderr;

env.has_testmod = true;
- if (!env.list_test_names && load_bpf_testmod(env.stderr, verbose())) {
- fprintf(env.stderr, "WARNING! Selftests relying on bpf_testmod.ko will be skipped.\n");
- env.has_testmod = false;
+ if (!env.list_test_names) {
+ /* ensure previous instance of the module is unloaded */
+ unload_bpf_testmod(env.stderr, verbose());
+
+ if (load_bpf_testmod(env.stderr, verbose())) {
+ fprintf(env.stderr, "WARNING! Selftests relying on bpf_testmod.ko will be skipped.\n");
+ env.has_testmod = false;
+ }
}

/* initializing tests */
diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c
index c0eb54bf08b3..ade6208b4a69 100644
--- a/tools/testing/selftests/bpf/testing_helpers.c
+++ b/tools/testing/selftests/bpf/testing_helpers.c
@@ -262,9 +262,6 @@ int load_bpf_testmod(FILE *err, bool verbose)
{
int fd;

- /* ensure previous instance of the module is unloaded */
- unload_bpf_testmod(err, verbose);
-
if (verbose)
fprintf(stdout, "Loading bpf_testmod.ko...\n");

--
2.39.1