Skip to content

Commit 07039ae

Browse files
seehearfeelKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Move is_jit_enabled() to testing_helpers
Currently, is_jit_enabled() is only used in test_progs, move it to 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 <[email protected]> Acked-by: Hou Tao <[email protected]>
1 parent 61cdd98 commit 07039ae

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

tools/testing/selftests/bpf/test_progs.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -547,24 +547,6 @@ int bpf_find_map(const char *test, struct bpf_object *obj, const char *name)
547547
return bpf_map__fd(map);
548548
}
549549

550-
static bool is_jit_enabled(void)
551-
{
552-
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
553-
bool enabled = false;
554-
int sysctl_fd;
555-
556-
sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
557-
if (sysctl_fd != -1) {
558-
char tmpc;
559-
560-
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
561-
enabled = (tmpc != '0');
562-
close(sysctl_fd);
563-
}
564-
565-
return enabled;
566-
}
567-
568550
int compare_map_keys(int map1_fd, int map2_fd)
569551
{
570552
__u32 key, next_key;

tools/testing/selftests/bpf/testing_helpers.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,21 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt)
457457
*buf = NULL;
458458
return -1;
459459
}
460+
461+
bool is_jit_enabled(void)
462+
{
463+
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
464+
bool enabled = false;
465+
int sysctl_fd;
466+
467+
sysctl_fd = open(jit_sysctl, O_RDONLY);
468+
if (sysctl_fd != -1) {
469+
char tmpc;
470+
471+
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
472+
enabled = (tmpc != '0');
473+
close(sysctl_fd);
474+
}
475+
476+
return enabled;
477+
}

tools/testing/selftests/bpf/testing_helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ struct bpf_insn;
5252
*/
5353
int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt);
5454
int testing_prog_flags(void);
55+
bool is_jit_enabled(void);
5556

5657
#endif /* __TESTING_HELPERS_H */

0 commit comments

Comments
 (0)