1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 # Kselftest framework requirement - SKIP code 4 # Kselftest framework requirement - SKIP code is 4. 5 ksft_skip=4 5 ksft_skip=4 6 6 7 BPF_FILE_USED="metadata_used.bpf.o" 7 BPF_FILE_USED="metadata_used.bpf.o" 8 BPF_FILE_UNUSED="metadata_unused.bpf.o" 8 BPF_FILE_UNUSED="metadata_unused.bpf.o" 9 9 10 TESTNAME=bpftool_metadata 10 TESTNAME=bpftool_metadata 11 BPF_FS=$(awk '$3 == "bpf" {print $2; exit}' /p 11 BPF_FS=$(awk '$3 == "bpf" {print $2; exit}' /proc/mounts) 12 BPF_DIR=$BPF_FS/test_$TESTNAME 12 BPF_DIR=$BPF_FS/test_$TESTNAME 13 13 14 _cleanup() 14 _cleanup() 15 { 15 { 16 set +e 16 set +e 17 rm -rf $BPF_DIR 2> /dev/null 17 rm -rf $BPF_DIR 2> /dev/null 18 } 18 } 19 19 20 cleanup_skip() 20 cleanup_skip() 21 { 21 { 22 echo "selftests: $TESTNAME [SKIP]" 22 echo "selftests: $TESTNAME [SKIP]" 23 _cleanup 23 _cleanup 24 24 25 exit $ksft_skip 25 exit $ksft_skip 26 } 26 } 27 27 28 cleanup() 28 cleanup() 29 { 29 { 30 if [ "$?" = 0 ]; then 30 if [ "$?" = 0 ]; then 31 echo "selftests: $TESTNAME [PA 31 echo "selftests: $TESTNAME [PASS]" 32 else 32 else 33 echo "selftests: $TESTNAME [FA 33 echo "selftests: $TESTNAME [FAILED]" 34 fi 34 fi 35 _cleanup 35 _cleanup 36 } 36 } 37 37 38 if [ $(id -u) -ne 0 ]; then 38 if [ $(id -u) -ne 0 ]; then 39 echo "selftests: $TESTNAME [SKIP] Need 39 echo "selftests: $TESTNAME [SKIP] Need root privileges" 40 exit $ksft_skip 40 exit $ksft_skip 41 fi 41 fi 42 42 43 if [ -z "$BPF_FS" ]; then 43 if [ -z "$BPF_FS" ]; then 44 echo "selftests: $TESTNAME [SKIP] Coul 44 echo "selftests: $TESTNAME [SKIP] Could not run test without bpffs mounted" 45 exit $ksft_skip 45 exit $ksft_skip 46 fi 46 fi 47 47 48 if ! bpftool version > /dev/null 2>&1; then 48 if ! bpftool version > /dev/null 2>&1; then 49 echo "selftests: $TESTNAME [SKIP] Coul 49 echo "selftests: $TESTNAME [SKIP] Could not run test without bpftool" 50 exit $ksft_skip 50 exit $ksft_skip 51 fi 51 fi 52 52 53 set -e 53 set -e 54 54 55 trap cleanup_skip EXIT 55 trap cleanup_skip EXIT 56 56 57 mkdir $BPF_DIR 57 mkdir $BPF_DIR 58 58 59 trap cleanup EXIT 59 trap cleanup EXIT 60 60 61 bpftool prog load $BPF_FILE_UNUSED $BPF_DIR/un 61 bpftool prog load $BPF_FILE_UNUSED $BPF_DIR/unused 62 62 63 METADATA_PLAIN="$(bpftool prog)" 63 METADATA_PLAIN="$(bpftool prog)" 64 echo "$METADATA_PLAIN" | grep 'a = "foo"' > /d 64 echo "$METADATA_PLAIN" | grep 'a = "foo"' > /dev/null 65 echo "$METADATA_PLAIN" | grep 'b = 1' > /dev/n 65 echo "$METADATA_PLAIN" | grep 'b = 1' > /dev/null 66 66 67 bpftool prog --json | grep '"metadata":{"a":"f 67 bpftool prog --json | grep '"metadata":{"a":"foo","b":1}' > /dev/null 68 68 69 bpftool map | grep 'metadata.rodata' > /dev/nu 69 bpftool map | grep 'metadata.rodata' > /dev/null 70 70 71 rm $BPF_DIR/unused 71 rm $BPF_DIR/unused 72 72 73 bpftool prog load $BPF_FILE_USED $BPF_DIR/used 73 bpftool prog load $BPF_FILE_USED $BPF_DIR/used 74 74 75 METADATA_PLAIN="$(bpftool prog)" 75 METADATA_PLAIN="$(bpftool prog)" 76 echo "$METADATA_PLAIN" | grep 'a = "bar"' > /d 76 echo "$METADATA_PLAIN" | grep 'a = "bar"' > /dev/null 77 echo "$METADATA_PLAIN" | grep 'b = 2' > /dev/n 77 echo "$METADATA_PLAIN" | grep 'b = 2' > /dev/null 78 78 79 bpftool prog --json | grep '"metadata":{"a":"b 79 bpftool prog --json | grep '"metadata":{"a":"bar","b":2}' > /dev/null 80 80 81 bpftool map | grep 'metadata.rodata' > /dev/nu 81 bpftool map | grep 'metadata.rodata' > /dev/null 82 82 83 rm $BPF_DIR/used 83 rm $BPF_DIR/used 84 84 85 exit 0 85 exit 0
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.