selftests/bpf: Move is_jit_enabled() into testing_helpers
authorTiezhu Yang <yangtiezhu@loongson.cn>
Tue, 23 Jan 2024 09:03:50 +0000 (17:03 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Wed, 24 Jan 2024 04:26:17 +0000 (20:26 -0800)
Currently, is_jit_enabled() is only used in test_progs, move it into
testing_helpers so that it can be used in test_verifier. While at it,
remove the second argument "0" of open() as Hou Tao suggested.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Hou Tao <houtao1@huawei.com>
Acked-by: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/bpf/20240123090351.2207-2-yangtiezhu@loongson.cn
tools/testing/selftests/bpf/test_progs.c
tools/testing/selftests/bpf/testing_helpers.c
tools/testing/selftests/bpf/testing_helpers.h

index 1b9387890148f4cf8879e05d23db724c442977ad..808550986f306530be2010f7e417ced77d7ba3a3 100644 (file)
@@ -547,24 +547,6 @@ int bpf_find_map(const char *test, struct bpf_object *obj, const char *name)
        return bpf_map__fd(map);
 }
 
-static bool is_jit_enabled(void)
-{
-       const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
-       bool enabled = false;
-       int sysctl_fd;
-
-       sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
-       if (sysctl_fd != -1) {
-               char tmpc;
-
-               if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
-                       enabled = (tmpc != '0');
-               close(sysctl_fd);
-       }
-
-       return enabled;
-}
-
 int compare_map_keys(int map1_fd, int map2_fd)
 {
        __u32 key, next_key;
index 106ef05586b8fe80e6c6cac2e3bbb46b921c010d..a59e56d804ee4b3fac66e048e1634b0f6247e218 100644 (file)
@@ -457,3 +457,21 @@ out_free_buf:
        *buf = NULL;
        return -1;
 }
+
+bool is_jit_enabled(void)
+{
+       const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
+       bool enabled = false;
+       int sysctl_fd;
+
+       sysctl_fd = open(jit_sysctl, O_RDONLY);
+       if (sysctl_fd != -1) {
+               char tmpc;
+
+               if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
+                       enabled = (tmpc != '0');
+               close(sysctl_fd);
+       }
+
+       return enabled;
+}
index e099aa4da611edb1edfb18ed946aed05c84236a3..d14de81727e6ef12aa0cfba4791109867b971f56 100644 (file)
@@ -52,5 +52,6 @@ struct bpf_insn;
  */
 int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt);
 int testing_prog_flags(void);
+bool is_jit_enabled(void);
 
 #endif /* __TESTING_HELPERS_H */