summaryrefslogtreecommitdiff
path: root/ecos/packages/net/autotest/current/host/tftpget.sh
blob: 090d786d7c60ef3405f979eb04a69c4460739def (plain)
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
#!/bin/sh

if [ $# -lt 1 ]; then
    echo "Usage: $0 target [tempfile [timeout [filesize]]]" > /dev/stderr
    exit 1
fi

[ "xXFAIL" == "x$1" ] && { XFAIL="XFAIL"; shift; }
TARGET=$1
if [ "x" == "x$2" ]; then TMP=tftpdata; else TMP=$2; fi
if [ "x" == "x$3" ]; then TIMEOUT=10;   else TIMEOUT=$3; fi
if [ "x" == "x$4" ]; then SIZE=unknown; else SIZE=$4; fi

if [ -f $TMP ]; then
    SRC=${TMP}
    TMP=${TMP}.tmp
else
    SRC=${TMP}.src
    TMP=${TMP}.tmp
fi

if [ -f $SRC ]; then
    [ $SIZE == unknown ] ||  \
    { echo "FAIL: '$SRC' exists but size given" > /dev/stderr; exit 1; }
else
    [ $SIZE == unknown ] && SIZE=876543
    tmpfile $SRC $SIZE $$ || \
    { echo "FAIL: Sourcefile '$SRC' create" > /dev/stderr; exit 1; }
fi

if [ ! -f $SRC ]; then
    echo "FAIL: Sourcefile '$SRC' not found" > /dev/stderr; exit 1
fi

if [ "x$XFAIL" != "xXFAIL" ]; then
    if ping -n -c5 $TARGET > /dev/null ; then
	echo "INFO:<$$: $TARGET is up>" > /dev/stderr
    else
	echo "FAIL:<$$: $TARGET is down>" > /dev/stderr; exit 1
    fi
fi

tftp $TARGET  <<-EOF
	rexmt 1
	binary
	put $SRC $TMP
EOF

declare -i COUNT=0
declare -i FAILS=0

# This test is to test tftp GET not PUT so gloss over one failed put
# (ie. if it reports corrupt the first time, put it again).
rm -f $TMP
tftp $TARGET  <<-EOF
	rexmt 1
	binary
	get $TMP $TMP
EOF
if ! cmp -s $SRC $TMP; then
echo "INFO:<$$: putting $SIZE bytes to $TARGET a second time>"
tftp $TARGET  <<-EOF
	rexmt 1
	binary
	put $SRC $TMP
EOF
else
((COUNT++));
fi

while [ $SECONDS -le $TIMEOUT ]; do
rm -f $TMP
tftp $TARGET  <<-EOF
	rexmt 1
	binary
	get $TMP $TMP
EOF
[ -f $TMP ]       || [ "x$XFAIL" == "xXFAIL" ] || break
cmp -s $SRC $TMP  || { ((FAILS++)); [ "x$XFAIL" == "xXFAIL" ]; } || break
((COUNT++));
done

if [ "x$XFAIL" == "xXFAIL" ]; then
    echo "PASS:<$$: tftp get XFAIL, $TIMEOUT seconds $SIZE bytes $FAILS/$COUNT fails>" > /dev/stderr
    exit 0
fi

if [ 1 -lt $FAILS ]; then
    echo "FAIL:<$$: wierd, multiple failures $FAILS in $COUNT xfers>" > /dev/stderr
fi

if [ ! -f $TMP ]; then
    echo "FAIL:<$$: temp file $TMP nonexistent $COUNT xfers>" > /dev/stderr
    exit 1
fi

if ! cmp -s $SRC $TMP; then
    echo "FAIL:<$$: temp file $TMP corrupt $COUNT xfers>" > /dev/stderr
    exit 1
fi

echo "PASS:<$$: tftp get OK, $TIMEOUT seconds $SIZE bytes $COUNT xfers>" > /dev/stderr

# EOF