• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
4
5TST_TESTFUNC=test
6TST_SETUP=setup
7TST_CNT=3
8TST_NEEDS_CMDS="tst_check_drivers find grep head sed"
9. tst_test.sh
10
11MODULES_DIR="${MODULES_DIR:-/lib/modules/$(uname -r)}"
12
13setup()
14{
15	tst_res TINFO "using modules directory '$MODULES_DIR'"
16
17	[ -d "$MODULES_DIR" ] || \
18		tst_brk TCONF "modules directory '$MODULES_DIR' missing"
19}
20
21test_drivers()
22{
23	local paths="$*"
24	local drv
25
26	if [ -z "$paths" ]; then
27		tst_res TCONF "no modules found"
28		return
29	fi
30
31	for drv in $paths; do
32		drv="$(echo $drv | sed 's/.*\/\([^/]\+\)\.ko.*/\1/')"
33		EXPECT_PASS tst_check_drivers $drv
34		drv="$(echo $drv | sed 's/_/-/g')"
35		EXPECT_PASS tst_check_drivers $drv
36	done
37}
38
39test1()
40{
41	tst_res TINFO "check loadable module detection"
42	test_drivers $(find $MODULES_DIR | grep -E '_[^/]+\.ko' | head -3)
43}
44
45test2()
46{
47	tst_res TINFO "check non-existing module detection"
48	EXPECT_FAIL tst_check_drivers not-existing-kernel-module
49}
50
51test3()
52{
53	local f="$MODULES_DIR/modules.builtin"
54
55	tst_res TINFO "check built-in module detection"
56
57	[ -f "$f" ] || \
58		tst_brk TCONF "missing '$f'"
59
60	test_drivers $(grep -E '_[^/]+\.ko' $f | head -3)
61}
62
63tst_run
64