tools/testing/selftests/drivers/net/netconsole/netcons_fragmented_msg.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/netconsole/netcons_fragmented_msg.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/netconsole/netcons_fragmented_msg.sh
Extension
.sh
Size
4130 bytes
Lines
123
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

function header_to_regex() {
	# header is everything before ;
	local HEADER="${1}"
	REGEX=$(echo "${HEADER}" | cut -d'=' -f1)
	echo "${REGEX}=[0-9]*\/[0-9]*;"
}

# We have two headers in the message. Remove both to get the full message,
# and extract the full message.
function extract_msg() {
	local MSGFILE="${1}"
	# Extract the header, which is the very first thing that arrives in the
	# first list.
	HEADER=$(sed -n '1p' "${MSGFILE}" | cut -d';' -f1)
	HEADER_REGEX=$(header_to_regex "${HEADER}")

	# Remove the two headers from the received message
	# This will return the message without any header, similarly to what
	# was sent.
	sed "s/""${HEADER_REGEX}""//g" "${MSGFILE}"
}

# Validate the message, which has two messages glued together.
# unwrap them to make sure all the characters were transmitted.
# File will look like the following:
#  13,468,514729715,-,ncfrag=0/1135;<message>
#   key=<part of key>-13,468,514729715,-,ncfrag=967/1135;<rest of the key>
function validate_fragmented_result() {
	# Discard the netconsole headers, and assemble the full message
	RCVMSG=$(extract_msg "${1}")

	# check for the main message
	if ! echo "${RCVMSG}" | grep -q "${MSG}"; then
		echo "Message body doesn't match." >&2
		echo "msg received=" "${RCVMSG}" >&2
		exit "${ksft_fail}"
	fi

	# check userdata
	if ! echo "${RCVMSG}" | grep -q "${USERDATA_VALUE}"; then
		echo "message userdata doesn't match" >&2
		echo "msg received=" "${RCVMSG}" >&2
		exit "${ksft_fail}"
	fi
	# test passed. hooray
}

# Check for basic system dependency and exit if not found
check_for_dependencies
# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)
echo "6 5" > /proc/sys/kernel/printk
# Remove the namespace, interfaces and netconsole target on exit
trap cleanup EXIT
# Create one namespace and two interfaces
set_network
# Create a dynamic target for netconsole
create_dynamic_target
# Set userdata "key" with the "value" value
set_user_data


# TEST 1: Send message and userdata. They will fragment
# =======
MSG=$(printf -- 'MSG%.3s=' {1..150})

# Listen 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.
wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
# Send the message

Annotation

Implementation Notes