selftest/Samba4: make use of get_cmd_env_vars() to setup all relevant env variables
[samba.git] / source3 / script / tests / test_aio_outstanding.sh
1 #!/usr/bin/env bash
2 #
3 # Test terminating an smbclient connection with outstanding
4 # aio requests.
5 #
6 # Note this is designed to be run against
7 # the aio_delay_inject share which is preconfigured
8 # with 2 second delays on pread/pwrite.
9
10 if [ $# -lt 4 ]; then
11         echo Usage: test_aio_outstanding.sh \
12                 SERVERCONFFILE SMBCLIENT IP aio_delay_inject_sharename
13         exit 1
14 fi
15
16 CONF=$1
17 SMBCLIENT=$2
18 SERVER=$3
19 SHARE=$4
20
21 # Do not let deprecated option warnings muck this up
22 SAMBA_DEPRECATED_SUPPRESS=1
23 export SAMBA_DEPRECATED_SUPPRESS
24
25 incdir=$(dirname $0)/../../../testprogs/blackbox
26 . $incdir/subunit.sh
27
28 failed=0
29
30 cd $SELFTEST_TMPDIR || exit 1
31
32 #
33 # Note if we already have any panics in the smbd log.
34 #
35 panic_count_0=$(grep -c PANIC $SMBD_TEST_LOG)
36
37 # Create the smbclient communication pipes.
38 rm -f smbclient-stdin smbclient-stdout smbclient-stderr
39 mkfifo smbclient-stdin smbclient-stdout smbclient-stderr
40
41 # Create a large-ish testfile
42 rm aio_outstanding_testfile
43 head -c 20MB /dev/zero >aio_outstanding_testfile
44
45 CLI_FORCE_INTERACTIVE=1
46 export CLI_FORCE_INTERACTIVE
47
48 ${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
49         <smbclient-stdin >smbclient-stdout 2>smbclient-stderr &
50 CLIENT_PID=$!
51
52 sleep 1
53
54 exec 100>smbclient-stdin 101<smbclient-stdout 102<smbclient-stderr
55
56 # consume the smbclient startup messages
57 head -n 1 <&101
58
59 # Ensure we're putting a fresh file.
60 echo "del aio_outstanding_testfile" >&100
61 echo "put aio_outstanding_testfile" >&100
62
63 sleep 2
64
65 # Terminate the smbclient write to the aio_delay_inject share whilst
66 # we have outstanding writes.
67 kill $CLIENT_PID
68
69 sleep 1
70
71 # Ensure the panic count didn't change.
72 #
73 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=14301
74 #
75
76 panic_count_1=$(grep -c PANIC $SMBD_TEST_LOG)
77
78 # Rerun smbclient to remove the testfile on the server.
79 rm -f smbclient-stdin smbclient-stdout smbclient-stderr aio_outstanding_testfile
80 mkfifo smbclient-stdin smbclient-stdout
81
82 ${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
83         <smbclient-stdin >smbclient-stdout &
84
85 sleep 1
86
87 exec 100>smbclient-stdin 101<smbclient-stdout
88
89 echo "del aio_outstanding_testfile" >&100
90 echo "exit" >&100
91
92 sleep 2
93
94 rm -f smbclient-stdin smbclient-stdout aio_outstanding_testfile
95
96 testit "check_panic" test $panic_count_0 -eq $panic_count_1 ||
97         failed=$(expr $failed + 1)
98
99 testok $0 $failed