summaryrefslogtreecommitdiff
path: root/xts5/bin/run_assert
blob: 9907b1bc268c46705124699881fd3ff168db77e5 (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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
#!/bin/sh
# Copyright (c) 2005 X.Org Foundation L.L.C.
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#!/bin/sh
# $Header: /cvs/xtest/xtest/xts5/bin/run_assert,v 1.2 2005-11-03 08:42:00 jmichael Exp $
#
#		 Copyright (c) Applied Testing and Technology, Inc. 1993, 1994
#		 All Rights Reserved.
#
# Project:	  Common APIs for UNIX(R)-based Operating Systems
#
# File:		  run_assert
#
# Description:
#		 Runs a single test purpose
#
# Modifications:
# $Log: run_assert,v $
# Revision 1.2  2005-11-03 08:42:00  jmichael
# clean up all vsw5 paths to use xts5 instead.
#
# Revision 1.1.1.2  2005/04/15 14:05:06  anderson
# Reimport of the base with the legal name in the copyright fixed.
#
# Revision 8.0  1998/12/23 23:22:42  mar
# Branch point for Release 5.0.2
#
# Revision 7.0  1998/10/30 22:40:41  mar
# Branch point for Release 5.0.2b1
#
# Revision 6.0  1998/03/02 05:15:17  tbr
# Branch point for Release 5.0.1
#
# Revision 5.0  1998/01/26 03:11:49  tbr
# Branch point for Release 5.0.1b1
#
# Revision 4.1  1996/05/29 22:13:16  tbr
# change TMPDIR to /tmp instead of /usr/tmp
# /tmp is mandated by UNIX95, /usr/tmp is not
#
# Revision 4.0  1995/12/15  08:37:34  tbr
# Branch point for Release 5.0.0
#
# Revision 3.1  1995/12/15  00:33:19  andy
# Prepare for GA Release
#


PrintMessage() {
	echo "$PROGRAMNAME: $*" >&2
}

PrintWarning() {
	echo "$PROGRAMNAME: WARNING: $*" >&2
}

PrintError() {
	echo "$PROGRAMNAME: ERROR: $*" >&2
}

PrintFatalError() {
	echo "$PROGRAMNAME: FATAL ERROR: $*" >&2
	echo "$PROGRAMNAME: FATAL ERROR: ABORTING" >&2
	Exit 1
}

PrintDebug() {
	if [ $Debug = "true" -o "$DEBUG" = "true" ]
	then
		PrintMessage "$*"
	fi
	return 0
}


StringIsEmpty() {
	[ "$1" = "" ] && return 0
	return 1
}


FileIsNotARegularFile () {
	FileIsARegularFile "$1" && return 1
	return 0
}


FileIsARegularFile () {
	FileIsADirectory "$1" && return 1
	FileIsAPipe "$1" && return 1
	FileIsADevice "$1" && return 1
	return 0
}

StringIsNotEmpty() {
	StringIsEmpty "$1" && return 1
	return 0
}


FileIsNotEmpty() {
	FileIsEmpty "$1" && return 1
	return 0
}


FileExists() {
	[ -s "$1" ] && return 1
return 0
}


FileExists() {
	[ -s "$1" ] && return 0
	# this catches files with 0 length
	[ "`ls -d $1 2>/dev/null`" != "" ] && return 0
	return 1
}


FileDoesNotExist() {
	FileExists "$1" && return 1
	return 0
}


FileIsReadable() {
	FileDoesNotExist "$1" && return 1
	[ -r "$1" ] && return 0
	return 1
}


FileIsNotReadable() {
	FileDoesNotExist "$1" && return 1
	FileIsReadable "$1" && return 1
	return 0
}


FileIsWriteable() {
	FileDoesNotExist "$1" && return 1
	[ -w "$1" ] && return 0
	return 1
}


FileIsNotWriteable() {
	FileDoesNotExist "$1" && return 1
	[ -w "$1" ] && return 1
	return 0
}


FileIsExecutable() {
	FileDoesNotExist "$1" && return 1
	[ -x "$1" ] && return 0
	return 1
}


FileIsNotExecutable() {
	FileDoesNotExist "$1" && return 1
	FileIsExecutable "$1" && return 1
	return 0
}


FileIsADirectory() {
	[ -d "$1" ] && return 0
	return 1
}


FileIsNotADirectory() {
	FileIsADirectory $1 && return 1
	return 0
}


FileIsAPipe() {
[ -p "$1" ] && return 0
return 1
}


FileIsNotAPipe() {
FileIsAPipe "$1" && return 1
return 0
}


FileIsABlockDevice() {
[ -b "$1" ] && return 0
return 1
}


FileIsNotABlockDevice() {
FileIsABlockDevice "$1" && return 1
return 0
}


FileIsACharacterDevice() {
[ -c "$1" ] && return 0
return 1
}


FileIsNotACharacterDevice() {
FileIsACharacterDevice "$1" && return 1
return 0
}


FileIsADevice() {
FileIsABlockDevice "$1" && return 0
FileIsACharacterDevice "$1" && return 0
return 1
}


FileIsNotADevice() {
FileIsADevice "$1" && return 1
return 0
}


RemoveFile() {
	rm -f "$1" 2>/dev/null
	[ -s "$1" ] && return 1
	return 0
}



Exit()
{
StringIsNotEmpty "$TmpDir" && rm -rf $TmpDir/$$*
StringIsNotEmpty "$TMPDIR" && rm -rf $TMPDIR/$$*
StringIsNotEmpty "$TmpDir" && rm -rf $TmpDir/*.$$
StringIsNotEmpty "$TMPDIR" && rm -rf $TMPDIR/*.$$

[ $# -lt 1 ] && exit 0
[ $# -gt 1 ] && exit 1
[ $1 -eq 0 ] && exit 0
exit 1
}



SetAWK()
{
AWK=""
gawk '{ exit }' </etc/passwd >/dev/null 2>&1 &&
	AWK="gawk"
StringIsEmpty "$AWK" &&
	nawk '{ exit }' </etc/passwd >/dev/null 2>&1 &&
	AWK="nawk"
StringIsEmpty "$AWK" &&
	awk '{ exit }' </etc/passwd >/dev/null 2>&1 &&
	AWK="awk"
StringIsEmpty "$AWK" &&
	PrintFatalError "$0: AWK: not found"

PrintDebug "AWK is $AWK"
return 0
}



GetTestCaseVariables()
{
[ $# -ne 1 ] &&
	PrintError "$0: invalid or missing arguments" &&
	return 1
$AWK -v TestCase="$1" <$TetScenarioFile '
BEGIN {
if ( TestCase == "" )
	{ exit; }
TestCase = sprintf("^%s$", TestCase);
}

{
if ( match($0, TestCase) || (match($2, "CASE") && match($3, TestCase)) )
	{
	while (getline > 0)
		{
		if (substr($1, 1, 1) != "/")
			{ continue; }
		NumberOfElements = split($0, Elements, "/");
		printf("TestSection=%s ; TestDirectory=%s ; TestFile=%s",
		Elements[NumberOfElements - 2],
		Elements[NumberOfElements - 1],
		Elements[NumberOfElements]);
		break;
		}
	exit;
	}
}
'
return 0
}

Usage() {
echo "
Usage: $ProgramName [-Truss] [-NoClean] TestCase AssertionNumbers...

This tool runs the specified assertions for a single test case.
"

Exit 1
}



# main()
trap 'Exit 1' 1 2

PROGRAMNAME="`echo $0 | sed 's,^[	 -~]*/,,'`"
ProgramName=$PROGRAMNAME

if [ "$DEBUG" = "true" -o "$Debug" = "true" ]
then
	DEBUG=true ; export DEBUG
	Debug=true ; export Debug
else
	DEBUG=false ; export DEBUG
	Debug=false ; export Debug
fi

[ "$TMPDIR" = "" ] && TMPDIR=/tmp
FileDoesNotExist "$TMPDIR" &&
	PrintFatalError "$TMPDIR does not exist"
FileIsNotADirectory "$TMPDIR" &&
	PrintFatalError "$TMPDIR is not a directory"
FileIsNotReadable "$TMPDIR" &&
	PrintFatalError "$TMPDIR is not readable"
FileIsNotWriteable "$TMPDIR" &&
	PrintFatalError "$TMPDIR is not writeable"
FileIsNotExecutable "$TMPDIR" &&
	PrintFatalError "Can not cd to $TMPDIR"
TmpDir="$TMPDIR"

STARTDIR=`pwd`
StartDir=$STARTDIR

Clean=true ; Truss=false ; TestCase="" ; Assertions=""
while [ $# -gt 0 ]
do
	case $1 in
		-[Cc]le*)
			shift;
			Clean=true
			;;
		-[Nn]o[Cc]le*)
			shift;
			Clean=false
			;;
		-[Tt]r*)
			shift;
			Truss=true
			;;
		-[Dd]ebug)
			shift
			DEBUG=true ; export DEBUG
			;;
		-[Vv]erbose)
			shift
			DEBUG=true ; export DEBUG
			;;
		-[Hh]elp)
			Usage
			;;
		-[Uu]sage)
			Usage
			;;
		-*)
			Usage
			;;
		*)
			if [ "$TestCase" = "" ]
			then
				TestCase="$1"
			else
				if [ "$1" -gt 0 -a "$1" -lt 1000 ]
				then
					Assertions="$Assertions $1"
				else
					Usage
				fi
			fi
			shift
			;;
	esac
done

StringIsEmpty "$TestCase" &&
	PrintError "No test case was specified" &&
	Usage

StringIsEmpty "$Assertions" &&
	PrintError "No Assertion(s) were specified" &&
	Usage

StringIsEmpty "$TET_ROOT" &&
	PrintFatalError "TET_ROOT must be defined in your environment"
FileIsNotADirectory "$TET_ROOT" &&
	PrintFatalError "$TET_ROOT is not a directory"
FileIsReadable $TET_ROOT ||
	PrintFatalError "$TET_ROOT is not readable"
FileIsExecutable $TET_ROOT ||
	PrintFatalError "Can not cd to $TET_ROOT"

VSWHome=$TET_ROOT/xts5
FileIsNotADirectory "$VSWHome" &&
	PrintFatalError "$VSWHome does not exist"
FileIsNotADirectory "$VSWHome" &&
	PrintFatalError "$VSWHome is not a directory"
FileIsReadable $VSWHome ||
	PrintFatalError "$VSWHome is not readable"
FileIsExecutable $VSWHome ||
	PrintFatalError "Can not cd to $VSWHome"

TetScenarioFile="$VSWHome/tet_scen"
FileDoesNotExist $TetScenarioFile &&
	PrintFatalError "$TetScenarioFile must exist for this tool to run"
FileIsReadable $TetScenarioFile ||
	PrintFatalError "$TetScenarioFile is not readable"

ScenarioPath=$TmpDir/$ProgramName.$$

SetAWK

eval `GetTestCaseVariables $TestCase`
PrintDebug "TestSection($TestSection), TestDirectory($TestDirectory), TestFile($TestFile)"
StringIsEmpty "$TestSection" &&
	PrintFatalError "TestSection not found"
StringIsEmpty "$TestDirectory" &&
	PrintFatalError "TestDirectory not found"
StringIsEmpty "$TestFile" &&
	PrintFatalError "TestFile not found"

trap 'Exit 1' 1 2

# this is an imperfect header, the 1s we use are fillers
# this generates errors when you run a creport on the test journal
# but it would take too much time to generate the proper numbers 
echo "$TestCase" >$ScenarioPath
[ "$QA_TESTING" != "" ] &&
	echo "	\"VSW5TESTSUITE SECTION $TestSection 1 1 1 1\"" >>$ScenarioPath
echo "	\"VSW5TESTSUITE CASE $TestCase 0\"" >>$ScenarioPath

for Assertion in $Assertions
do
	echo "	/$TestSection/$TestDirectory/Test{$Assertion}" >>$ScenarioPath
done
 
tcc -c -s $ScenarioPath xts5 "$TestCase"

TccArgs=-be
$Clean && TccArgs=-bec
if [ "$Truss" = "true" ]
then
	truss -f -a tcc $TccArgs -s $ScenarioPath xts5 "$TestCase" 
else
	tcc $TccArgs -s $ScenarioPath xts5 "$TestCase"
fi

Exit 0