summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
diff options
context:
space:
mode:
authorUdip Pant <udippant@fb.com>2020-08-25 16:20:02 -0700
committerAlexei Starovoitov <ast@kernel.org>2020-08-26 12:47:56 -0700
commit50d19736aff497a4c25ec7e36375195bfd8570cd (patch)
treee47a69ea55e1b60a83aaea5c1ea8907efdccf974 /tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
parent6dc03dc71387e1dc65cf14efb49e5cf7062a2d46 (diff)
selftests/bpf: Test for checking return code for the extended prog
This adds test to enforce same check for the return code for the extended prog as it is enforced for the target program. It asserts failure for a return code, which is permitted without the patch in this series, while it is restricted after the application of this patch. Signed-off-by: Udip Pant <udippant@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200825232003.2877030-4-udippant@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
index 7c7168963d52..d295ca9bbf96 100644
--- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
@@ -142,10 +142,50 @@ static void test_func_replace_verify(void)
prog_name, false);
}
+static void test_func_replace_return_code(void)
+{
+ /*
+ * standalone test that asserts failure to load freplace prog
+ * because of invalid return code.
+ */
+ struct bpf_object *obj = NULL, *pkt_obj;
+ int err, pkt_fd;
+ __u32 duration = 0;
+ const char *target_obj_file = "./connect4_prog.o";
+ const char *obj_file = "./freplace_connect_v4_prog.o";
+
+ err = bpf_prog_load(target_obj_file, BPF_PROG_TYPE_UNSPEC,
+ &pkt_obj, &pkt_fd);
+ /* the target prog should load fine */
+ if (CHECK(err, "tgt_prog_load", "file %s err %d errno %d\n",
+ target_obj_file, err, errno))
+ return;
+ DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
+ .attach_prog_fd = pkt_fd,
+ );
+
+ obj = bpf_object__open_file(obj_file, &opts);
+ if (CHECK(IS_ERR_OR_NULL(obj), "obj_open",
+ "failed to open %s: %ld\n", obj_file,
+ PTR_ERR(obj)))
+ goto close_prog;
+
+ /* It should fail to load the program */
+ err = bpf_object__load(obj);
+ if (CHECK(!err, "bpf_obj_load should fail", "err %d\n", err))
+ goto close_prog;
+
+close_prog:
+ if (!IS_ERR_OR_NULL(obj))
+ bpf_object__close(obj);
+ bpf_object__close(pkt_obj);
+}
+
void test_fexit_bpf2bpf(void)
{
test_target_no_callees();
test_target_yes_callees();
test_func_replace();
test_func_replace_verify();
+ test_func_replace_return_code();
}