2 # SPDX-License-Identifier: GPL-2.0
4 # Kselftest framework requirement - SKIP code is 4.
7 TESTNAME
=bpftool_metadata
8 BPF_FS
=$
(awk '$3 == "bpf" {print $2; exit}' /proc
/mounts
)
9 BPF_DIR
=$BPF_FS/test_
$TESTNAME
14 rm -rf $BPF_DIR 2> /dev
/null
19 echo "selftests: $TESTNAME [SKIP]"
28 echo "selftests: $TESTNAME [PASS]"
30 echo "selftests: $TESTNAME [FAILED]"
35 if [ $
(id
-u) -ne 0 ]; then
36 echo "selftests: $TESTNAME [SKIP] Need root privileges"
40 if [ -z "$BPF_FS" ]; then
41 echo "selftests: $TESTNAME [SKIP] Could not run test without bpffs mounted"
45 if ! bpftool version
> /dev
/null
2>&1; then
46 echo "selftests: $TESTNAME [SKIP] Could not run test without bpftool"
52 trap cleanup_skip 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
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