1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3 #include <test_progs.h>
5 #include "struct_ops_maybe_null.skel.h"
6 #include "struct_ops_maybe_null_fail.skel.h"
8 /* Test that the verifier accepts a program that access a nullable pointer
11 static void maybe_null(void)
13 struct struct_ops_maybe_null *skel;
15 skel = struct_ops_maybe_null__open_and_load();
16 if (!ASSERT_OK_PTR(skel, "struct_ops_module_open_and_load"))
19 struct_ops_maybe_null__destroy(skel);
22 /* Test that the verifier rejects a program that access a nullable pointer
23 * without a check beforehand.
25 static void maybe_null_fail(void)
27 struct struct_ops_maybe_null_fail *skel;
29 skel = struct_ops_maybe_null_fail__open_and_load();
30 if (ASSERT_ERR_PTR(skel, "struct_ops_module_fail__open_and_load"))
33 struct_ops_maybe_null_fail__destroy(skel);
36 void test_struct_ops_maybe_null(void)
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.
42 if (test__start_subtest("maybe_null"))
44 if (test__start_subtest("maybe_null_fail"))