3 # this runs a simple tarmode test
7 Usage: test_smbclient_tarmode.sh SERVER SERVER_IP USERNAME PASSWORD LOCAL_PATH PREFIX SMBCLIENT [create|extract] <smbclient arguments>
19 SMBCLIENT
="$VALGRIND ${SMBCLIENT}"
23 incdir
=`dirname $0`/..
/..
/..
/testprogs
/blackbox
28 # Check command is available
30 type "$1" > /dev
/null
2>&1
34 # Create a test corpus
43 if [ -e "$DIR" ]; then
44 echo "Test data directory '$DIR' already exists!"
49 if ! mkdir
-p "$DIR" > /dev
/null
2>&1; then
50 echo "Couldn't create test data directory '$DIR'"
56 if have_command
"od"; then # Use random file sizes
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)"
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)"
82 # Check that two directories are equivalent (In Data content)
87 diff -r "$DIR1" "$DIR2"
92 test_tarmode_creation
() {
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
100 if ! create_test_data
"$LOCAL_PATH/tarmode"; then
101 echo "Test data creation failed"
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"
114 # Extract data to verify
115 if ! tar -xf "$PREFIX/tarmode.tar" -C "$PREFIX"; then
116 echo "Couldn't extract data from created tarfile"
122 if ! validate_data
"$PREFIX/tarmode" "$LOCAL_PATH/tarmode"; then
123 echo "Data not equivalent"
134 test_tarmode_extraction
() {
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"
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"
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"
164 if ! validate_data
"$PREFIX/tarmode" "$LOCAL_PATH/tarmode"; then
165 echo "Data not equivalent"
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`