xref: /aosp_15_r20/external/ublksrv/tests/run_test.sh (revision 94c4a1e103eb1715230460aab379dff275992c20)
1#!/bin/bash
2# SPDX-License-Identifier: MIT or GPL-2.0-only
3
4DIR=$(cd "$(dirname "$0")";pwd)
5cd $DIR
6
7#. $DIR/common/fio_common
8
9: ${UBLK:=${DIR}/../ublk}
10if ! command -v "${UBLK}" &> /dev/null; then
11	echo "error: ublk command could not be found: ${UBLK}"
12	exit -1
13fi
14
15export UBLK
16export TEST_DIR=$DIR
17export UBLK_TMP=`mktemp /tmp/ublk_tmp_XXXXX`
18
19[ ! -d ${UBLK_TMP_DIR} ] && mkdir ${UBLK_TMP_DIR}
20
21run_test() {
22	TS=$1
23
24	NAME=`basename $TS`
25	TMP=`dirname $TS`
26	GRP=`basename $TMP`
27
28	echo "running $GRP/$NAME" | tee /dev/kmsg
29	sh -c $TS &
30	local TPID=$!
31	local timeout=600
32	local count=0
33	while [ $count -lt $timeout ]; do
34		sleep 1
35		kill -0 $TPID > /dev/null 2>&1
36		[ $? -ne 0 ] && break
37		let count++
38	done
39	[ $count -ge $timeout ] && echo "test $GRP/$NAME timeout"
40}
41
42run_test_grp() {
43	local D=$1
44	for ITEM in `ls ${D} | grep "^[0-9]" | grep -v "~$"`; do
45			#echo $D/$ITEM
46			run_test $D/$ITEM
47	done
48}
49
50run_test_all() {
51	local D=$1
52	local GRPS="generic $ALL_TGTS"
53	for G in $GRPS; do
54			run_test_grp $D/$G
55	done
56}
57
58display_usage() {
59	echo 'usage:'
60	echo '    run_test.sh <test> <test_running_time> <temp_dir>'
61}
62
63TEST=$1
64if [ -z "$TEST" ]; then
65	echo 'error: no test specified'
66	display_usage
67	exit -1
68fi
69
70[ ! -c /dev/ublk-control ] && echo 'please run "modprobe ublk_drv" first' && exit -1
71
72TDIR=$3
73if [ -z "$TDIR" ]; then
74	echo 'error: no temp dir specified'
75	display_usage
76	exit -1
77fi
78
79if [ "${TDIR:0:1}" != "/" ]; then
80	TDIR=`dirname $PWD`/${TDIR}
81fi
82
83export ALL_TGTS="null loop qcow2 nbd"
84export TRUNTIME=$2
85export UBLK_TMP_DIR=$TDIR
86export T_TYPE_PARAMS=""
87
88[ ! -d ${UBLK_TMP_DIR} ] && mkdir -p ${UBLK_TMP_DIR}
89
90_ITEMS=($(echo ${TEST} | tr ':' '\n'))
91for _ITEM in "${_ITEMS[@]}"; do
92	if [ -d ${_ITEM} ]; then
93		run_test_grp ${_ITEM}
94	elif [ -f ${_ITEM} ]; then
95		run_test ${_ITEM}
96	elif [ `basename ${_ITEM}` = "all" ]; then
97		run_test_all `dirname ${_ITEM}`
98	else
99		echo "error: test suite not found: ${_ITEM}"
100		exit -1
101	fi
102done
103
104rm -f ${UBLK_TMP}
105