[PATCH net-next 4/4] netconsole: selftest: Validate CPU number auto-population in userdata

Breno Leitao posted 4 patches 1 week, 2 days ago
[PATCH net-next 4/4] netconsole: selftest: Validate CPU number auto-population in userdata
Posted by Breno Leitao 1 week, 2 days ago
Expand the existing netconsole selftest to verify the functionality of
the recently added CPU number auto-population feature in the netconsole
userdata.

The changes include enabling the "populate_cpu_nr" option on the
netconsole target before sending the test data, and validating that the
received data on the listener side contains a "cpu=" entry in the
userdata, indicating that the CPU number was successfully
auto-populated.

This addition to the netconsole selftest ensures that the new CPU number
auto-population feature works as expected and helps catch any
regressions in this functionality.

Signed-off-by: Breno Leitao <leitao@debian.org>
---
 tools/testing/selftests/drivers/net/netcons_basic.sh | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/testing/selftests/drivers/net/netcons_basic.sh b/tools/testing/selftests/drivers/net/netcons_basic.sh
index b175f4d966e5056ddb62e335f212c03e55f50fb0..92538a188f0696b3e54071d1d32c7b2e523db839 100755
--- a/tools/testing/selftests/drivers/net/netcons_basic.sh
+++ b/tools/testing/selftests/drivers/net/netcons_basic.sh
@@ -153,6 +153,16 @@ function set_user_data() {
 	echo "${USERDATA_VALUE}" > "${VALUE_PATH}"
 }
 
+function set_cpu_nr() {
+	if [[ ! -f "${NETCONS_PATH}""/userdata/populate_cpu_nr" ]]
+	then
+		echo "Populate CPU configfs path not available in ${NETCONS_PATH}/userdata/populate_cpu_nr" >&2
+		exit "${ksft_skip}"
+	fi
+
+	echo 1 > "${NETCONS_PATH}""/userdata/populate_cpu_nr"
+}
+
 function listen_port_and_save_to() {
 	local OUTPUT=${1}
 	# Just wait for 2 seconds
@@ -185,6 +195,12 @@ function validate_result() {
 		exit "${ksft_fail}"
 	fi
 
+	if ! grep -q "cpu=[0-9]\+" "${TMPFILENAME}"; then
+		echo "FAIL: 'cpu=' not found in ${TMPFILENAME}" >&2
+		cat "${TMPFILENAME}" >&2
+		exit "${ksft_fail}"
+	fi
+
 	# Delete the file once it is validated, otherwise keep it
 	# for debugging purposes
 	rm "${TMPFILENAME}"
@@ -254,6 +270,8 @@ set_network
 create_dynamic_target
 # Set userdata "key" with the "value" value
 set_user_data
+# Auto populate CPU number
+set_cpu_nr
 # Listed for netconsole port inside the namespace and destination interface
 listen_port_and_save_to "${OUTPUT_FILE}" &
 # Wait for socat to start and listen to the port.

-- 
2.43.5
Re: [PATCH net-next 4/4] netconsole: selftest: Validate CPU number auto-population in userdata
Posted by Jakub Kicinski 4 days, 6 hours ago
On Wed, 13 Nov 2024 07:10:55 -0800 Breno Leitao wrote:
> +	if ! grep -q "cpu=[0-9]\+" "${TMPFILENAME}"; then
> +		echo "FAIL: 'cpu=' not found in ${TMPFILENAME}" >&2
> +		cat "${TMPFILENAME}" >&2
> +		exit "${ksft_fail}"
> +	fi

Could we try to do something like pick a 'random' CPU ID from sysfs,
taskset the write / echo, and match that the incoming message has the
expected CPU ID, not just any?