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