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