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
12set -euo pipefail
13
14SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
15
16source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh
17# This is coming from netconsole code. Check for it in drivers/net/netconsole.c
18MAX_USERDATA_ITEMS=16
19
20# Function to create userdata entries
21function 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
32function 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
51modprobe netdevsim 2> /dev/null || true
52modprobe netconsole 2> /dev/null || true
53
54# Check for basic system dependency and exit if not found
55check_for_dependencies
56
57# Remove the namespace, interfaces and netconsole target on exit
58trap cleanup EXIT
59# Create one namespace and two interfaces
60set_network
61# Create a dynamic target for netconsole
62create_dynamic_target
63# populate the maximum number of supported keys in userdata
64create_userdata_max_entries
65# Verify an additional entry is not allowed
66verify_entry_limit
67exit "${ksft_pass}"
68