1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci# SPDX-License-Identifier: GPL-2.0-or-later
3f08c3bdfSopenharmony_ci# Copyright (c) 2016 Fujitsu Ltd.
4f08c3bdfSopenharmony_ci# Copyright (c) Linux Test Project, 2016-2023
5f08c3bdfSopenharmony_ci# Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
6f08c3bdfSopenharmony_ci#
7f08c3bdfSopenharmony_ci# Test basic functionality of insmod command.
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_ciTST_CLEANUP=cleanup
10f08c3bdfSopenharmony_ciTST_TESTFUNC=do_test
11f08c3bdfSopenharmony_ciTST_NEEDS_ROOT=1
12f08c3bdfSopenharmony_ciTST_NEEDS_CMDS="rmmod insmod"
13f08c3bdfSopenharmony_ciTST_NEEDS_MODULE="ltp_insmod01.ko"
14f08c3bdfSopenharmony_ciTST_SKIP_IN_LOCKDOWN=1
15f08c3bdfSopenharmony_ciTST_SKIP_IN_SECUREBOOT=1
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ciinserted=0
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_cicleanup()
20f08c3bdfSopenharmony_ci{
21f08c3bdfSopenharmony_ci	if [ $inserted -ne 0 ]; then
22f08c3bdfSopenharmony_ci		tst_res TINFO "running rmmod ltp_insmod01"
23f08c3bdfSopenharmony_ci		rmmod ltp_insmod01
24f08c3bdfSopenharmony_ci		if [ $? -ne 0 ]; then
25f08c3bdfSopenharmony_ci			tst_res TWARN "failed to rmmod ltp_insmod01"
26f08c3bdfSopenharmony_ci		fi
27f08c3bdfSopenharmony_ci		inserted=0
28f08c3bdfSopenharmony_ci	fi
29f08c3bdfSopenharmony_ci}
30f08c3bdfSopenharmony_ci
31f08c3bdfSopenharmony_cido_test()
32f08c3bdfSopenharmony_ci{
33f08c3bdfSopenharmony_ci	insmod "$TST_MODPATH"
34f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
35f08c3bdfSopenharmony_ci		tst_res TFAIL "insmod failed"
36f08c3bdfSopenharmony_ci		return
37f08c3bdfSopenharmony_ci	fi
38f08c3bdfSopenharmony_ci	inserted=1
39f08c3bdfSopenharmony_ci
40f08c3bdfSopenharmony_ci	grep -q ltp_insmod01 /proc/modules
41f08c3bdfSopenharmony_ci	if [ $? -ne 0 ]; then
42f08c3bdfSopenharmony_ci		tst_res TFAIL "ltp_insmod01 not found in /proc/modules"
43f08c3bdfSopenharmony_ci		return
44f08c3bdfSopenharmony_ci	fi
45f08c3bdfSopenharmony_ci
46f08c3bdfSopenharmony_ci	cleanup
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci	tst_res TPASS "insmod passed"
49f08c3bdfSopenharmony_ci}
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci. tst_test.sh
52f08c3bdfSopenharmony_citst_run
53