On 9/20/23 8:59 AM, thinker.li@xxxxxxxxx wrote:
diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c new file mode 100644 index 000000000000..8219a477b6d6 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_module.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ +#include <test_progs.h> + +#include "struct_ops_module.skel.h" +#include "testing_helpers.h" + +static void test_regular_load(void) +{ + struct struct_ops_module *skel; + struct bpf_link *link; + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts); + int err; + + printf("test_regular_load\n"); + skel = struct_ops_module__open_opts(&opts); + if (!ASSERT_OK_PTR(skel, "struct_ops_module_open")) + return; + err = struct_ops_module__load(skel); + if (!ASSERT_OK(err, "struct_ops_module_load")) + return; + + link = bpf_map__attach_struct_ops(skel->maps.testmod_1); + ASSERT_OK_PTR(link, "attach_test_mod_1"); + + ASSERT_EQ(skel->bss->test_2_result, 7, "test_2_result"); + + bpf_link__destroy(link); + + struct_ops_module__destroy(skel); + + /* Wait for the map to be freed, or we may fail to unload + * bpf_testmod. + */ + sleep(1);
Instead of sleep(1), please check if something can be reused from kern_sync_rcu_tasks_trace() in map_kptr.c such that the wait can be done deterministically. If not, waiting for a fexit trace on bpf_struct_ops_map_free probably should work also.