Skip to content

Commit 510d820

Browse files
harshimogalapalliKernel Patches Daemon
authored andcommitted
selftests/bpf: Add test for bpftool map ID printing
Add selftest to check if Map ID is printed on successful creation in both plain text and json formats. Signed-off-by: Harshit Mogalapalli <[email protected]>
1 parent 7f8089e commit 510d820

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tools/testing/selftests/bpf/test_bpftool_map.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,40 @@ test_map_access_with_btf_list() {
361361
fi
362362
}
363363

364+
# Function to test map ID printing
365+
# Parameters:
366+
# $1: bpftool path
367+
# $2: BPF_DIR
368+
test_map_id_printing() {
369+
local bpftool_path="$1"
370+
local bpf_dir="$2"
371+
local test_map_name="test_map_id"
372+
local test_map_path="$bpf_dir/$test_map_name"
373+
374+
local output
375+
output=$("$bpftool_path" map create "$test_map_path" type hash key 4 \
376+
value 8 entries 128 name "$test_map_name")
377+
if echo "$output" | grep -q "Map successfully created with ID:"; then
378+
echo "PASS: Map ID printed in plain text output."
379+
else
380+
echo "FAIL: Map ID not printed in plain text output."
381+
exit 1
382+
fi
383+
384+
rm -f "$test_map_path"
385+
386+
output=$("$bpftool_path" map create "$test_map_path" type hash key 4 \
387+
value 8 entries 128 name "$test_map_name" --json)
388+
if echo "$output" | jq -e 'has("id")' >/dev/null 2>&1; then
389+
echo "PASS: Map ID printed in JSON output."
390+
else
391+
echo "FAIL: Map ID not printed in JSON output."
392+
exit 1
393+
fi
394+
395+
rm -f "$test_map_path"
396+
}
397+
364398
set -eu
365399

366400
trap cleanup_skip EXIT
@@ -395,4 +429,6 @@ test_map_creation_and_map_of_maps "$BPFTOOL_PATH" "$BPF_DIR"
395429

396430
test_map_access_with_btf_list "$BPFTOOL_PATH"
397431

432+
test_map_id_printing "$BPFTOOL_PATH" "$BPF_DIR"
433+
398434
exit 0

0 commit comments

Comments
 (0)