129a1c00cSLuis R. Rodriguez#!/bin/bash 229a1c00cSLuis R. Rodriguez# SPDX-License-Identifier: GPL-2.0 329a1c00cSLuis R. Rodriguez 429a1c00cSLuis R. Rodriguez# Library of helpers for test scripts. 529a1c00cSLuis R. Rodriguezset -e 629a1c00cSLuis R. Rodriguez 729a1c00cSLuis R. RodriguezDIR=/sys/devices/virtual/misc/test_firmware 829a1c00cSLuis R. Rodriguez 929a1c00cSLuis R. RodriguezPROC_CONFIG="/proc/config.gz" 1029a1c00cSLuis R. RodriguezTEST_DIR=$(dirname $0) 1129a1c00cSLuis R. Rodriguez 1229a1c00cSLuis R. Rodriguezprint_reqs_exit() 1329a1c00cSLuis R. Rodriguez{ 1429a1c00cSLuis R. Rodriguez echo "You must have the following enabled in your kernel:" >&2 1529a1c00cSLuis R. Rodriguez cat $TEST_DIR/config >&2 1629a1c00cSLuis R. Rodriguez exit 1 1729a1c00cSLuis R. Rodriguez} 1829a1c00cSLuis R. Rodriguez 1929a1c00cSLuis R. Rodrigueztest_modprobe() 2029a1c00cSLuis R. Rodriguez{ 2129a1c00cSLuis R. Rodriguez if [ ! -d $DIR ]; then 2229a1c00cSLuis R. Rodriguez print_reqs_exit 2329a1c00cSLuis R. Rodriguez fi 2429a1c00cSLuis R. Rodriguez} 2529a1c00cSLuis R. Rodriguez 2629a1c00cSLuis R. Rodriguezcheck_mods() 2729a1c00cSLuis R. Rodriguez{ 2829a1c00cSLuis R. Rodriguez trap "test_modprobe" EXIT 2929a1c00cSLuis R. Rodriguez if [ ! -d $DIR ]; then 3029a1c00cSLuis R. Rodriguez modprobe test_firmware 3129a1c00cSLuis R. Rodriguez fi 3229a1c00cSLuis R. Rodriguez if [ ! -f $PROC_CONFIG ]; then 3329a1c00cSLuis R. Rodriguez if modprobe configs 2>/dev/null; then 3429a1c00cSLuis R. Rodriguez echo "Loaded configs module" 3529a1c00cSLuis R. Rodriguez if [ ! -f $PROC_CONFIG ]; then 3629a1c00cSLuis R. Rodriguez echo "You must have the following enabled in your kernel:" >&2 3729a1c00cSLuis R. Rodriguez cat $TEST_DIR/config >&2 3829a1c00cSLuis R. Rodriguez echo "Resorting to old heuristics" >&2 3929a1c00cSLuis R. Rodriguez fi 4029a1c00cSLuis R. Rodriguez else 4129a1c00cSLuis R. Rodriguez echo "Failed to load configs module, using old heuristics" >&2 4229a1c00cSLuis R. Rodriguez fi 4329a1c00cSLuis R. Rodriguez fi 4429a1c00cSLuis R. Rodriguez} 45