s3:test: fix registry roundtrip test on older systems (usage of mktemp)
[Samba.git] / source3 / script / tests / test_net_registry_roundtrip.sh
blob390db5ed05a3ce732a7d8073f6a567585e09322c
1 #!/bin/sh
3 # Blackbox test for net conf/registry roundtrips.
5 # Copyright (C) 2010 Gregor Beck <gbeck@sernet.de>
6 # Copyright (C) 2011 Michael Adam <obnox@samba.org>
8 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
11 if test "x${RPC}" = "xrpc" ; then
12 NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
13 else
14 NETREG="${NET} registry"
17 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
18 incdir=`dirname $0`/../../../testprogs/blackbox
19 . $incdir/subunit.sh
22 failed=0
24 SED_INVALID_PARAMS="{
25 s/lock directory/;&/g
26 s/modules dir/;&/g
27 s/logging/;&/g
28 s/status/;&/g
29 s/logdir/;&/g
30 s/read prediction/;&/g
31 s/mkprofile/;&/g
32 s/valid chars/;&/g
33 s/timesync/;&/g
34 s/sambaconf/;&/g
35 s/logtype/;&/g
36 s/servername/;&/g
39 REGPATH="HKLM\Software\Samba"
41 conf_roundtrip_step() {
42 echo $* >>$LOG
43 $@ 2>>$LOG
44 # echo -n .
47 LOGDIR_PREFIX="conf_roundtrip"
49 conf_roundtrip()
51 local DIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXX)
52 local LOG=$DIR/log
54 echo conf_roundtrip $1 > $LOG
56 sed -e "$SED_INVALID_PARAMS" $1 >$DIR/conf_in
58 conf_roundtrip_step $NET conf drop
59 test -z "$($NET conf list)" 2>>$LOG
60 if [ "$?" = "1" ]; then
61 echo "ERROR: conf drop failed" | tee -a $LOG
62 return 1
65 conf_roundtrip_step $NET conf import $DIR/conf_in
66 conf_roundtrip_step $NET conf list > $DIR/conf_exp
68 grep "\[global\]" $DIR/conf_exp >/dev/null 2>>$LOG
69 if [ "$?" = "1" ]; then
70 echo "ERROR: conf import => conf export failed" | tee -a $LOG
71 return 1
74 conf_roundtrip_step $NET -d10 registry export $REGPATH $DIR/conf_exp.reg
76 conf_roundtrip_step $NET conf drop
77 test -z "$($NET conf list)" 2>>$LOG
78 if [ "$?" = "1" ]; then
79 echo "ERROR: conf drop failed" | tee -a $LOG
80 return 1
83 conf_roundtrip_step $NET registry import $DIR/conf_exp.reg
85 conf_roundtrip_step $NET conf list >$DIR/conf_out
86 diff -q $DIR/conf_out $DIR/conf_exp >> $LOG
87 if [ "$?" = "1" ]; then
88 echo "ERROR: registry import => conf export failed" | tee -a $LOG
89 return 1
92 conf_roundtrip_step $NET registry export $REGPATH $DIR/conf_out.reg
93 diff -q $DIR/conf_out.reg $DIR/conf_exp.reg >>$LOG
94 if [ "$?" = "1" ]; then
95 echo "Error: registry import => registry export failed" | tee -a $LOG
96 return 1
98 rm -r $DIR
101 CONF_FILES=${CONF_FILES:-$(find $SRCDIR/ -name '*.conf' | xargs grep -l "\[global\]")}
103 # remove old logs:
104 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
105 echo "removing old directory ${OLDDIR}"
106 rm -rf ${OLDDIR}
107 done
109 for conf_file in $CONF_FILES
111 testit "conf_roundtrip $conf_file" \
112 conf_roundtrip $conf_file \
113 || failed=`expr $failed + 1`
114 done
116 testok $0 $failed