Skip to content

Commit daea6d2

Browse files
leitaokuba-moo
authored andcommitted
netconsole: selftest: verify userdata entry limit
Add a new selftest for netconsole that tests the userdata entry limit functionality. The test performs two key verifications: 1. Create MAX_USERDATA_ITEMS (16) userdata entries successfully 2. Confirm that attempting to create an additional userdata entry fails The selftest script uses the netcons library and checks the behavior by attempting to create entries beyond the maximum allowed limit. Signed-off-by: Breno Leitao <[email protected]> Tested-by: Simon Horman <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7dcb653 commit daea6d2

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16171,7 +16171,7 @@ S: Maintained
1617116171
F: Documentation/networking/netconsole.rst
1617216172
F: drivers/net/netconsole.c
1617316173
F: tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
16174-
F: tools/testing/selftests/drivers/net/netcons_basic.sh
16174+
F: tools/testing/selftests/drivers/net/netcons\*
1617516175

1617616176
NETDEVSIM
1617716177
M: Jakub Kicinski <[email protected]>

tools/testing/selftests/drivers/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ TEST_INCLUDES := $(wildcard lib/py/*.py) \
77

88
TEST_PROGS := \
99
netcons_basic.sh \
10+
netcons_overflow.sh \
1011
ping.py \
1112
queues.py \
1213
stats.py \
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
# This test verifies that users can successfully create up to
5+
# MAX_USERDATA_ITEMS userdata entries without encountering any failures.
6+
#
7+
# Additionally, it tests for expected failure when attempting to exceed this
8+
# maximum limit.
9+
#
10+
# Author: Breno Leitao <[email protected]>
11+
12+
set -euo pipefail
13+
14+
SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
15+
16+
source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh
17+
# This is coming from netconsole code. Check for it in drivers/net/netconsole.c
18+
MAX_USERDATA_ITEMS=16
19+
20+
# Function to create userdata entries
21+
function create_userdata_max_entries() {
22+
# All these keys should be created without any error
23+
for i in $(seq $MAX_USERDATA_ITEMS)
24+
do
25+
# USERDATA_KEY is used by set_user_data
26+
USERDATA_KEY="key"${i}
27+
set_user_data
28+
done
29+
}
30+
31+
# Function to verify the entry limit
32+
function verify_entry_limit() {
33+
# Allowing the test to fail without exiting, since the next command
34+
# will fail
35+
set +e
36+
mkdir "${NETCONS_PATH}/userdata/key_that_will_fail" 2> /dev/null
37+
ret="$?"
38+
set -e
39+
if [ "$ret" -eq 0 ];
40+
then
41+
echo "Adding more than ${MAX_USERDATA_ITEMS} entries in userdata should fail, but it didn't" >&2
42+
ls "${NETCONS_PATH}/userdata/" >&2
43+
exit "${ksft_fail}"
44+
fi
45+
}
46+
47+
# ========== #
48+
# Start here #
49+
# ========== #
50+
51+
modprobe netdevsim 2> /dev/null || true
52+
modprobe netconsole 2> /dev/null || true
53+
54+
# Check for basic system dependency and exit if not found
55+
check_for_dependencies
56+
57+
# Remove the namespace, interfaces and netconsole target on exit
58+
trap cleanup EXIT
59+
# Create one namespace and two interfaces
60+
set_network
61+
# Create a dynamic target for netconsole
62+
create_dynamic_target
63+
# populate the maximum number of supported keys in userdata
64+
create_userdata_max_entries
65+
# Verify an additional entry is not allowed
66+
verify_entry_limit
67+
exit "${ksft_pass}"

0 commit comments

Comments
 (0)