Skip to content

Commit

Permalink
selftests/bpf: Move is_jit_enabled() into testing_helpers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Hou Tao <[email protected]>
Acked-by: Song Liu <[email protected]>
  • Loading branch information
Tiezhu Yang authored and Kernel Patches Daemon committed Jan 24, 2024
1 parent 7c8a452 commit 0588866
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
18 changes: 0 additions & 18 deletions tools/testing/selftests/bpf/test_progs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tools/testing/selftests/bpf/testing_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,21 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt)
*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;
}
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/testing_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 0588866

Please sign in to comment.