]> Git Repo - J-linux.git/blob - tools/testing/selftests/bpf/prog_tests/test_struct_ops_maybe_null.c
Merge tag 'vfs-6.13-rc7.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[J-linux.git] / tools / testing / selftests / bpf / prog_tests / test_struct_ops_maybe_null.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3 #include <test_progs.h>
4
5 #include "struct_ops_maybe_null.skel.h"
6 #include "struct_ops_maybe_null_fail.skel.h"
7
8 /* Test that the verifier accepts a program that access a nullable pointer
9  * with a proper check.
10  */
11 static void maybe_null(void)
12 {
13         struct struct_ops_maybe_null *skel;
14
15         skel = struct_ops_maybe_null__open_and_load();
16         if (!ASSERT_OK_PTR(skel, "struct_ops_module_open_and_load"))
17                 return;
18
19         struct_ops_maybe_null__destroy(skel);
20 }
21
22 /* Test that the verifier rejects a program that access a nullable pointer
23  * without a check beforehand.
24  */
25 static void maybe_null_fail(void)
26 {
27         struct struct_ops_maybe_null_fail *skel;
28
29         skel = struct_ops_maybe_null_fail__open_and_load();
30         if (ASSERT_ERR_PTR(skel, "struct_ops_module_fail__open_and_load"))
31                 return;
32
33         struct_ops_maybe_null_fail__destroy(skel);
34 }
35
36 void test_struct_ops_maybe_null(void)
37 {
38         /* The verifier verifies the programs at load time, so testing both
39          * programs in the same compile-unit is complicated. We run them in
40          * separate objects to simplify the testing.
41          */
42         if (test__start_subtest("maybe_null"))
43                 maybe_null();
44         if (test__start_subtest("maybe_null_fail"))
45                 maybe_null_fail();
46 }
This page took 0.028833 seconds and 4 git commands to generate.