Skip to content

Commit f01750a

Browse files
theihoranakryiko
authored andcommitted
selftests/bpf: Set test path for token/obj_priv_implicit_token_envvar
token/obj_priv_implicit_token_envvar test may fail in an environment where the process executing tests can not write to the root path. Example: https://github.com/libbpf/libbpf/actions/runs/11844507007/job/33007897936 Change default path used by the test to /tmp/bpf-token-fs, and make it runtime configurable via an environment variable. Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241115003853.864397-1-ihor.solodrai@pm.me
1 parent 379d5ee commit f01750a

File tree

1 file changed

+12
-7
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+12
-7
lines changed

tools/testing/selftests/bpf/prog_tests/token.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,12 @@ static int userns_obj_priv_btf_success(int mnt_fd, struct token_lsm *lsm_skel)
828828
return validate_struct_ops_load(mnt_fd, true /* should succeed */);
829829
}
830830

831+
static const char *token_bpffs_custom_dir()
832+
{
833+
return getenv("BPF_SELFTESTS_BPF_TOKEN_DIR") ?: "/tmp/bpf-token-fs";
834+
}
835+
831836
#define TOKEN_ENVVAR "LIBBPF_BPF_TOKEN_PATH"
832-
#define TOKEN_BPFFS_CUSTOM "/bpf-token-fs"
833837

834838
static int userns_obj_priv_implicit_token(int mnt_fd, struct token_lsm *lsm_skel)
835839
{
@@ -892,6 +896,7 @@ static int userns_obj_priv_implicit_token(int mnt_fd, struct token_lsm *lsm_skel
892896

893897
static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *lsm_skel)
894898
{
899+
const char *custom_dir = token_bpffs_custom_dir();
895900
LIBBPF_OPTS(bpf_object_open_opts, opts);
896901
struct dummy_st_ops_success *skel;
897902
int err;
@@ -909,10 +914,10 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
909914
* BPF token implicitly, unless pointed to it through
910915
* LIBBPF_BPF_TOKEN_PATH envvar
911916
*/
912-
rmdir(TOKEN_BPFFS_CUSTOM);
913-
if (!ASSERT_OK(mkdir(TOKEN_BPFFS_CUSTOM, 0777), "mkdir_bpffs_custom"))
917+
rmdir(custom_dir);
918+
if (!ASSERT_OK(mkdir(custom_dir, 0777), "mkdir_bpffs_custom"))
914919
goto err_out;
915-
err = sys_move_mount(mnt_fd, "", AT_FDCWD, TOKEN_BPFFS_CUSTOM, MOVE_MOUNT_F_EMPTY_PATH);
920+
err = sys_move_mount(mnt_fd, "", AT_FDCWD, custom_dir, MOVE_MOUNT_F_EMPTY_PATH);
916921
if (!ASSERT_OK(err, "move_mount_bpffs"))
917922
goto err_out;
918923

@@ -925,7 +930,7 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
925930
goto err_out;
926931
}
927932

928-
err = setenv(TOKEN_ENVVAR, TOKEN_BPFFS_CUSTOM, 1 /*overwrite*/);
933+
err = setenv(TOKEN_ENVVAR, custom_dir, 1 /*overwrite*/);
929934
if (!ASSERT_OK(err, "setenv_token_path"))
930935
goto err_out;
931936

@@ -951,11 +956,11 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l
951956
if (!ASSERT_ERR(err, "obj_empty_token_path_load"))
952957
goto err_out;
953958

954-
rmdir(TOKEN_BPFFS_CUSTOM);
959+
rmdir(custom_dir);
955960
unsetenv(TOKEN_ENVVAR);
956961
return 0;
957962
err_out:
958-
rmdir(TOKEN_BPFFS_CUSTOM);
963+
rmdir(custom_dir);
959964
unsetenv(TOKEN_ENVVAR);
960965
return -EINVAL;
961966
}

0 commit comments

Comments
 (0)