s3: Fix vfs_zfsacl to compile.
[Samba/gebeck_regimport.git] / source3 / script / tests / test_smbclient_tarmode.sh
blob331ba2021998eb463ce4b480c727536c33061eb6
1 #!/bin/sh
3 # this runs a simple tarmode test
5 if [ $# -lt 7 ]; then
6 cat <<EOF
7 Usage: test_smbclient_tarmode.sh SERVER SERVER_IP USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT [create|extract] <smbclient arguments>
8 EOF
9 exit 1;
12 SERVER="$1"
13 SERVER_IP="$2"
14 USERNAME="$3"
15 PASSWORD="$4"
16 LOCAL_PATH="$5"
17 PREFIX="$6"
18 SMBCLIENT="$7"
19 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
20 shift 7
21 ADDARGS="$*"
23 incdir=`dirname $0`/../../../testprogs/blackbox
24 . $incdir/subunit.sh
26 FAILCOUNT=0
28 # Check command is available
29 have_command() {
30 type "$1" > /dev/null 2>&1
31 return $?
34 # Create a test corpus
35 create_test_data() {
37 local DIR="$1"
38 local BS=1024
39 local NUM_FILES=10
40 local NORND_COUNT=25
42 # Bomb if dir exists
43 if [ -e "$DIR" ]; then
44 echo "Test data directory '$DIR' already exists!"
45 false
46 return
49 if ! mkdir -p "$DIR" > /dev/null 2>&1; then
50 echo "Couldn't create test data directory '$DIR'"
51 false
52 return
55 local I=1
56 if have_command "od"; then # Use random file sizes
57 local RND_COUNT
58 for RND_COUNT in `od -An -N$NUM_FILES -tu1 < /dev/urandom`; do
59 if ! dd if=/dev/urandom of="$DIR/file.$I" bs=$BS count=$RND_COUNT > /dev/null 2>&1; then
60 echo "Couldn't create test file '$DIR/file.$I' (random size)"
61 false
62 return
64 I=`expr $I + 1`
65 done
66 else # Fallback to same file sizes
67 while [ $I -le $NUM_FILES ]; do
68 if ! dd if=/dev/urandom of="$DIR/file.$I" bs=$BS count=$NORND_COUNT > /dev/null 2>&1; then
69 echo "Couldn't create test file '$DIR/file.$I' (static size)"
70 false
71 return
73 I=`expr $I + 1`
74 done
77 true
78 return
82 # Check that two directories are equivalent (In Data content)
83 validate_data() {
84 local DIR1="$1"
85 local DIR2="$2"
87 diff -r "$DIR1" "$DIR2"
88 return $?
91 # Test tarmode -Tc
92 test_tarmode_creation() {
94 # Clear temp data
95 rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1
96 rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1
97 rm -rf "$LOCAL_PATH"/tarmode > /dev/null 2>&1
99 # Build the test data
100 if ! create_test_data "$LOCAL_PATH/tarmode"; then
101 echo "Test data creation failed"
102 false
103 return
106 # Create tarfile with smbclient
107 if ! $SMBCLIENT //$SERVER/tmp $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \
108 $ADDARGS -c "tarmode full" -Tc "$PREFIX/tarmode.tar" "/tarmode"; then
109 echo "Couldn't create tar file with tarmode -Tc"
110 false
111 return
114 # Extract data to verify
115 if ! tar -xf "$PREFIX/tarmode.tar" -C "$PREFIX"; then
116 echo "Couldn't extract data from created tarfile"
117 false
118 return
121 # Verify data
122 if ! validate_data "$PREFIX/tarmode" "$LOCAL_PATH/tarmode"; then
123 echo "Data not equivalent"
124 false
125 return
128 true
129 return
133 # Test tarmode -Tx
134 test_tarmode_extraction() {
136 # Clear temp data
137 rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1
138 rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1
139 rm -rf "$LOCAL_PATH"/tarmode > /dev/null 2>&1
141 # Build the test data
142 if ! create_test_data "$PREFIX/tarmode"; then
143 echo "Test data creation failed"
144 false
145 return
148 # Create tarfile to extract on client
149 if ! tar -cf "$PREFIX/tarmode.tar" -C "$PREFIX" tarmode; then
150 echo "Couldn't create tar archive"
151 false
152 return
155 # Extract tarfile with smbclient
156 if ! $SMBCLIENT //$SERVER/tmp $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \
157 $ADDARGS -c "tarmode full" -Tx "$PREFIX/tarmode.tar"; then
158 echo "Couldn't extact tar file with tarmode -Tx"
159 false
160 return
163 # Verify data
164 if ! validate_data "$PREFIX/tarmode" "$LOCAL_PATH/tarmode"; then
165 echo "Data not equivalent"
166 false
167 return
170 true
171 return
175 testit "test_tarmode_creation" \
176 test_tarmode_creation || FAILCOUNT=`expr $FAILCOUNT + 1`
178 testit "test_tarmode_extraction" \
179 test_tarmode_extraction || FAILCOUNT=`expr $FAILCOUNT + 1`
181 testok $0 $FAILCOUNT