summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLorry <lorry@roadtrain.codethink.co.uk>2012-08-15 09:31:11 +0100
committerLorry <lorry@roadtrain.codethink.co.uk>2012-08-15 09:31:11 +0100
commitd0dc3f5c30ca0b8350b48ba032a65681bfa20bdb (patch)
tree17ada9ef2482441523576855dce14785e40d96a3 /tests
downloadpv-d0dc3f5c30ca0b8350b48ba032a65681bfa20bdb.tar.gz
Tarball conversion
Diffstat (limited to 'tests')
-rw-r--r--tests/000-cat8
-rw-r--r--tests/001-interval12
-rw-r--r--tests/002-rate13
-rw-r--r--tests/003-progress13
-rw-r--r--tests/004-timer14
-rw-r--r--tests/005-eta20
-rw-r--r--tests/006-ratecount22
-rw-r--r--tests/007-bytes10
-rw-r--r--tests/008-numeric18
-rw-r--r--tests/009-quiet9
-rw-r--r--tests/010-pipe26
-rw-r--r--tests/011-cksum26
-rw-r--r--tests/012-averagerate24
-rw-r--r--tests/013-1mboundary25
-rw-r--r--tests/014-1mboundary225
-rw-r--r--tests/015-cksumpipe53
16 files changed, 318 insertions, 0 deletions
diff --git a/tests/000-cat b/tests/000-cat
new file mode 100644
index 0000000..1b07549
--- /dev/null
+++ b/tests/000-cat
@@ -0,0 +1,8 @@
+#!/bin/sh
+#
+# Check that data can be just passed straight through.
+
+VALUE=`echo TESTING | $PROG 2>/dev/null` || exit 1
+test "$VALUE" = "TESTING"
+
+# EOF
diff --git a/tests/001-interval b/tests/001-interval
new file mode 100644
index 0000000..2903cb8
--- /dev/null
+++ b/tests/001-interval
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Check that the update interval can be set.
+
+sleep 1 | $PROG -f -i 0.1 >/dev/null 2>$TMP1
+
+# There should be more than 6 lines of output.
+#
+NUM=`tr '\r' '\n' < $TMP1 | wc -l | tr -d ' '`
+test $NUM -gt 6
+
+# EOF
diff --git a/tests/002-rate b/tests/002-rate
new file mode 100644
index 0000000..2609ce4
--- /dev/null
+++ b/tests/002-rate
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# A simple test of rate limiting.
+
+# Transfer 102 bytes at 100 bytes/sec. It should take at least 1 second.
+#
+START=`date +%S`
+dd if=/dev/zero bs=102 count=1 2>/dev/null | $PROG -L 100 2>/dev/null | cat >/dev/null
+END=`date +%S`
+
+test $START -ne $END
+
+# EOF
diff --git a/tests/003-progress b/tests/003-progress
new file mode 100644
index 0000000..d6438f7
--- /dev/null
+++ b/tests/003-progress
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# Check that the progress bar moves when data is coming in.
+
+dd if=/dev/zero bs=100 count=1 2>/dev/null \
+| $PROG -f -p -i 0.1 -L 500 >/dev/null 2>$TMP1
+
+# There should be more than 2 different lines of output.
+#
+NUM=`tr '\r' '\n' < $TMP1 | sort | uniq -u | wc -l | tr -d ' '`
+test $NUM -gt 2
+
+# EOF
diff --git a/tests/004-timer b/tests/004-timer
new file mode 100644
index 0000000..ab1c134
--- /dev/null
+++ b/tests/004-timer
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Check that the elapsed time counter does count up.
+
+# Transfer a zero amount of data, but take 3 seconds to do it.
+#
+(sleep 3 | $PROG -f -t >/dev/null) 2>&1 | tr '\r' '\n' > $TMP1
+
+# Count the number of different timer values; it should be >1.
+#
+NUM=`sort < $TMP1 | uniq -u | wc -l | tr -d ' '`
+test $NUM -gt 1
+
+# EOF
diff --git a/tests/005-eta b/tests/005-eta
new file mode 100644
index 0000000..0f0eb40
--- /dev/null
+++ b/tests/005-eta
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Check that the estimated time counter counts.
+
+dd if=/dev/zero bs=100 count=1 2>/dev/null \
+| $PROG -f -e -s 100 -i 0.1 -L 25 >/dev/null 2>$TMP1
+
+# Count the number of different ETA values there have been.
+#
+NUM=`tr '\r' '\n' < $TMP1 | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' '`
+
+# 3 or less - not OK, since it should have taken 4 seconds.
+#
+test $NUM -gt 3 || exit 1
+
+# 8 or more - not OK, since even on a heavily loaded system that's too long.
+#
+test $NUM -lt 8
+
+# EOF
diff --git a/tests/006-ratecount b/tests/006-ratecount
new file mode 100644
index 0000000..1d4ea86
--- /dev/null
+++ b/tests/006-ratecount
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Check that the transfer rate counter changes.
+
+# Transfer 200 bytes as two 100-byte blocks with a 2-second gap between.
+#
+(dd if=/dev/zero bs=100 count=1 2>/dev/null;
+ sleep 2;
+ dd if=/dev/zero bs=100 count=1 2>/dev/null;
+) | $PROG -f -i 0.5 -r >/dev/null 2>$TMP1
+
+# Count the number of different rates output.
+#
+NUM=`tr '\r' '\n' < $TMP1 | sort | uniq -u | wc -l | tr -d ' '`
+
+# There should be more than 2 different rates counted (around 100 bytes/sec
+# for the each block, 0 bytes/sec for the gap in the middle, and around 50
+# bytes/sec for the average time reported at the end).
+#
+test $NUM -gt 2
+
+# EOF
diff --git a/tests/007-bytes b/tests/007-bytes
new file mode 100644
index 0000000..ca0cfc6
--- /dev/null
+++ b/tests/007-bytes
@@ -0,0 +1,10 @@
+#!/bin/sh
+#
+# Check that the byte counter counts.
+
+dd if=/dev/zero bs=100 count=1 2>/dev/null \
+| LANG=C $PROG -f -b >/dev/null 2>$TMP1
+NUM=`tr '\r' '\n' < $TMP1 | tr -d ' '`
+test "$NUM" = "100B"
+
+# EOF
diff --git a/tests/008-numeric b/tests/008-numeric
new file mode 100644
index 0000000..baa44f2
--- /dev/null
+++ b/tests/008-numeric
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Check that numeric output outputs some percentages.
+
+# Process 100 bytes at 100 bytes per second, updating every 0.1 seconds for
+# around 10 output lines.
+#
+dd if=/dev/zero bs=100 count=1 2>/dev/null \
+| $PROG -s 100 -n -i 0.1 -L 100 >/dev/null 2>$TMP1
+
+# The number of output lines should be >8 and <13, and the final percentage
+# should be 100.
+#
+test `wc -l < $TMP1` -gt 8
+test `wc -l < $TMP1` -lt 13
+test `sed -n '$p' < $TMP1` -eq 100
+
+# EOF
diff --git a/tests/009-quiet b/tests/009-quiet
new file mode 100644
index 0000000..a75da36
--- /dev/null
+++ b/tests/009-quiet
@@ -0,0 +1,9 @@
+#!/bin/sh
+#
+# Check that the -q option shuts everything up.
+
+dd if=/dev/zero bs=1000 count=5 2>/dev/null \
+| $PROG -f -q -i 0.1 -L 5000 >/dev/null 2>$TMP1
+test ! -s $TMP1
+
+# EOF
diff --git a/tests/010-pipe b/tests/010-pipe
new file mode 100644
index 0000000..8e569dd
--- /dev/null
+++ b/tests/010-pipe
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Check that there is no SIGPIPE or dropped data on bigger data transfers.
+
+# We nead GNU head. On some platforms it is named ghead instead of head.
+HEAD=head
+for p in `echo $PATH | tr ':' '\n'`
+do
+ if test -x $p/ghead
+ then
+ HEAD=$p/ghead
+ break
+ fi
+done
+
+# Don't use dd. See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=324308
+COUNT1=100000000
+#COUNT2=`$PROG -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | wc -c | tr -d ' '`
+# Remove \n to fix the test on AIX
+COUNT2=`$PROG -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | tr -d '\n' | wc -c | tr -d ' '`
+
+#echo "[$COUNT1] [$COUNT2]"
+
+test "x$COUNT1" = "x$COUNT2"
+
+# EOF
diff --git a/tests/011-cksum b/tests/011-cksum
new file mode 100644
index 0000000..beb8443
--- /dev/null
+++ b/tests/011-cksum
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Transfer a large chunk of data through pv and check data correctness
+# afterwards.
+
+rm -f $TMP1 $TMP2 2>/dev/null
+
+# exit on non-zero return codes
+set -e
+
+# generate some data
+dd if=/dev/urandom of=$TMP1 bs=1024 count=10240 2>/dev/null
+
+CKSUM1=`cksum $TMP1 | awk '{print $1}'`
+
+# read through pv and test afterwards
+$PROG -B 100000 -q $TMP1 > $TMP2
+
+CKSUM2=`cksum $TMP2 | awk '{print $1}'`
+
+test "x$CKSUM1" = "x$CKSUM2"
+
+# clean up
+rm -f $TMP1 $TMP2 2>/dev/null
+
+# EOF
diff --git a/tests/012-averagerate b/tests/012-averagerate
new file mode 100644
index 0000000..89b77be
--- /dev/null
+++ b/tests/012-averagerate
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# Check that the average transfer rate counter changes, but not more than it
+# should.
+
+# Transfer 210 bytes as 100 bytes, a 1 second gap, 110 bytes, and another 1
+# second gap.
+#
+(dd if=/dev/zero bs=100 count=1 2>/dev/null;
+ sleep 1;
+ dd if=/dev/zero bs=110 count=1 2>/dev/null;
+ sleep 1;
+) | $PROG -f -i 0.5 -a >/dev/null 2>$TMP1
+
+# Count the number of rates output that are below 80.
+#
+NUM=`tr '\r' '\n' < $TMP1 | tr -dc '0-9.\n' | sed '/^$/d' | awk '$1<80{print}' | wc -l | tr -d ' '`
+
+# Nearly all of the output rates should be above 80 since the average rate
+# will always be around 100 bytes per second, except for pauses.
+#
+test $NUM -lt 2
+
+# EOF
diff --git a/tests/013-1mboundary b/tests/013-1mboundary
new file mode 100644
index 0000000..89e2523
--- /dev/null
+++ b/tests/013-1mboundary
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Check that the bytes count doesn't increase the line length as it passes
+# 1MiB, described here:
+# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586763
+
+# Transfer 1500kB of data in a bursty fashion.
+#
+(dd if=/dev/zero bs=1k count=999;
+ sleep 1;
+ dd if=/dev/zero bs=1k count=1;
+ sleep 1;
+ dd if=/dev/zero bs=1k count=500;
+ sleep 1;
+) 2>/dev/null | ($PROG -btef -s 1500k >/dev/null) 2>$TMP1
+
+# Count how many different line lengths we've seen.
+#
+NUM=`tr '\r' '\n' < $TMP1 | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l`
+
+# There should only be one length (not counting 0).
+#
+test $NUM -eq 1 || { echo; tr '\r' '\n' < $TMP1; exit 1; }
+
+# EOF
diff --git a/tests/014-1mboundary2 b/tests/014-1mboundary2
new file mode 100644
index 0000000..00738cc
--- /dev/null
+++ b/tests/014-1mboundary2
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Same as test 13 (1mboundary) but for rate, not bytes transferred.
+
+# Transfer 1500kB of data in a bursty fashion.
+#
+(dd if=/dev/zero bs=1k count=999;
+ sleep 1;
+ dd if=/dev/zero bs=1k count=1;
+ sleep 1;
+ dd if=/dev/zero bs=3 count=1;
+ sleep 1;
+ dd if=/dev/zero bs=1k count=500;
+ sleep 1;
+) 2>/dev/null | ($PROG -rtef -s 1500k >/dev/null) 2>$TMP1
+
+# Count how many different line lengths we've seen.
+#
+NUM=`tr '\r' '\n' < $TMP1 | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l`
+
+# There should only be one length (not counting 0).
+#
+test $NUM -eq 1 || { echo; tr '\r' '\n' < $TMP1; exit 1; }
+
+# EOF
diff --git a/tests/015-cksumpipe b/tests/015-cksumpipe
new file mode 100644
index 0000000..665d729
--- /dev/null
+++ b/tests/015-cksumpipe
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Transfer a large chunk of data through pv using pipes, sending it in a
+# bursty fashion, and check data correctness afterwards.
+
+rm -f $TMP1 $TMP2 2>/dev/null
+
+# exit on non-zero return codes
+set -e
+
+# generate some data
+dd if=/dev/urandom of=$TMP1 bs=1024 count=10240 2>/dev/null
+
+CKSUM1=`cksum $TMP1 | awk '{print $1}'`
+
+# read through pv and test afterwards
+(
+dd if=$TMP1 bs=1 count=9000
+sleep 1
+dd if=$TMP1 bs=1 skip=9000 count=1240
+sleep 1
+dd if=$TMP1 bs=1024 skip=10 count=1014
+sleep 1
+dd if=$TMP1 bs=1024 skip=1024 count=1024
+sleep 1
+dd if=$TMP1 bs=1024 skip=2048
+) 2>/dev/null | $PROG -q -L 2M | cat > $TMP2
+
+CKSUM2=`cksum $TMP2 | awk '{print $1}'`
+
+test "x$CKSUM1" = "x$CKSUM2"
+
+# same again but with one less pipe
+(
+dd if=$TMP1 bs=1 count=9000
+sleep 1
+dd if=$TMP1 bs=1 skip=9000 count=1240
+sleep 1
+dd if=$TMP1 bs=1024 skip=10 count=1014
+sleep 1
+dd if=$TMP1 bs=1024 skip=1024 count=1024
+sleep 1
+dd if=$TMP1 bs=1024 skip=2048
+) 2>/dev/null | $PROG -q -L 2M > $TMP2
+
+CKSUM2=`cksum $TMP2 | awk '{print $1}'`
+
+test "x$CKSUM1" = "x$CKSUM2"
+
+# clean up
+rm -f $TMP1 $TMP2 2>/dev/null
+
+# EOF