r18884: client_test.exp getting changed to client_tests.exp was an intentional error...
[samba.git] / source / script / tests / test_win.sh
1 #!/bin/sh
2
3 # A shell script to connect to a windows host over telnet,
4 # setup for a smbtorture test,
5 # run the test,
6 # and remove the previously configured directory and share.
7 # Copyright Brad Henry <brad@samba.org> 2006
8 # Released under the GNU GPL v2 or later.
9
10 . script/tests/test_functions.sh
11
12 # This variable is defined in the per-hosts .fns file.
13 . $WINTESTCONF
14
15 # Setup the windows environment.
16 # This was the best way I could figure out including library files
17 # for the moment.
18 # I was finding that "cat common.exp wintest_setup.exp | expect -f -"
19 # fails to run, but exits with 0 status something like 1% of the time.
20
21 setup_qfileinfo_test()
22 {
23         echo -e "\nSetting up windows environment."
24         cat $WINTEST_DIR/common.exp > $TMPDIR/setup.exp
25         cat $WINTEST_DIR/wintest_setup.exp >> $TMPDIR/setup.exp
26         expect $TMPDIR/setup.exp
27         err_rtn=$?
28         rm -f $TMPDIR/setup.exp
29 }
30
31 # Clean up the windows environment after the test has run or failed.
32 remove_qfileinfo_test()
33 {
34         echo -e "\nCleaning up windows environment."
35         cat $WINTEST_DIR/common.exp > $TMPDIR/remove.exp
36         cat $WINTEST_DIR/wintest_remove.exp >> $TMPDIR/remove.exp
37         expect $TMPDIR/remove.exp
38         err_rtn=$?
39         rm -f $TMPDIR/remove.exp
40 }
41
42 restore_snapshot()
43 {
44         echo -e $1
45         perl -I$WINTEST_DIR $WINTEST_DIR/vm_load_snapshot.pl
46         echo "Snapshot restored."
47 }
48
49 # Index variable to count the total number of tests which fail.
50 all_errs=0
51
52 export SMBTORTURE_REMOTE_HOST=`perl -I$WINTEST_DIR $WINTEST_DIR/vm_get_ip.pl`
53 if [ -z $SMBTORTURE_REMOTE_HOST ]; then
54         # Restore snapshot to ensure VM is in a known state, then exit.
55         restore_snapshot "Test failed to get the IP address of the windows host."
56         exit 1
57 fi
58
59 test_name="RAW-QFILEINFO / WINDOWS SERVER"
60 echo -e "\n$test_name SETUP PHASE"
61
62 setup_qfileinfo_test
63
64 if [ $err_rtn -ne 0 ]; then
65         # If test setup fails, load VM snapshot and skip test.
66         restore_snapshot "\n$test_name setup failed, skipping test."
67 else
68         echo -e "\n$test_name setup completed successfully."
69         old_errs=$all_errs
70
71         testit "$test_name" $SMBTORTURE_BIN_PATH \
72                 -U $SMBTORTURE_USERNAME%$SMBTORTURE_PASSWORD \
73                 -d 10 -W $SMBTORTURE_WORKGROUP \
74                 //$SMBTORTURE_REMOTE_HOST/$SMBTORTURE_REMOTE_SHARE_NAME \
75                 RAW-QFILEINFO || all_errs=`expr $all_errs + 1`
76         if [ $old_errs -lt $all_errs ]; then
77                 # If test fails, load VM snapshot and skip cleanup.
78                 restore_snapshot "\n$test_name failed."
79         else
80                 echo -e "\n$test_name CLEANUP PHASE"
81                 remove_qfileinfo_test
82                 if [ $err_rtn -ne 0 ]; then
83                         # If cleanup fails, restore VM snapshot.
84                         restore_snapshot "\n$test_name removal failed."
85                 else
86                         echo -e "\n$test_name removal completed successfully."
87                 fi
88         fi
89 fi
90
91 test_name="RPC-WINREG / WINDOWS SERVER"
92 old_errs=$all_errs
93
94 testit "$test_name" $SMBTORTURE_BIN_PATH \
95         -U $SMBTORTURE_USERNAME%$SMBTORTURE_PASSWORD \
96         -W $SMBTORTURE_WORKGROUP \
97         ncacn_np:$SMBTORTURE_REMOTE_HOST \
98         RPC-WINREG || all_errs=`expr $all_errs + 1`
99 if [ $old_errs -lt $all_errs ]; then
100         restore_snapshot "\n$test_name failed."
101 fi
102
103 test_name="WINDOWS CLIENT / SAMBA SERVER SHARE"
104 old_errs=$all_errs
105 cat $WINTEST_DIR/common.exp > $TMPDIR/client_test.exp
106 cat $WINTEST_DIR/wintest_client.exp >> $TMPDIR/client_test.exp
107
108 testit "$test_name" \
109         expect $TMPDIR/client_test.exp || all_errs=`expr $all_errs + 1`
110
111 if [ $old_errs -lt $all_errs ]; then
112         # Restore snapshot to ensure VM is in a known state.
113         restore_snapshot "\n$test_name failed."
114         echo "Snapshot restored."
115 fi
116 rm -f $TMPDIR/client_test.exp
117
118 testok $0 $all_errs