Re: [PATCH bpf-next v1 8/8] selftests/bpf: tests for struct_ops autoload/autocreate toggling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 27, 2024 at 10:45:56PM +0200, Eduard Zingerman wrote:
> Verify automatic interaction between struct_ops map autocreate flag
> and struct_ops programs autoload flags.
> 
> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>
> ---
>  .../bpf/prog_tests/struct_ops_autocreate.c    | 65 +++++++++++++++++--
>  1 file changed, 61 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/struct_ops_autocreate.c b/tools/testing/selftests/bpf/prog_tests/struct_ops_autocreate.c
> index b21b10f94fc2..ace296aae8c4 100644
> --- a/tools/testing/selftests/bpf/prog_tests/struct_ops_autocreate.c
> +++ b/tools/testing/selftests/bpf/prog_tests/struct_ops_autocreate.c
> @@ -46,10 +46,6 @@ static void can_load_partial_object(void)
>  	if (!ASSERT_OK_PTR(skel, "struct_ops_autocreate__open_opts"))
>  		return;
>  
> -	err = bpf_program__set_autoload(skel->progs.test_2, false);
> -	if (!ASSERT_OK(err, "bpf_program__set_autoload"))
> -		goto cleanup;
> -
>  	err = bpf_map__set_autocreate(skel->maps.testmod_2, false);
>  	if (!ASSERT_OK(err, "bpf_map__set_autocreate"))
>  		goto cleanup;
> @@ -70,8 +66,69 @@ static void can_load_partial_object(void)
>  	struct_ops_autocreate__destroy(skel);
>  }
>  
> +static void autoload_toggles(void)
> +{
> +	DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);
> +	struct bpf_map *testmod_1, *testmod_2;
> +	struct bpf_program *test_1, *test_2;
> +	struct struct_ops_autocreate *skel;
> +
> +	skel = struct_ops_autocreate__open_opts(&opts);
> +	if (!ASSERT_OK_PTR(skel, "struct_ops_autocreate__open_opts"))
> +		return;
> +
> +	testmod_1 = skel->maps.testmod_1;
> +	testmod_2 = skel->maps.testmod_2;
> +	test_1 = skel->progs.test_1;
> +	test_2 = skel->progs.test_2;
> +
> +	/* testmod_1 on, testmod_2 on */
> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #1");
> +	ASSERT_TRUE(bpf_program__autoload(test_2), "autoload(test_2) #1");
> +
> +	/* testmod_1 off, testmod_2 on */
> +	bpf_map__set_autocreate(testmod_1, false);
> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #2");
> +	ASSERT_TRUE(bpf_program__autoload(test_2), "autoload(test_2) #2");
> +
> +	/* testmod_1 off, testmod_2 off,
> +	 * setting same state several times should not confuse internal state.
> +	 */
> +	bpf_map__set_autocreate(testmod_2, false);
> +	bpf_map__set_autocreate(testmod_2, false);

Duplicate line

> +	ASSERT_FALSE(bpf_program__autoload(test_1), "autoload(test_1) #3");
> +	ASSERT_FALSE(bpf_program__autoload(test_2), "autoload(test_2) #3");
> +
> +	/* testmod_1 on, testmod_2 off */
> +	bpf_map__set_autocreate(testmod_1, true);
> +	bpf_map__set_autocreate(testmod_1, true);

Here as well

> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #4");
> +	ASSERT_FALSE(bpf_program__autoload(test_2), "autoload(test_2) #4");
> +
> +	/* testmod_1 on, testmod_2 on */
> +	bpf_map__set_autocreate(testmod_2, true);
> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #5");
> +	ASSERT_TRUE(bpf_program__autoload(test_2), "autoload(test_2) #5");
> +
> +	/* testmod_1 on, testmod_2 off */
> +	bpf_map__set_autocreate(testmod_2, false);
> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #6");
> +	ASSERT_FALSE(bpf_program__autoload(test_2), "autoload(test_2) #6");
> +
> +	/* setting autoload manually overrides automatic toggling */
> +	bpf_program__set_autoload(test_2, false);
> +	/* testmod_1 on, testmod_2 off */
> +	bpf_map__set_autocreate(testmod_2, true);
> +	ASSERT_TRUE(bpf_program__autoload(test_1), "autoload(test_1) #7");
> +	ASSERT_FALSE(bpf_program__autoload(test_2), "autoload(test_2) #7");
> +
> +	struct_ops_autocreate__destroy(skel);
> +}
> +
>  void serial_test_struct_ops_autocreate(void)
>  {
> +	if (test__start_subtest("autoload_toggles"))
> +		autoload_toggles();
>  	if (test__start_subtest("cant_load_full_object"))
>  		cant_load_full_object();
>  	if (test__start_subtest("can_load_partial_object"))
> -- 
> 2.43.0
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux