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