summaryrefslogtreecommitdiff
path: root/source4/script/tests/selftest.sh
blob: 92fba70c4a5d83f861006615df95dbedb8d6e5d5 (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
#!/bin/sh
# Bootstrap Samba and run a number of tests against it.

if [ $# -lt 1 ]
then
	echo "$0 PREFIX TESTS"
	exit
fi

ARG0=$0
ARG1=$1
ARG2=$2
ARG3=$3

if [ -z "$TORTURE_MAXTIME" ]; then
    TORTURE_MAXTIME=1200
fi

# disable rpc validation when using valgrind - its way too slow
if [ -z "$VALGRIND" ]; then
    VALIDATE="validate";
else
    VALIDATE="";
fi

OLD_PWD=`pwd`
PREFIX=$ARG1
PREFIX=`echo $PREFIX | sed s+//+/+`
export PREFIX

# allow selection of the test lists
TESTS=$ARG2

if [ $TESTS = "all" ]; then
    TLS_ENABLED="yes"
else
    TLS_ENABLED="no"
fi
export TLS_ENABLED

LD_LDB_MODULE_PATH=$OLD_PWD/bin/modules/ldb
export LD_LDB_MODULE_PATH

LD_SAMBA_MODULE_PATH=$OLD_PWD/bin/modules
export LD_SAMBA_MODULE_PATH

LD_LIBRARY_PATH=$OLD_PWD/bin/shared:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

PKG_CONFIG_PATH=$OLD_PWD/bin/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH

incdir=`dirname $ARG0`
echo -n "PROVISIONING..."
. $incdir/mktestsetup.sh $PREFIX >/dev/null || exit 1
echo "DONE"

PATH=bin:$PATH
export PATH

DO_SOCKET_WRAPPER=$ARG3
if [ x"$DO_SOCKET_WRAPPER" = x"SOCKET_WRAPPER" ];then
	SOCKET_WRAPPER_DIR="$PREFIX/w"
	export SOCKET_WRAPPER_DIR
	echo "SOCKET_WRAPPER_DIR=$SOCKET_WRAPPER_DIR"
else
	echo "NOT USING SOCKET_WRAPPER"
fi

incdir=`dirname $ARG0`
. $incdir/test_functions.sh

#Start slapd before smbd
if [ x"$TEST_LDAP" = x"yes" ]; then
    if test -z "$FEDORA_DS_PREFIX"; then
	slapd_start || exit 1;
    else
	perl $FEDORA_DS_PREFIX/lib/fedora-ds/ds_newinst.pl $FEDORA_DS_INF || exit 1;
    fi
    echo -n "LDAP PROVISIONING..."
    $srcdir/bin/smbscript $srcdir/setup/provision $PROVISION_OPTIONS "$PROVISION_ACI" --ldap-backend=$LDAP_URI || {
	echo "LDAP PROVISIONING failed: $srcdir/bin/smbscript $srcdir/setup/provision $PROVISION_OPTIONS $PROVISION_ACI --ldap-backend=$LDAP_URI"
	exit 1;
    }
    #LDAP is slow
    TORTURE_MAXTIME=`expr $TORTURE_MAXTIME '*' 2`
fi

SMBD_TEST_FIFO="$PREFIX/smbd_test.fifo"
export SMBD_TEST_FIFO
SMBD_TEST_LOG="$PREFIX/smbd_test.log"
export SMBD_TEST_LOG

SOCKET_WRAPPER_DEFAULT_IFACE=1
export SOCKET_WRAPPER_DEFAULT_IFACE
smbd_check_or_start

SOCKET_WRAPPER_DEFAULT_IFACE=6
export SOCKET_WRAPPER_DEFAULT_IFACE
TORTURE_INTERFACES='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'
TORTURE_OPTIONS="--option=interfaces=$TORTURE_INTERFACES $CONFIGURATION"
# ensure any one smbtorture call doesn't run too long
TORTURE_OPTIONS="$TORTURE_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
TORTURE_OPTIONS="$TORTURE_OPTIONS --target=samba4"
export TORTURE_OPTIONS

if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
	TORTURE_OPTIONS="$TORTURE_OPTIONS --option=torture:progress=no"
fi

 runtest() {
	if [ -z "$PREFIX" ]; then
	    PREFIX=test_prefix
	    mkdir -p $PREFIX
	fi
	name=$1
	shift 1
	cmdline="$*"

	SMBD_IS_UP="no"

	shname=`echo $name | \
	sed -e 's%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g'`

	UNIQUE_PID=`/bin/sh -c 'echo $$'`
	TEST_LOG="$PREFIX/test_log.${UNIQUE_PID}"
	TEST_PCAP="$PREFIX/test_${shname}_${UNIQUE_PID}.pcap"
	trap "rm -f $TEST_LOG $TEST_PCAP" EXIT

        if [ -n "$SMBD_TEST_LOG" -a -z "$smbd_log_size" ]; then
	    smbd_log_size=`wc -l < $SMBD_TEST_LOG`;
	fi

	if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
		echo "--==--==--==--==--==--==--==--==--==--==--"
		echo "Running test $name (level 0 stdout)"
		echo "--==--==--==--==--==--==--==--==--==--==--"
		date
		echo "Testing $name"
	else
	        nf="`expr $failed + $totalfailed`";
		if [ "$nf" = "0" ]; then 
		    echo "[$current/$total] Testing $name"
		else 
		    echo "[$current/$total, $nf failures] Testing $name"
		fi
	fi

	smbd_check_only && SMBD_IS_UP="yes"
	if [ x"$SMBD_IS_UP" != x"yes" ];then
		if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
			echo "SMBD is down! Skipping: $cmdline"
			echo "=========================================="
			echo "TEST SKIPPED: $name (reason SMBD is down)"
			echo "=========================================="
   		else
			echo "TEST SKIPPED: $name (reason SMBD is down)"
		fi
		return 1
	fi

	if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then
		SOCKET_WRAPPER_PCAP_FILE=$TEST_PCAP
		export SOCKET_WRAPPER_PCAP_FILE
	fi

	( $cmdline > $TEST_LOG 2>&1 )
	status=$?
	# show any additional output from smbd that has happened in this test
	smbd_have_test_log && {		    
	    new_log_size=`wc -l < $SMBD_TEST_LOG`;
	    test "$new_log_size" = "$smbd_log_size" || {
		echo "SMBD OUTPUT:";
		incr_log_size=`expr $new_log_size - $smbd_log_size`;
		tail -$incr_log_size $SMBD_TEST_LOG;
		smbd_log_size=$new_log_size;
	    }
	}
	if [ x"$status" != x"0" ]; then
		echo "TEST OUTPUT:"
		cat $TEST_LOG;
		rm -f $TEST_LOG;
		if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then
			echo "TEST PCAP: $TEST_PCAP"
		fi
		if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
			echo "=========================================="
			echo "TEST FAILED: $name (status $status)"
			echo "=========================================="
   		else
			echo "TEST FAILED: $cmdline (status $status)"
		fi
		trap "" EXIT
		return 1;
	fi
	rm -f $TEST_LOG;
	if [ x"$MAKE_TEST_KEEP_PCAP" = x"yes" ];then
		echo "TEST PCAP: $TEST_PCAP"
	else
		rm -f $TEST_PCAP;
	fi
	if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
		echo "ALL OK: $cmdline"
		echo "=========================================="
		echo "TEST PASSED: $name"
		echo "=========================================="
	fi
	trap "" EXIT
	return 0;
}

START=`date`
(
 # give time for nbt server to register its names
 echo delaying for nbt name registration
 sleep 4
 # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
 bin/nmblookup $CONFIGURATION $SERVER
 bin/nmblookup $CONFIGURATION -U $SERVER $SERVER
 bin/nmblookup $CONFIGURATION $SERVER
 bin/nmblookup $CONFIGURATION -U $SERVER $NETBIOSNAME
 bin/nmblookup $CONFIGURATION $NETBIOSNAME
 bin/nmblookup $CONFIGURATION -U $SERVER $NETBIOSNAME

# start off with 0 failures
totalfailed=0
export totalfailed

. script/tests/tests_$TESTS.sh > $PREFIX/recipe
total=`grep "TEST --" $PREFIX/recipe | wc -l`
current=0
cat $PREFIX/recipe | (
 	while read LINE
	do
		if [ "$LINE" = "-- TEST --" ]; then
			read NAME
			read CMDLINE
			current=`expr $current + 1`
			runtest "$NAME" "$CMDLINE" || totalfailed=`expr $totalfailed + $?`
		else
			echo "$LINE"
		fi
 	done
	exit $totalfailed
)
exit $?
) 9>$SMBD_TEST_FIFO
totalfailed=$?

smbd_PID=`cat $PIDDIR/smbd.pid`
waitforpid $smbd_PID 20 || {
    echo "smbd process $1 took more than 20 seconds to exit, killing"
    kill -9 $smbd_PID
}

if [ "$TEST_LDAP"x = "yesx" ]; then
    if test -z "$FEDORA_DS_PREFIX"; then
	kill `cat $PIDDIR/slapd.pid`
    else
	$LDAPDIR/slapd-samba4/stop-slapd
    fi
fi

END=`date`
echo "START: $START ($ARG0)";
echo "END:   $END ($ARG0)";

# if there were any valgrind failures, show them
count=`find $PREFIX -name 'valgrind.log*' | wc -l`
if [ "$count" != 0 ]; then
    for f in $PREFIX/valgrind.log*; do
	if [ -s $f ] && grep -v DWARF2.CFI.reader $f > /dev/null; then
	    echo "VALGRIND FAILURE";
	    totalfailed=`expr $totalfailed + 1`
	    cat $f
	fi
    done
fi

teststatus $ARG0 $totalfailed