Skip to content

Commit 4b73dc8

Browse files
leitaoPaolo Abeni
authored andcommitted
selftests: netconsole: Add tests for 'release' feature in sysdata
Expands the self-tests to include the 'release' feature in sysdata. Verifies that enabling the 'release' feature appends the correct data and ensures that disabling it functions as expected. When enabled, the message should have an item similar to in the userdata: `release=$(uname -r)` Signed-off-by: Breno Leitao <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent cfcc923 commit 4b73dc8

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tools/testing/selftests/drivers/net/netcons_sysdata.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ function set_taskname() {
4242
echo 1 > "${NETCONS_PATH}/userdata/taskname_enabled"
4343
}
4444

45+
# Enable the release to be appended to sysdata
46+
function set_release() {
47+
if [[ ! -f "${NETCONS_PATH}/userdata/release_enabled" ]]
48+
then
49+
echo "Not able to enable release sysdata append. Configfs not available in ${NETCONS_PATH}/userdata/release_enabled" >&2
50+
exit "${ksft_skip}"
51+
fi
52+
53+
echo 1 > "${NETCONS_PATH}/userdata/release_enabled"
54+
}
55+
4556
# Disable the sysdata cpu_nr feature
4657
function unset_cpu_nr() {
4758
echo 0 > "${NETCONS_PATH}/userdata/cpu_nr_enabled"
@@ -52,6 +63,10 @@ function unset_taskname() {
5263
echo 0 > "${NETCONS_PATH}/userdata/taskname_enabled"
5364
}
5465

66+
function unset_release() {
67+
echo 0 > "${NETCONS_PATH}/userdata/release_enabled"
68+
}
69+
5570
# Test if MSG contains sysdata
5671
function validate_sysdata() {
5772
# OUTPUT_FILE will contain something like:
@@ -93,6 +108,21 @@ function validate_sysdata() {
93108
pkill_socat
94109
}
95110

111+
function validate_release() {
112+
RELEASE=$(uname -r)
113+
114+
if [ ! -f "$OUTPUT_FILE" ]; then
115+
echo "FAIL: File was not generated." >&2
116+
exit "${ksft_fail}"
117+
fi
118+
119+
if ! grep -q "release=${RELEASE}" "${OUTPUT_FILE}"; then
120+
echo "FAIL: 'release=${RELEASE}' not found in ${OUTPUT_FILE}" >&2
121+
cat "${OUTPUT_FILE}" >&2
122+
exit "${ksft_fail}"
123+
fi
124+
}
125+
96126
# Test if MSG content exists in OUTPUT_FILE but no `cpu=` and `taskname=`
97127
# strings
98128
function validate_no_sysdata() {
@@ -119,6 +149,12 @@ function validate_no_sysdata() {
119149
exit "${ksft_fail}"
120150
fi
121151

152+
if grep -q "release=" "${OUTPUT_FILE}"; then
153+
echo "FAIL: 'release= found in ${OUTPUT_FILE}" >&2
154+
cat "${OUTPUT_FILE}" >&2
155+
exit "${ksft_fail}"
156+
fi
157+
122158
rm "${OUTPUT_FILE}"
123159
}
124160

@@ -169,9 +205,11 @@ MSG="Test #1 from CPU${CPU}"
169205
set_cpu_nr
170206
# Enable taskname to be appended to sysdata
171207
set_taskname
208+
set_release
172209
runtest
173210
# Make sure the message was received in the dst part
174211
# and exit
212+
validate_release
175213
validate_sysdata
176214

177215
#====================================================
@@ -184,19 +222,19 @@ OUTPUT_FILE="/tmp/${TARGET}_2"
184222
MSG="Test #2 from CPU${CPU}"
185223
set_user_data
186224
runtest
225+
validate_release
187226
validate_sysdata
188227

189228
# ===================================================
190229
# TEST #3
191-
# Unset cpu_nr, so, no CPU should be appended.
192-
# userdata is still set
230+
# Unset all sysdata, fail if any userdata is set
193231
# ===================================================
194232
CPU=$((RANDOM % $(nproc)))
195233
OUTPUT_FILE="/tmp/${TARGET}_3"
196234
MSG="Test #3 from CPU${CPU}"
197-
# Enable the auto population of cpu_nr
198235
unset_cpu_nr
199236
unset_taskname
237+
unset_release
200238
runtest
201239
# At this time, cpu= shouldn't be present in the msg
202240
validate_no_sysdata

0 commit comments

Comments
 (0)