diff mbox series

[bpf-next] selftests/bpf: fix test_bpffs

Message ID 20231027223006.2062967-1-chantr4@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: fix test_bpffs | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 1 maintainers not CCed: linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch warning WARNING: Possible repeated word: 'tracefs'
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-17 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-llvm-16 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-llvm-16 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-16 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-16 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-11 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-3 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-llvm-16 / build / build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-16 / veristat
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-10 success Logs for set-matrix

Commit Message

Manu Bretelle Oct. 27, 2023, 10:30 p.m. UTC
Currently this tests tries to umount /sys/kernel/debug (TDIR) but the
system it is running on may have mounts below.

For example, danobi/vmtest [0] VMs have
    mount -t tracefs tracefs /sys/kernel/debug/tracing
as part of their init.

This change instead creates a "random" directory under /tmp and uses this
as TDIR.
If the directory already exists, ignore the error and keep moving on.

Test:

Originally:

    $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
    => bzImage
    ===> Booting
    ===> Setting up VM
    ===> Running command
    [    2.138818] bpf_testmod: loading out-of-tree module taints kernel.
    [    2.140913] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
    bpf_testmod.ko is already unloaded.
    Loading bpf_testmod.ko...
    Successfully loaded bpf_testmod.ko.
    test_test_bpffs:PASS:clone 0 nsec
    fn:PASS:unshare 0 nsec
    fn:PASS:mount / 0 nsec
    fn:FAIL:umount /sys/kernel/debug unexpected error: -1 (errno 16)
    bpf_testmod.ko is already unloaded.
    Loading bpf_testmod.ko...
    Successfully loaded bpf_testmod.ko.
    test_test_bpffs:PASS:clone 0 nsec
    test_test_bpffs:PASS:waitpid 0 nsec
    test_test_bpffs:FAIL:bpffs test  failed 255#282     test_bpffs:FAIL
    Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
    Successfully unloaded bpf_testmod.ko.
    Command failed with exit code: 1

After this change:

    $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
    => bzImage
    ===> Booting
    ===> Setting up VM
    ===> Running command
    [    2.119236] bpf_testmod: loading out-of-tree module taints kernel.
    [    2.121768] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
    bpf_testmod.ko is already unloaded.
    Loading bpf_testmod.ko...
    Successfully loaded bpf_testmod.ko.
    test_test_bpffs:PASS:clone 0 nsec
    fn:PASS:unshare 0 nsec
    fn:PASS:mount / 0 nsec
    fn:PASS:mount tmpfs 0 nsec
    fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
    fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
    fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
    fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
    fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/maps.debug 0 nsec
    fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2/progs.debug 0 nsec
    fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a 0 nsec
    fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a/1 0 nsec
    fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b 0 nsec
    fn:PASS:create_map(ARRAY) 0 nsec
    fn:PASS:pin map 0 nsec
    fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a) 0 nsec
    fn:PASS:renameat2(/fs1/a, /fs1/b, RENAME_EXCHANGE) 0 nsec
    fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
    fn:PASS:b should have a's inode 0 nsec
    fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b/1) 0 nsec
    fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/map) 0 nsec
    fn:PASS:renameat2(/fs1/c, /fs1/b, RENAME_EXCHANGE) 0 nsec
    fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
    fn:PASS:b should have c's inode 0 nsec
    fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/c/1) 0 nsec
    fn:PASS:renameat2(RENAME_NOREPLACE) 0 nsec
    fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
    bpf_testmod.ko is already unloaded.
    Loading bpf_testmod.ko...
    Successfully loaded bpf_testmod.ko.
    test_test_bpffs:PASS:clone 0 nsec
    test_test_bpffs:PASS:waitpid 0 nsec
    test_test_bpffs:PASS:bpffs test  0 nsec
    #282     test_bpffs:OK
    Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
    Successfully unloaded bpf_testmod.ko.

[0] https://github.com/danobi/vmtest

This is a follow-up of https://lore.kernel.org/bpf/20231024201852.1512720-1-chantr4@gmail.com/T/

Signed-off-by: Manu Bretelle <chantr4@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/test_bpffs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Yonghong Song Oct. 28, 2023, 2:06 a.m. UTC | #1
On 10/27/23 3:30 PM, Manu Bretelle wrote:
> Currently this tests tries to umount /sys/kernel/debug (TDIR) but the
> system it is running on may have mounts below.
>
> For example, danobi/vmtest [0] VMs have
>      mount -t tracefs tracefs /sys/kernel/debug/tracing
> as part of their init.
>
> This change instead creates a "random" directory under /tmp and uses this
> as TDIR.
> If the directory already exists, ignore the error and keep moving on.
>
> Test:
>
> Originally:
>
>      $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
>      => bzImage
>      ===> Booting
>      ===> Setting up VM
>      ===> Running command
>      [    2.138818] bpf_testmod: loading out-of-tree module taints kernel.
>      [    2.140913] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
>      bpf_testmod.ko is already unloaded.
>      Loading bpf_testmod.ko...
>      Successfully loaded bpf_testmod.ko.
>      test_test_bpffs:PASS:clone 0 nsec
>      fn:PASS:unshare 0 nsec
>      fn:PASS:mount / 0 nsec
>      fn:FAIL:umount /sys/kernel/debug unexpected error: -1 (errno 16)
>      bpf_testmod.ko is already unloaded.
>      Loading bpf_testmod.ko...
>      Successfully loaded bpf_testmod.ko.
>      test_test_bpffs:PASS:clone 0 nsec
>      test_test_bpffs:PASS:waitpid 0 nsec
>      test_test_bpffs:FAIL:bpffs test  failed 255#282     test_bpffs:FAIL
>      Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
>      Successfully unloaded bpf_testmod.ko.
>      Command failed with exit code: 1
>
> After this change:
>
>      $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
>      => bzImage
>      ===> Booting
>      ===> Setting up VM
>      ===> Running command
>      [    2.119236] bpf_testmod: loading out-of-tree module taints kernel.
>      [    2.121768] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
>      bpf_testmod.ko is already unloaded.
>      Loading bpf_testmod.ko...
>      Successfully loaded bpf_testmod.ko.
>      test_test_bpffs:PASS:clone 0 nsec
>      fn:PASS:unshare 0 nsec
>      fn:PASS:mount / 0 nsec
>      fn:PASS:mount tmpfs 0 nsec
>      fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
>      fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
>      fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
>      fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
>      fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/maps.debug 0 nsec
>      fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2/progs.debug 0 nsec
>      fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a 0 nsec
>      fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a/1 0 nsec
>      fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b 0 nsec
>      fn:PASS:create_map(ARRAY) 0 nsec
>      fn:PASS:pin map 0 nsec
>      fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a) 0 nsec
>      fn:PASS:renameat2(/fs1/a, /fs1/b, RENAME_EXCHANGE) 0 nsec
>      fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>      fn:PASS:b should have a's inode 0 nsec
>      fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b/1) 0 nsec
>      fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/map) 0 nsec
>      fn:PASS:renameat2(/fs1/c, /fs1/b, RENAME_EXCHANGE) 0 nsec
>      fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>      fn:PASS:b should have c's inode 0 nsec
>      fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/c/1) 0 nsec
>      fn:PASS:renameat2(RENAME_NOREPLACE) 0 nsec
>      fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>      bpf_testmod.ko is already unloaded.
>      Loading bpf_testmod.ko...
>      Successfully loaded bpf_testmod.ko.
>      test_test_bpffs:PASS:clone 0 nsec
>      test_test_bpffs:PASS:waitpid 0 nsec
>      test_test_bpffs:PASS:bpffs test  0 nsec
>      #282     test_bpffs:OK
>      Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>      Successfully unloaded bpf_testmod.ko.
>
> [0] https://github.com/danobi/vmtest
>
> This is a follow-up of https://lore.kernel.org/bpf/20231024201852.1512720-1-chantr4@gmail.com/T/
>
> Signed-off-by: Manu Bretelle <chantr4@gmail.com>

Acked-by: Yonghong Song <yonghong.song@linux.dev>
Andrii Nakryiko Oct. 31, 2023, 6:29 a.m. UTC | #2
On Fri, Oct 27, 2023 at 3:30 PM Manu Bretelle <chantr4@gmail.com> wrote:
>
> Currently this tests tries to umount /sys/kernel/debug (TDIR) but the
> system it is running on may have mounts below.
>
> For example, danobi/vmtest [0] VMs have
>     mount -t tracefs tracefs /sys/kernel/debug/tracing
> as part of their init.
>
> This change instead creates a "random" directory under /tmp and uses this
> as TDIR.
> If the directory already exists, ignore the error and keep moving on.
>
> Test:
>
> Originally:
>
>     $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
>     => bzImage
>     ===> Booting
>     ===> Setting up VM
>     ===> Running command
>     [    2.138818] bpf_testmod: loading out-of-tree module taints kernel.
>     [    2.140913] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
>     bpf_testmod.ko is already unloaded.
>     Loading bpf_testmod.ko...
>     Successfully loaded bpf_testmod.ko.
>     test_test_bpffs:PASS:clone 0 nsec
>     fn:PASS:unshare 0 nsec
>     fn:PASS:mount / 0 nsec
>     fn:FAIL:umount /sys/kernel/debug unexpected error: -1 (errno 16)
>     bpf_testmod.ko is already unloaded.
>     Loading bpf_testmod.ko...
>     Successfully loaded bpf_testmod.ko.
>     test_test_bpffs:PASS:clone 0 nsec
>     test_test_bpffs:PASS:waitpid 0 nsec
>     test_test_bpffs:FAIL:bpffs test  failed 255#282     test_bpffs:FAIL
>     Summary: 0/0 PASSED, 0 SKIPPED, 1 FAILED
>     Successfully unloaded bpf_testmod.ko.
>     Command failed with exit code: 1
>
> After this change:
>
>     $ vmtest -k $KERNEL_REPO/arch/x86_64/boot/bzImage "./test_progs -vv -a test_bpffs"
>     => bzImage
>     ===> Booting
>     ===> Setting up VM
>     ===> Running command
>     [    2.119236] bpf_testmod: loading out-of-tree module taints kernel.
>     [    2.121768] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
>     bpf_testmod.ko is already unloaded.
>     Loading bpf_testmod.ko...
>     Successfully loaded bpf_testmod.ko.
>     test_test_bpffs:PASS:clone 0 nsec
>     fn:PASS:unshare 0 nsec
>     fn:PASS:mount / 0 nsec
>     fn:PASS:mount tmpfs 0 nsec
>     fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
>     fn:PASS:mkdir /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
>     fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1 0 nsec
>     fn:PASS:mount bpffs /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2 0 nsec
>     fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/maps.debug 0 nsec
>     fn:PASS:reading /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs2/progs.debug 0 nsec
>     fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a 0 nsec
>     fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a/1 0 nsec
>     fn:PASS:creating /tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b 0 nsec
>     fn:PASS:create_map(ARRAY) 0 nsec
>     fn:PASS:pin map 0 nsec
>     fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/a) 0 nsec
>     fn:PASS:renameat2(/fs1/a, /fs1/b, RENAME_EXCHANGE) 0 nsec
>     fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>     fn:PASS:b should have a's inode 0 nsec
>     fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b/1) 0 nsec
>     fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/map) 0 nsec
>     fn:PASS:renameat2(/fs1/c, /fs1/b, RENAME_EXCHANGE) 0 nsec
>     fn:PASS:stat(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>     fn:PASS:b should have c's inode 0 nsec
>     fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/c/1) 0 nsec
>     fn:PASS:renameat2(RENAME_NOREPLACE) 0 nsec
>     fn:PASS:access(/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed/fs1/b) 0 nsec
>     bpf_testmod.ko is already unloaded.
>     Loading bpf_testmod.ko...
>     Successfully loaded bpf_testmod.ko.
>     test_test_bpffs:PASS:clone 0 nsec
>     test_test_bpffs:PASS:waitpid 0 nsec
>     test_test_bpffs:PASS:bpffs test  0 nsec
>     #282     test_bpffs:OK
>     Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>     Successfully unloaded bpf_testmod.ko.
>
> [0] https://github.com/danobi/vmtest
>
> This is a follow-up of https://lore.kernel.org/bpf/20231024201852.1512720-1-chantr4@gmail.com/T/
>
> Signed-off-by: Manu Bretelle <chantr4@gmail.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/test_bpffs.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> index 214d9f4a94a5..80a1afb9589d 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
> @@ -8,7 +8,8 @@
>  #include <sys/types.h>
>  #include <test_progs.h>
>
> -#define TDIR "/sys/kernel/debug"
> +// TDIR must be in a location we can create a directory in.
> +#define TDIR "/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed"

and "/tmp/test_bpffs_testdir" isn't unique enough? ;)

>
>  static int read_iter(char *file)
>  {
> @@ -43,8 +44,10 @@ static int fn(void)
>         if (!ASSERT_OK(err, "mount /"))
>                 goto out;
>
> -       err = umount(TDIR);
> -       if (!ASSERT_OK(err, "umount " TDIR))
> +       err =  mkdir(TDIR, 0777);
> +       // If the directory already exists we can carry on. It may be left over
> +       // from a previous run.

we don't use C++-style comments in kernel and selftests code, please
change to /* */

same above for TDIR comment

> +       if ((err && errno != EEXIST) && !ASSERT_OK(err, "mkdir " TDIR))
>                 goto out;
>
>         err = mount("none", TDIR, "tmpfs", 0, NULL);
> @@ -138,6 +141,7 @@ static int fn(void)
>         rmdir(TDIR "/fs1");
>         rmdir(TDIR "/fs2");
>         umount(TDIR);
> +       rmdir(TDIR);
>         exit(err);
>  }
>
> --
> 2.40.1
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
index 214d9f4a94a5..80a1afb9589d 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
@@ -8,7 +8,8 @@ 
 #include <sys/types.h>
 #include <test_progs.h>
 
-#define TDIR "/sys/kernel/debug"
+// TDIR must be in a location we can create a directory in.
+#define TDIR "/tmp/vvnlhrgunvkrfegnlrvnggcudfgdtrhbfelkebeurfed"
 
 static int read_iter(char *file)
 {
@@ -43,8 +44,10 @@  static int fn(void)
 	if (!ASSERT_OK(err, "mount /"))
 		goto out;
 
-	err = umount(TDIR);
-	if (!ASSERT_OK(err, "umount " TDIR))
+	err =  mkdir(TDIR, 0777);
+	// If the directory already exists we can carry on. It may be left over
+	// from a previous run.
+	if ((err && errno != EEXIST) && !ASSERT_OK(err, "mkdir " TDIR))
 		goto out;
 
 	err = mount("none", TDIR, "tmpfs", 0, NULL);
@@ -138,6 +141,7 @@  static int fn(void)
 	rmdir(TDIR "/fs1");
 	rmdir(TDIR "/fs2");
 	umount(TDIR);
+	rmdir(TDIR);
 	exit(err);
 }