-
Notifications
You must be signed in to change notification settings - Fork 4
/
basic-tests.sh
executable file
·163 lines (128 loc) · 3.34 KB
/
basic-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#! /usr/bin/env bash
# Self tests for fastdd
# Author: Sudhi Herle
# License: Public Domain
FASTDD="./fastdd -q"
TESTDIR=/tmp/fastdd$$
# V important for pipelined commands!
set -o pipefail
die() {
echo "$0: $@" 1>&2
exit 1
}
mkdir -p $TESTDIR || die "Can't make $TESTDIR"
#trap "rm -rf $TESTDIR" EXIT INT QUIT ABRT
uname=$(uname)
case $uname in
Linux*)
MD5=md5sum
filesz() {
local fn=$1
local sz=$(stat -c '%s' $fn)
echo $sz
return 0
}
;;
Darwin|OpenBSD)
MD5='md5 -q'
filesz() {
local fn=$1
eval $(stat -s $fn)
echo $st_size
return 0
}
;;
*) die "Don't know how to do md5 on $uname"
;;
esac
FASTDD=
for d in dbg rel; do
f=$(uname)-$d/fastdd
if [ -x $f ]; then
FASTDD=$f
break
fi
done
[ -z $FASTDD ] && die "can't find fastdd in $(uname)-rel or $(uname)-dbg"
# verify arguments and such
basictests() {
local t=$TESTDIR
local in=$t/in
local out=$t/out
local out2=$t/out2
rdd if=/dev/urandom of=$in bs=1024 count=8 || die "can't dd"
# This should be first test to verify "nocreat"
begin "copy +nocreat"
fdd if=$in of=$out bs=1024 count=6 oflag=nocreat && die "fail nocreat"
end " OK"
begin "simple copy"
fdd if=$in of=$out bs=1024 count=8 || die "fail simple"
[ -f $out ] || die "fail no outfile"
xcmp $in $out
# Keep file from previous run!
begin "copy +notrunc"
fdd if=$in of=$out bs=1024 count=2 oflag=notrunc || die "fail notrunc"
xcmp $in $out
begin "copy +notrunc +nocreat"
fdd if=$in of=$out bs=1024 count=1 oflag=notrunc,nocreat || die "fail notrunc"
xcmp $in $out
# O_EXCL => don't succeed if file exists
# Do NOT remove file after previous test; we need it to verify 'excl'
begin "copy +excl"
fdd if=$in of=$out bs=1024 count=8 oflag=excl && die "fail exist+excl"
end " OK"
rm -f $out
begin "copy noexist +excl"
fdd if=$in of=$out bs=1024 count=8 oflag=excl || die "fail noexist+excl"
xcmp $in $out
# Do NOT remove file after previous test; we need it to verify 'trunc'
begin "copy +trunc"
rdd if=$in of=$in.2 bs=1024 count=2 || die "can't run dd"
fdd if=$in.2 of=$out bs=1024 count=2 oflag=trunc iosize=1k || die "failed trunc"
xcmp $in.2 $out
rm -f $out
begin "simple opipe"
(fdd if=$in bs=1024 count=8 iosize=1k | cat - > $out) || die "failed opipe"
xcmp $in $out
rm -f $out
begin "simple ipipe"
(cat $in | fdd of=$out bs=1024 count=8 iosize=1k) || die "failed ipipe"
xcmp $in $out
rm -f $out
begin "simple dualpipe"
(cat $in | fdd bs=1024 count=8 iosize=1k | cat - > $out) || die "failed dualpipe"
xcmp $in $out
rm -f $out
begin "seek opipe"
(fdd if=$in bs=1024 count=8 seek=1 | cat - >$out) && die "fail seek opipe"
end " OK"
rm -rf $TESTDIR
}
begin() {
echo -n "$@"
}
end() {
echo "$@"
}
xcmp() {
local inf=$1
local dec=$2
local a=`$MD5 $inf| awk '{print $1}'`
local b=`$MD5 $dec| awk '{print $1}'`
if [ $a != $b ]; then
end " Fail"
else
end " OK"
fi
return 0
}
fdd() {
$FASTDD -q "$@" 2>/dev/null
#$DD "$@"
return $?
}
rdd() {
dd "$@" >/dev/null 2>&1
return $?
}
basictests