diff options
| author | Eduard Zingerman <[email protected]> | 2024-03-06 12:45:23 +0200 | 
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2024-03-06 15:18:15 -0800 | 
| commit | 651d49f15b2a84b3bcfe950fa99c3672b9619dbd (patch) | |
| tree | eea5bdf4b6fe6d7b31445339fba8e799bf8ad623 /tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c | |
| parent | fe9d049c3da06373a1a35914b7f695509e4cb1fe (diff) | |
selftests/bpf: Verify struct_ops autoload/autocreate sync
Check that autocreate flags of struct_ops map cause autoload of
struct_ops corresponding programs:
- when struct_ops program is referenced only from a map for which
  autocreate is set to false, that program should not be loaded;
- when struct_ops program with autoload == false is set to be used
  from a map with autocreate == true using shadow var,
  that program should be loaded;
- when struct_ops program is not referenced from any map object load
  should fail.
Signed-off-by: Eduard Zingerman <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c')
| -rw-r--r-- | tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c b/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c index 9f5dbefa0dd9..6a707213e46b 100644 --- a/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c +++ b/tools/testing/selftests/bpf/prog_tests/bad_struct_ops.c @@ -2,6 +2,7 @@  #include <test_progs.h>  #include "bad_struct_ops.skel.h" +#include "bad_struct_ops2.skel.h"  static void invalid_prog_reuse(void)  { @@ -28,8 +29,39 @@ cleanup:  	bad_struct_ops__destroy(skel);  } +static void unused_program(void) +{ +	struct bad_struct_ops2 *skel; +	char *log = NULL; +	int err; + +	skel = bad_struct_ops2__open(); +	if (!ASSERT_OK_PTR(skel, "bad_struct_ops2__open")) +		return; + +	/* struct_ops programs not referenced from any maps are open +	 * with autoload set to true. +	 */ +	ASSERT_TRUE(bpf_program__autoload(skel->progs.foo), "foo autoload == true"); + +	if (start_libbpf_log_capture()) +		goto cleanup; + +	err = bad_struct_ops2__load(skel); +	ASSERT_ERR(err, "bad_struct_ops2__load should fail"); +	log = stop_libbpf_log_capture(); +	ASSERT_HAS_SUBSTR(log, "prog 'foo': failed to load", +			  "message about 'foo' failing to load"); + +cleanup: +	free(log); +	bad_struct_ops2__destroy(skel); +} +  void test_bad_struct_ops(void)  {  	if (test__start_subtest("invalid_prog_reuse"))  		invalid_prog_reuse(); +	if (test__start_subtest("unused_program")) +		unused_program();  } |