1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
3 #include <test_progs.h>
4 #include "test_subprogs.skel.h"
5 #include "test_subprogs_unused.skel.h"
12 static void *toggle_jit_harden(void *arg)
14 struct toggler_ctx *ctx = arg;
19 lseek(ctx->fd, SEEK_SET, 0);
20 write(ctx->fd, &two, sizeof(two));
21 lseek(ctx->fd, SEEK_SET, 0);
22 write(ctx->fd, &zero, sizeof(zero));
28 static void test_subprogs_with_jit_harden_toggling(void)
30 struct toggler_ctx ctx;
33 unsigned int i, loop = 10;
35 ctx.fd = open("/proc/sys/net/core/bpf_jit_harden", O_RDWR);
36 if (!ASSERT_GE(ctx.fd, 0, "open bpf_jit_harden"))
40 err = pthread_create(&toggler, NULL, toggle_jit_harden, &ctx);
41 if (!ASSERT_OK(err, "new toggler"))
44 /* Make toggler thread to run */
47 for (i = 0; i < loop; i++) {
48 struct test_subprogs *skel = test_subprogs__open_and_load();
50 if (!ASSERT_OK_PTR(skel, "skel open"))
52 test_subprogs__destroy(skel);
56 pthread_join(toggler, NULL);
61 static void test_subprogs_alone(void)
63 struct test_subprogs *skel;
64 struct test_subprogs_unused *skel2;
67 skel = test_subprogs__open_and_load();
68 if (!ASSERT_OK_PTR(skel, "skel_open"))
71 err = test_subprogs__attach(skel);
72 if (!ASSERT_OK(err, "skel attach"))
77 ASSERT_EQ(skel->bss->res1, 12, "res1");
78 ASSERT_EQ(skel->bss->res2, 17, "res2");
79 ASSERT_EQ(skel->bss->res3, 19, "res3");
80 ASSERT_EQ(skel->bss->res4, 36, "res4");
82 skel2 = test_subprogs_unused__open_and_load();
83 ASSERT_OK_PTR(skel2, "unused_progs_skel");
84 test_subprogs_unused__destroy(skel2);
87 test_subprogs__destroy(skel);
90 void test_subprogs(void)
92 if (test__start_subtest("subprogs_alone"))
93 test_subprogs_alone();
94 if (test__start_subtest("subprogs_and_jit_harden"))
95 test_subprogs_with_jit_harden_toggling();