WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_bpftool_metadata.sh
blob1bf81b49457afa9217440738663c0474493e3a60
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Kselftest framework requirement - SKIP code is 4.
5 ksft_skip=4
7 TESTNAME=bpftool_metadata
8 BPF_FS=$(awk '$3 == "bpf" {print $2; exit}' /proc/mounts)
9 BPF_DIR=$BPF_FS/test_$TESTNAME
11 _cleanup()
13 set +e
14 rm -rf $BPF_DIR 2> /dev/null
17 cleanup_skip()
19 echo "selftests: $TESTNAME [SKIP]"
20 _cleanup
22 exit $ksft_skip
25 cleanup()
27 if [ "$?" = 0 ]; then
28 echo "selftests: $TESTNAME [PASS]"
29 else
30 echo "selftests: $TESTNAME [FAILED]"
32 _cleanup
35 if [ $(id -u) -ne 0 ]; then
36 echo "selftests: $TESTNAME [SKIP] Need root privileges"
37 exit $ksft_skip
40 if [ -z "$BPF_FS" ]; then
41 echo "selftests: $TESTNAME [SKIP] Could not run test without bpffs mounted"
42 exit $ksft_skip
45 if ! bpftool version > /dev/null 2>&1; then
46 echo "selftests: $TESTNAME [SKIP] Could not run test without bpftool"
47 exit $ksft_skip
50 set -e
52 trap cleanup_skip EXIT
54 mkdir $BPF_DIR
56 trap cleanup EXIT
58 bpftool prog load metadata_unused.o $BPF_DIR/unused
60 METADATA_PLAIN="$(bpftool prog)"
61 echo "$METADATA_PLAIN" | grep 'a = "foo"' > /dev/null
62 echo "$METADATA_PLAIN" | grep 'b = 1' > /dev/null
64 bpftool prog --json | grep '"metadata":{"a":"foo","b":1}' > /dev/null
66 bpftool map | grep 'metadata.rodata' > /dev/null
68 rm $BPF_DIR/unused
70 bpftool prog load metadata_used.o $BPF_DIR/used
72 METADATA_PLAIN="$(bpftool prog)"
73 echo "$METADATA_PLAIN" | grep 'a = "bar"' > /dev/null
74 echo "$METADATA_PLAIN" | grep 'b = 2' > /dev/null
76 bpftool prog --json | grep '"metadata":{"a":"bar","b":2}' > /dev/null
78 bpftool map | grep 'metadata.rodata' > /dev/null
80 rm $BPF_DIR/used
82 exit 0