blob: f4d8444ad7a60e1afa37ac985c964714f8120e6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#!/bin/bash
## CONFIG ##
export dtf_resultdir=${dtf_resultdir_override-/var/tmp/dtf}
export dtf_srcdir=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
export dtf_testdir=${dtf_testdir-$dtf_srcdir}
export dtf_resultxml_file=/var/tmp/dtf.xml
export dtf_option_verbose=0
export dtf_option_force=0
export dtf_option_testids=""
export dtf_option_listonly=0
. $dtf_srcdir/lib.sh
## F.DEFS ##
info()
{
echo " * $@"
}
die()
{
echo "$@" >&2
exit 1
}
# run TESTDIR
# -----------
# source the $TESTDIR/runtest.sh
run()
{
export dtf_workdir=$1
export dtf_test_id=`basename $dtf_workdir`
dtf_resultxml_cache "$( cd $dtf_workdir
. ./config.sh
echo "<test>"
echo "<id>$DTF_TEST_ID</id>"
echo "<description>"
echo "$DTF_TEST_DESCRIPTION"
echo "</description>"
)"
( cd $dtf_workdir
outlog="$dtf_resultdir/$dtf_test_id.log"
output_wrapper="cat > $outlog"
test $dtf_option_verbose = 1 \
&& output_wrapper="tee $outlog"
test ! -e ./config.sh -o ! -e ./config.sh \
&& echo "can not find one of {config,runtest}.sh" \
&& exit 1
. ./config.sh
if test "$dtf_option_listonly" -eq 1; then
echo $DTF_TEST_ID
exit 0
fi
if test -n "$dtf_option_testids"; then
[[ "$dtf_option_testids" = *\ $DTF_TEST_ID\ * ]] || exit 0
fi
printf "%-40s" "RUN $DTF_TEST_ID ..."
set -o pipefail
( . $dtf_srcdir/lib.sh || exit 1
. ./config.sh
. ./runtest.sh
rv=$?
test -n "$DTF_RESULT_TARBALL" \
&& cp "$DTF_RESULT_TARBALL" $dtf_resultdir/$dtf_test_id.tar.gz
exit $rv
) 2>&1 | eval $output_wrapper
rv=$?
test $rv -eq 0 && echo "[ OK ]" || echo "[ FAIL ]"
exit $rv
)
}
prepare_resultdir()
{
if test -e "$dtf_resultdir"; then
test $dtf_option_force -eq 0 && die "result dir $dtf_resultdir exits"
rm -rf $dtf_resultdir || die "can not remove $dtf_resultdir"
fi
mkdir -p "$dtf_resultdir" || die "can not create $dtf_resultdir"
}
show_help()
{
cat <<EOHELP >&2
Usage: $0 [OPTIONS]
Script is aimed to perform set of tests in subdirectories.
Options:
--force Overwrite result dir if exists
--listonly List the available test ids
--testid=TESTID Perform this test only
--verbose Show complete output from each test
--help Show this help
EOHELP
test -n "$1" && exit $1
}
longopts="verbose,help,force,testid:,listonly"
ARGS=`getopt -o "v" -l "$longopts" -n "getopt" -- "$@"`
if [ $? -ne 0 ]; then
echo "getopt error"
exit 1
fi
eval set -- "$ARGS"
while true; do
case "$1" in
--verbose)
dtf_option_verbose=1
shift
;;
--force)
dtf_option_force=1
shift
;;
--listonly)
dtf_option_listonly=1
shift
;;
--testid)
dtf_option_testids="$dtf_option_testids $2 "
shift 2
;;
--help)
show_help 0
;;
--)
shift
break
;;
esac
done
test $dtf_option_listonly -ne 1 && prepare_resultdir
dtf_resultxml_init "$dtf_resultxml_file"
result=0
for i in `find $dtf_testdir -name runtest.sh`; do
testdir=`dirname $i`
run $testdir || result=1
test $result -eq 0 \
&& dtf_resultxml_cache "<result>Success</result></test>" \
|| dtf_resultxml_cache "<result>Fail</result></test>"
done
dtf_resultxml_finish
exit $result
|