File: test

package info (click to toggle)
parted 3.2-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 15,312 kB
  • ctags: 12,128
  • sloc: ansic: 68,106; sh: 18,156; makefile: 632; perl: 179; python: 45; asm: 36; sed: 16
file content (261 lines) | stat: -rwxr-xr-x 4,373 bytes parent folder | download | duplicates (6)
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
#! /bin/bash

do_help()
{
	echo You need to fill out the testrc with your machine\'s details before
	echo using this script.
	exit;
}

do_test()
{
	test_prog=$1
	test_name=`echo -n $test_prog | sed "s/test_//" | sed "s/_/ /" \
		   | tr '[:lower:]' '[:upper:]'`

	echo "-----------------------------------------------------------------"
	echo "TESTING $test_name..."
	echo "-----------------------------------------------------------------"

	echo "-----------------------------------------------------------------"\
		>> test_log
	echo "TESTING $test_name..." >> test_log
	echo "-----------------------------------------------------------------"\
		>> test_log

	if [ -e core* ]; then
		rm core*
	fi
	./$test_prog
	if [ -e test_out ]; then
		echo > test_out
	fi
}

do_tests()
{
	for walk in $TEST_LIST; do
		if [ -x $walk ]; then
			do_test $walk
		fi
	done
}

################################################
# GLOBAL HELPER FUNCTIONS
################################################

ped_testing()
{
	echo -n "testing $1... "
	echo -n "testing $1... " >> test_log
}

ped_testing_expect_fail()
{
	echo -n "testing for failure on $1... "
	echo -n "testing for failure on $1... " >> test_log
}

ped_test_ok()
{
	echo "ok"
	echo "ok" >> test_log

	if [ "x$VERBOSE_LOGS" = "x1" ]; then
		cat test_out >> test_log
		echo >> test_log
	fi

	export OK_COUNT=$[ $OK_COUNT + 1 ]
}

ped_test_failed()
{
	echo "failed"
	echo "failed" >> test_log

	cat test_out >> test_log
	echo >> test_log

	export FAILED_COUNT=$[ $FAILED_COUNT + 1 ]

	if [ -e core ]; then
		echo core dumped, saving to core-$CORE_COUNTER\
			>> test_log
		echo >> test_log
		mv core core-$CORE_COUNTER
		export CORE_COUNTER=$[ $CORE_COUNTER + 1 ]
	fi
}

check_leaks()
{
	if test "x$MALLOC_TRACE" != "x"; then
		./build_leak_list > leaks
		if test -s leaks; then
			printf \
'Found memory leaks: (add this list to dodgey_malloc_list in\n'\
'libparted/libparted.c to debug them)\n' \
				>> test_out
			cat leaks >> test_out
			return 0
		fi
		rm leaks
	fi

	return 1
}

ped_test_get_val()
{
	post_command=$2
	if test "x$input" = "x"; then
		input="Cancel"
	fi
	if test "x$post_command" = "x"; then
		post_command="true"
	fi

	if test -e leaks; then
		rm leaks
	fi
	if test "x$MALLOC_TRACE" != "x"; then
		if test -e $MALLOC_TRACE; then
			rm $MALLOC_TRACE
		fi
	fi

	if $TEST_PARTED_COMMAND -s $TEST_DRIVE $1 2>&1 > test_out; then
		if [ -e core ]; then
			return 0
		fi

		if check_leaks; then
			return 0
		fi

		if ( echo >> test_out ; ( eval $post_command ) 2>&1 >> test_out ); then
			return 1
		else
			return 0
		fi
	else
		return 0
	fi
}

ped_test()
{
	ped_testing "$1"
	if ped_test_get_val "$2" "$3"; then
		ped_test_failed
		return 1
	else
		ped_test_ok
		return 0
	fi
}

ped_test_expect_fail()
{
	ped_testing_expect_fail "$1"
	if ped_test_get_val "$2" "$3"; then

	# we expect a CLEAN fail :-)
		if [ -e core ]; then
			ped_test_failed
			return 1
		fi
		if check_leaks; then
			ped_test_failed
			return 1
		fi

		ped_test_ok
		return 0
	else
		ped_test_failed
		return 1
	fi
}

################################################
# the rest...
################################################

init_environment()
{
	if [ "x$UID" != "x0" ]; then
		echo Warning: you should probably be running this as root.
		echo
	fi

	. testrc
	`cat testrc | grep "^[^#].*=" | sed "s/=.*//" | sed "s/^/export /" `

	if [ "x$HOSTNAME" != "x$TEST_HOST" ]; then
		do_help
	fi

	export OLD_KERNEL_PRINTK=`cat /proc/sys/kernel/printk`

	if [ "x$QUIET_KERNEL" = "x1" ]; then
		echo 1 1 1 1 > /proc/sys/kernel/printk
	fi

	renice 20 $$ > /dev/null

	export CORE_COUNTER=1
	export OK_COUNT=0
	export FAILED_COUNT=0

	export -f ped_testing
	export -f ped_testing_expect_fail
	export -f ped_test_ok
	export -f ped_test_failed
	export -f ped_test_get_val
	export -f ped_test
	export -f ped_test_expect_fail
	export -f check_leaks
}

done_environment()
{
	echo $OLD_KERNEL_PRINTK > /proc/sys/kernel/printk
}

open_log()
{
	if [ -e test_log ]; then
		echo -n > test_log;
	fi
}

print_version()
{
	echo -n "Testing "
	$TEST_PARTED_COMMAND --version
	echo

	echo -n "Testing " >> test_log
	$TEST_PARTED_COMMAND --version >> test_log
	echo >> test_log
}

main()
{
	init_environment
	open_log
	print_version
	do_tests
	done_environment
}

if [ "x$1" !=  "x" ]; then
	export TEST_LIST="test_*$1*"
else
	export TEST_LIST="test_*"
fi

main