]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/autotest/v2_0/host/tftpget.sh
Initial revision
[karo-tx-redboot.git] / packages / net / autotest / v2_0 / host / tftpget.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4     echo "Usage: $0 target [tempfile [timeout [filesize]]]" > /dev/stderr
5     exit 1
6 fi
7
8 [ "xXFAIL" == "x$1" ] && { XFAIL="XFAIL"; shift; }
9 TARGET=$1
10 if [ "x" == "x$2" ]; then TMP=tftpdata; else TMP=$2; fi
11 if [ "x" == "x$3" ]; then TIMEOUT=10;   else TIMEOUT=$3; fi
12 if [ "x" == "x$4" ]; then SIZE=unknown; else SIZE=$4; fi
13
14 if [ -f $TMP ]; then
15     SRC=${TMP}
16     TMP=${TMP}.tmp
17 else
18     SRC=${TMP}.src
19     TMP=${TMP}.tmp
20 fi
21
22 if [ -f $SRC ]; then
23     [ $SIZE == unknown ] ||  \
24     { echo "FAIL: '$SRC' exists but size given" > /dev/stderr; exit 1; }
25 else
26     [ $SIZE == unknown ] && SIZE=876543
27     tmpfile $SRC $SIZE $$ || \
28     { echo "FAIL: Sourcefile '$SRC' create" > /dev/stderr; exit 1; }
29 fi
30
31 if [ ! -f $SRC ]; then
32     echo "FAIL: Sourcefile '$SRC' not found" > /dev/stderr; exit 1
33 fi
34
35 if [ "x$XFAIL" != "xXFAIL" ]; then
36     if ping -n -c5 $TARGET > /dev/null ; then
37         echo "INFO:<$$: $TARGET is up>" > /dev/stderr
38     else
39         echo "FAIL:<$$: $TARGET is down>" > /dev/stderr; exit 1
40     fi
41 fi
42
43 tftp $TARGET  <<-EOF
44         rexmt 1
45         binary
46         put $SRC $TMP
47 EOF
48
49 declare -i COUNT=0
50 declare -i FAILS=0
51
52 # This test is to test tftp GET not PUT so gloss over one failed put
53 # (ie. if it reports corrupt the first time, put it again).
54 rm -f $TMP
55 tftp $TARGET  <<-EOF
56         rexmt 1
57         binary
58         get $TMP $TMP
59 EOF
60 if ! cmp -s $SRC $TMP; then
61 echo "INFO:<$$: putting $SIZE bytes to $TARGET a second time>"
62 tftp $TARGET  <<-EOF
63         rexmt 1
64         binary
65         put $SRC $TMP
66 EOF
67 else
68 ((COUNT++));
69 fi
70
71 while [ $SECONDS -le $TIMEOUT ]; do
72 rm -f $TMP
73 tftp $TARGET  <<-EOF
74         rexmt 1
75         binary
76         get $TMP $TMP
77 EOF
78 [ -f $TMP ]       || [ "x$XFAIL" == "xXFAIL" ] || break
79 cmp -s $SRC $TMP  || { ((FAILS++)); [ "x$XFAIL" == "xXFAIL" ]; } || break
80 ((COUNT++));
81 done
82
83 if [ "x$XFAIL" == "xXFAIL" ]; then
84     echo "PASS:<$$: tftp get XFAIL, $TIMEOUT seconds $SIZE bytes $FAILS/$COUNT fails>" > /dev/stderr
85     exit 0
86 fi
87
88 if [ 1 -lt $FAILS ]; then
89     echo "FAIL:<$$: wierd, multiple failures $FAILS in $COUNT xfers>" > /dev/stderr
90 fi
91
92 if [ ! -f $TMP ]; then
93     echo "FAIL:<$$: temp file $TMP nonexistent $COUNT xfers>" > /dev/stderr
94     exit 1
95 fi
96
97 if ! cmp -s $SRC $TMP; then
98     echo "FAIL:<$$: temp file $TMP corrupt $COUNT xfers>" > /dev/stderr
99     exit 1
100 fi
101
102 echo "PASS:<$$: tftp get OK, $TIMEOUT seconds $SIZE bytes $COUNT xfers>" > /dev/stderr
103
104 # EOF