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