File: mini_tdir.sh

package info (click to toggle)
unbound 1.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,436 kB
  • sloc: ansic: 138,476; sh: 6,860; yacc: 4,259; python: 1,950; makefile: 1,881; awk: 162; perl: 158; xml: 36
file content (232 lines) | stat: -rwxr-xr-x 5,351 bytes parent folder | download | duplicates (3)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# tdir that only exes the files.
args="../.."
if test "$1" = "-a"; then
	args=$2
	shift
	shift
fi

# This will keep the temporary directory around and return 1 when the test failed.
DEBUG=0
test -n "$DEBUG_TDIR" && DEBUG=1

quiet=0
if test "$1" = "-q"; then
	quiet=1
	shift
fi

if test "$1" = "clean"; then
	if test $quiet = 0; then
		echo "rm -f result.* .done* .skip* .tdir.var.master .tdir.var.test"
	fi
	rm -f result.* .done* .skip* .tdir.var.master .tdir.var.test
	exit 0
fi
if test "$1" = "fake"; then
	if test $quiet = 0; then
		echo "minitdir fake $2"
	fi
	echo "fake" > .done-`basename $2 .tdir`
	exit 0
fi
if test "$1" = "-f" && test "$2" = "report"; then
	echo "Minitdir Long Report"
	pass=0
	fail=0
	skip=0
	echo "   STATUS    ELAPSED TESTNAME TESTDESCRIPTION"
	for result in *.tdir; do
		name=`basename $result .tdir`
		timelen="     "
		desc=""
		if test -f "result.$name"; then
			timestart=`grep ^DateRunStart: "result.$name" | sed -e 's/DateRunStart: //'`
			timeend=`grep ^DateRunEnd: "result.$name" | sed -e 's/DateRunEnd: //'`
			timesec=`expr $timeend - $timestart`
			timelen=`printf %4ds $timesec`
			if test $? -ne 0; then
				timelen="$timesec""s"
			fi
			desc=`grep ^Description: "result.$name" | sed -e 's/Description: //'`
		fi
		if test -f ".done-$name"; then
			if test $quiet = 0; then
				echo "** PASSED ** $timelen $name: $desc"
				pass=`expr $pass + 1`
			fi
		elif test -f ".skip-$name"; then
			echo ".. SKIPPED.. $timelen $name: $desc"
			skip=`expr $skip + 1`
		else
			if test -f "result.$name"; then
				echo "!! FAILED !! $timelen $name: $desc"
				fail=`expr $fail + 1`
			else
				echo ".. SKIPPED.. $timelen $name: $desc"
				skip=`expr $skip + 1`
			fi
		fi
	done
	echo ""
	if test "$skip" = "0"; then
		echo "$pass pass, $fail fail"
	else
		echo "$pass pass, $fail fail, $skip skip"
	fi
	echo ""
	exit 0
fi
if test "$1" = "report" || test "$2" = "report"; then
	echo "Minitdir Report"
	for result in *.tdir; do
		name=`basename $result .tdir`
		if test -f ".done-$name"; then
			if test $quiet = 0; then
				echo "** PASSED ** : $name"
			fi
		elif test -f ".skip-$name"; then
			if test $quiet = 0; then
				echo ".. SKIPPED.. : $name"
			fi
		else
			if test -f "result.$name"; then
				echo "!! FAILED !! : $name"
			else
				if test $quiet = 0; then
					echo ".. SKIPPED.. : $name"
				fi
			fi
		fi
	done
	exit 0
fi

if test "$1" != 'exe'; then
	# usage
	echo "mini tdir. Reduced functionality for old shells."
	echo "	tdir [-q] exe <file>"
	echo "	tdir [-q] fake <file>"
	echo "	tdir [-q] clean"
	echo "	tdir [-q|-f] report"
	exit 1
fi
shift

# do not execute if the disk is too full
#DISKLIMIT=100000
# This check is not portable (to Solaris 10).
#avail=`df . | tail -1 | awk '{print $4}'`
#if test "$avail" -lt "$DISKLIMIT"; then
	#echo "minitdir: The disk is too full! Only $avail."
	#exit 1
#fi

name=`basename $1 .tdir`
dir=$name.$$
result=result.$name
done=.done-$name
skip=.skip-$name
asan_text="SUMMARY: AddressSanitizer"
success="no"
if test -x "`which bash`"; then
	shell="bash"
else
	shell="sh"
fi

# check already done
if test -f $done; then
	echo "minitdir $done exists. skip test."
	exit 0
fi

# Copy
if test $quiet = 0; then
	echo "minitdir copy $1 to $dir"
fi
mkdir $dir
if cp --help 2>&1 | grep -- "-a" >/dev/null; then
cp -a $name.tdir/* $dir/
else
cp -R $name.tdir/* $dir/
fi
cd $dir

# EXE
echo "minitdir exe $name" > $result
grep "Description:" $name.dsc >> $result 2>&1
echo "DateRunStart: "`date "+%s" 2>/dev/null` >> $result
if test -f $name.pre; then
	if test $quiet = 0; then
		echo "minitdir exe $name.pre"
	fi
	echo "minitdir exe $name.pre" >> $result
	$shell $name.pre $args >> $result
	exit_value=$?
	if test $exit_value -eq 3; then
		echo "$name: SKIPPED" >> $result
		echo "$name: SKIPPED" > ../$skip
		echo "$name: SKIPPED"
	elif test $exit_value -ne 0; then
		echo "Warning: $name.pre did not exit successfully"
	fi
fi
if test -f $name.test -a ! -f ../$skip; then
	if test $quiet = 0; then
		echo "minitdir exe $name.test"
	fi
	echo "minitdir exe $name.test" >> $result
	$shell $name.test $args >>$result 2>&1
	if test $? -ne 0; then
		echo "$name: FAILED" >> $result
		echo "$name: FAILED"
		success="no"
	else
		echo "$name: PASSED" >> $result
		echo "$name: PASSED" > ../$done
		if test $quiet = 0; then
			echo "$name: PASSED"
		fi
		success="yes"
	fi
fi
if test -f $name.post -a ! -f ../$skip; then
	if test $quiet = 0; then
		echo "minitdir exe $name.post"
	fi
	echo "minitdir exe $name.post" >> $result
	$shell $name.post $args >> $result
	if test $? -ne 0; then
		echo "Warning: $name.post did not exit successfully"
	fi
fi
# Check if there were any AddressSanitizer errors
# if compiled with -fsanitize=address
if grep "$asan_text" $result >/dev/null 2>&1; then
	if test -f ../$done; then
		rm ../$done
	fi
	echo "$name: FAILED (AddressSanitizer)" >> $result
	echo "$name: FAILED (AddressSanitizer)"
	success="no"
fi
echo "DateRunEnd: "`date "+%s" 2>/dev/null` >> $result

mv $result ..
cd ..
if test $DEBUG -eq 0; then
	rm -rf $dir
	# compat for windows where deletion may not succeed initially (files locked
	# by processes that still have to exit).
	if test $? -eq 1; then
		echo "minitdir waiting for processes to terminate"
		sleep 2 # some time to exit, and try again
		rm -rf $dir
	fi
else
	if test $success = "no"; then
		exit 1
	fi
	exit 0
fi