Skip to content

Commit 8dbd83a

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]> Reviewed-by: Quentin Monnet <[email protected]>
1 parent 1587cfc commit 8dbd83a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tools/testing/selftests/bpf/test_bpftool_map.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,36 @@ 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 "Map ID not printed in plain text output."
379+
exit 1
380+
fi
381+
382+
rm -f "$test_map_path"
383+
384+
output=$("$bpftool_path" map create "$test_map_path" type hash key 4 \
385+
value 8 entries 128 name "$test_map_name" --json)
386+
if ! echo "$output" | jq -e 'has("id")' >/dev/null 2>&1; then
387+
echo "Map ID not printed in JSON output."
388+
exit 1
389+
fi
390+
391+
rm -f "$test_map_path"
392+
}
393+
364394
set -eu
365395

366396
trap cleanup_skip EXIT
@@ -395,4 +425,6 @@ test_map_creation_and_map_of_maps "$BPFTOOL_PATH" "$BPF_DIR"
395425

396426
test_map_access_with_btf_list "$BPFTOOL_PATH"
397427

428+
test_map_id_printing "$BPFTOOL_PATH" "$BPF_DIR"
429+
398430
exit 0

0 commit comments

Comments
 (0)