blob: adabf887c28f4ccff0af720a6bc1febb937b1daf [file] [log] [blame]
Anders Roxelle3f51b82024-07-04 12:30:01 +02001#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-only
3# Copyright (C) 2024 Linaro Ltd.
4
5# shellcheck disable=SC1091
6. ../../lib/sh-test-lib
7OUTPUT="$(pwd)/output"
8RESULT_FILE="${OUTPUT}/result.txt"
9export RESULT_FILE
10
11MODULES_LIST=""
12MODULES_SUBDIRS=""
13MODULE_MODPROBE_NUMBER="1"
14SHARD_NUMBER=1
15SHARD_INDEX=1
16
17usage() {
18 echo "Usage: $0 [-d <subdir of the modules directory> ]
19 [-l <space separated module list> ]
20 [-c <Number of load/unload of a module> ]
21 [-i <sharding bucket to run> ]
22 [-n <number of shard buckets to create> ]
23 [-h ]" 1>&2
24 exit 0
25}
26
27while getopts "c:d:i:l:n:h" o; do
28 case "$o" in
29 d) MODULES_SUBDIRS="${OPTARG}" ;;
30 l) MODULES_LIST="${OPTARG}" ;;
31 c) MODULE_MODPROBE_NUMBER="${OPTARG}" ;;
32 i) SHARD_INDEX="${OPTARG}" ;;
33 n) SHARD_NUMBER="${OPTARG}" ;;
34 h|*) usage ;;
35 esac
36done
37
38get_modules_list() {
39 if [ -z "${MODULES_LIST}" ]; then
40 rm -f /tmp/find_modules.txt
41 for subdir in ${MODULES_SUBDIRS}; do
42 find /lib/modules/"$(uname -r)"/kernel/"${subdir}" -type f -name '*.ko*' | tee -a /tmp/find_modules.txt
43 done
44 split --verbose --numeric-suffixes=1 -n l/"${SHARD_INDEX}"/"${SHARD_NUMBER}" /tmp/find_modules.txt > /tmp/shardfile
45 echo "============== Tests to run ==============="
46 cat /tmp/shardfile
47 echo "===========End Tests to run ==============="
48 if [ -s /tmp/shardfile ]; then
49 report_pass "shardfile"
50 else
51 report_fail "shardfile"
52 fi
53 while IFS= read -r line
54 do
55 module_basename=$(basename "${line}")
56 module_name=${module_basename%.*}
57 MODULES_LIST="${MODULES_LIST} ${module_name}"
58 done < /tmp/shardfile
59 fi
60}
61
62report() {
63 local _modprop_flag="${1}"
64 local _module="${2}"
65 local _text="${3}"
66 local _num="${4}"
67 echo
68 echo "${_text} module: ${_module}"
69 if ! modprobe "${_module}" "${_modprop_flag}"; then
70 report_fail "${_text}_module_${_num}_${_module}"
71 else
72 report_pass "${_text}_module_${_num}_${_module}"
73 fi
74}
75
76run () {
77 for module in ${MODULES_LIST}; do
78 # don't insert/remove modules that is already inserted.
79 if ! lsmod | grep "^${module}"; then
80 for num in $(seq "${MODULE_MODPROBE_NUMBER}"); do
81 dmesg -C
82 report "" "${module}" "insert" "${num}"
83 echo
84 echo "modinfo ${module}"
85 modinfo "${module}"
86 report "--remove" "${module}" "remove" "${num}"
87 dmesg -l 0,1,2,3,4,5
88 done
89 fi
90 done
91}
92
93# Test run.
94! check_root && error_msg "This script must be run as root"
95create_out_dir "${OUTPUT}"
96info_msg "Output directory: ${OUTPUT}"
97info_msg "About to run load/unload kernel modules ..."
98get_modules_list
99run