summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorLandry Breuil <landry@cvs.openbsd.org>2012-11-01 10:49:12 +0000
committerLandry Breuil <landry@cvs.openbsd.org>2012-11-01 10:49:12 +0000
commit2292f459669a55ef9dc9a5122fae2d837b414d06 (patch)
tree3ca1c4ac2a9affda991854cd7585696cb9eeb27d /regress
parent4902be292f926a36c13b675bc238ee47e3cc750b (diff)
Add regress tests for tail -f.
newsyslog test failing atm on NFS.. ok sthen@
Diffstat (limited to 'regress')
-rw-r--r--regress/usr.bin/tail/Makefile16
-rw-r--r--regress/usr.bin/tail/follow-newsyslog.sh44
-rw-r--r--regress/usr.bin/tail/follow-overwrite-by-file.out3
-rw-r--r--regress/usr.bin/tail/follow-overwrite-by-file.sh34
-rw-r--r--regress/usr.bin/tail/follow-overwrite-data.out4
-rw-r--r--regress/usr.bin/tail/follow-overwrite-data.sh38
-rw-r--r--regress/usr.bin/tail/follow-removed-recreated.out3
-rw-r--r--regress/usr.bin/tail/follow-removed-recreated.sh37
-rw-r--r--regress/usr.bin/tail/follow-renames.out3
-rw-r--r--regress/usr.bin/tail/follow-renames.sh33
10 files changed, 215 insertions, 0 deletions
diff --git a/regress/usr.bin/tail/Makefile b/regress/usr.bin/tail/Makefile
new file mode 100644
index 00000000000..5adb880a532
--- /dev/null
+++ b/regress/usr.bin/tail/Makefile
@@ -0,0 +1,16 @@
+# $OpenBSD: Makefile,v 1.1 2012/11/01 10:49:11 landry Exp $
+
+REGRESS_TARGETS = follow-renames follow-overwrite-by-file follow-overwrite-data follow-removed-recreated follow-newsyslog
+REGRESS_ROOT_TARGETS = follow-newsyslog
+
+.for t in ${REGRESS_ROOT_TARGETS}
+${t}:
+ ${SUDO} sh ${.CURDIR}/${t}.sh
+.endfor
+
+.for t in ${REGRESS_TARGETS}
+${t}:
+ sh ${.CURDIR}/${t}.sh
+.endfor
+
+.include <bsd.regress.mk>
diff --git a/regress/usr.bin/tail/follow-newsyslog.sh b/regress/usr.bin/tail/follow-newsyslog.sh
new file mode 100644
index 00000000000..8926bd30c6a
--- /dev/null
+++ b/regress/usr.bin/tail/follow-newsyslog.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# test if tail follows a file rotated by newsyslog
+
+#set TMPDIR to a nfs-based dir for nfs testing
+local DIR=$(mktemp -d)
+echo DIR=${DIR}
+
+local NAME=${0##*/}
+local OUT=${DIR}/${NAME%%.sh}.out
+local ERR=${DIR}/${NAME%%.sh}.err
+echo bar > ${DIR}/bar
+
+# retry until file appears for nfs
+local RET=1
+while [ ${RET} == 1 ] ; do
+ tail -f ${DIR}/bar 2> ${ERR} > ${OUT} &
+ RET=$?
+ PID=$!
+ sleep 1
+done
+
+echo "${DIR}/bar 644 1 1 *" > ${DIR}/newsyslog.conf
+newsyslog -Ff ${DIR}/newsyslog.conf
+echo 'bar' >> ${DIR}/bar
+sleep 1
+echo "${DIR}/bar 644 0 1 *" > ${DIR}/newsyslog.conf
+newsyslog -Ff ${DIR}/newsyslog.conf
+echo 'bar' >> ${DIR}/bar
+
+# hey nfs !
+sleep 5
+kill ${PID}
+# no diff this time, output too complex
+[ $(grep -c -e '^bar$' ${OUT}) -eq 3 ] || exit 1
+[ $(grep -c -e 'newsyslog\[.*\]: logfile turned over' ${OUT}) -eq 4 ] || exit 2
+tail -1 ${OUT} | grep -q -e '^bar$' || exit 3
+head -1 ${OUT} | grep -q -e '^bar$' || exit 4
+
+#[ $(grep -c "tail: ${DIR}/bar has been truncated, resetting." ${ERR}) -eq 2 ] || exit $?
+[ $(grep -c "tail: ${DIR}/bar has been replaced, reopening." ${ERR}) -eq 2 ] || exit 5
+
+# cleanup if okay
+rm -Rf ${DIR}
diff --git a/regress/usr.bin/tail/follow-overwrite-by-file.out b/regress/usr.bin/tail/follow-overwrite-by-file.out
new file mode 100644
index 00000000000..4b8a05d0f98
--- /dev/null
+++ b/regress/usr.bin/tail/follow-overwrite-by-file.out
@@ -0,0 +1,3 @@
+bar
+bar2
+bar
diff --git a/regress/usr.bin/tail/follow-overwrite-by-file.sh b/regress/usr.bin/tail/follow-overwrite-by-file.sh
new file mode 100644
index 00000000000..180190fc669
--- /dev/null
+++ b/regress/usr.bin/tail/follow-overwrite-by-file.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# test if tail follows a file overwritten by another new file
+
+#set TMPDIR to a nfs-based dir for nfs testing
+local DIR=$(mktemp -d)
+echo DIR=${DIR}
+
+local NAME=${0##*/}
+local OUT=${DIR}/${NAME%%.sh}.out
+local ERR=${DIR}/${NAME%%.sh}.err
+echo bar > ${DIR}/bar
+
+# retry until file appears for nfs
+local RET=1
+while [ ${RET} == 1 ] ; do
+ tail -f ${DIR}/bar 2> ${ERR} > ${OUT} &
+ RET=$?
+ PID=$!
+ sleep 1
+done
+
+echo 'bar2' >> ${DIR}/bar2
+mv ${DIR}/bar2 ${DIR}/bar
+echo 'bar' >> ${DIR}/bar
+
+# hey nfs !
+sleep 5
+kill ${PID}
+diff -u ${OUT} ${0%%.sh}.out || exit 1
+grep -q "tail: ${DIR}/bar has been replaced, reopening." ${ERR} || exit 2
+
+# cleanup if okay
+rm -Rf ${DIR}
diff --git a/regress/usr.bin/tail/follow-overwrite-data.out b/regress/usr.bin/tail/follow-overwrite-data.out
new file mode 100644
index 00000000000..4122e9af95a
--- /dev/null
+++ b/regress/usr.bin/tail/follow-overwrite-data.out
@@ -0,0 +1,4 @@
+bar
+ba
+baar
+bar
diff --git a/regress/usr.bin/tail/follow-overwrite-data.sh b/regress/usr.bin/tail/follow-overwrite-data.sh
new file mode 100644
index 00000000000..356f0f39cea
--- /dev/null
+++ b/regress/usr.bin/tail/follow-overwrite-data.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# test if tail follows a file overwritten by data
+
+#set TMPDIR to a nfs-based dir for nfs testing
+local DIR=$(mktemp -d)
+echo DIR=${DIR}
+
+local NAME=${0##*/}
+local OUT=${DIR}/${NAME%%.sh}.out
+local ERR=${DIR}/${NAME%%.sh}.err
+echo bar > ${DIR}/bar
+
+# retry until file appears for nfs
+local RET=1
+while [ ${RET} == 1 ] ; do
+ tail -f ${DIR}/bar 2> ${ERR} > ${OUT} &
+ RET=$?
+ PID=$!
+ sleep 1
+done
+
+# smaller data
+echo 'ba' > ${DIR}/bar
+sleep 1
+# bigger data with delay
+echo 'baar' > ${DIR}/bar
+# smaller data without delay
+echo 'bar' > ${DIR}/bar
+
+# hey nfs !
+sleep 5
+kill ${PID}
+diff -u ${OUT} ${0%%.sh}.out || exit 1
+[ $(grep -c "tail: ${DIR}/bar has been truncated, resetting." ${ERR}) -eq 3 ] || exit 2
+
+# cleanup if okay
+rm -Rf ${DIR}
diff --git a/regress/usr.bin/tail/follow-removed-recreated.out b/regress/usr.bin/tail/follow-removed-recreated.out
new file mode 100644
index 00000000000..4b8a05d0f98
--- /dev/null
+++ b/regress/usr.bin/tail/follow-removed-recreated.out
@@ -0,0 +1,3 @@
+bar
+bar2
+bar
diff --git a/regress/usr.bin/tail/follow-removed-recreated.sh b/regress/usr.bin/tail/follow-removed-recreated.sh
new file mode 100644
index 00000000000..3317006d31f
--- /dev/null
+++ b/regress/usr.bin/tail/follow-removed-recreated.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# test if tail follows a file removed then recreated later
+
+#set TMPDIR to a nfs-based dir for nfs testing
+local DIR=$(mktemp -d)
+echo DIR=${DIR}
+
+local NAME=${0##*/}
+local OUT=${DIR}/${NAME%%.sh}.out
+local ERR=${DIR}/${NAME%%.sh}.err
+echo bar > ${DIR}/bar
+
+# retry until file appears for nfs
+local RET=1
+while [ ${RET} == 1 ] ; do
+ tail -f ${DIR}/bar 2> ${ERR} > ${OUT} &
+ RET=$?
+ PID=$!
+ sleep 1
+done
+
+# remove
+rm -f ${DIR}/bar
+echo 'bar2' > ${DIR}/bar2
+sleep 1
+mv ${DIR}/bar2 ${DIR}/bar
+echo 'bar' >> ${DIR}/bar
+
+# hey nfs !
+sleep 5
+kill ${PID}
+diff -u ${OUT} ${0%%.sh}.out || exit 1
+grep -q "tail: ${DIR}/bar has been replaced, reopening." ${ERR} || exit 2
+
+# cleanup if okay
+rm -Rf ${DIR}
diff --git a/regress/usr.bin/tail/follow-renames.out b/regress/usr.bin/tail/follow-renames.out
new file mode 100644
index 00000000000..4b8a05d0f98
--- /dev/null
+++ b/regress/usr.bin/tail/follow-renames.out
@@ -0,0 +1,3 @@
+bar
+bar2
+bar
diff --git a/regress/usr.bin/tail/follow-renames.sh b/regress/usr.bin/tail/follow-renames.sh
new file mode 100644
index 00000000000..efa6121acf9
--- /dev/null
+++ b/regress/usr.bin/tail/follow-renames.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# test if tail follows a file descriptor across renames
+
+#set TMPDIR to a nfs-based dir for nfs testing
+local DIR=$(mktemp -d)
+echo DIR=${DIR}
+
+local NAME=${0##*/}
+local OUT=${DIR}/${NAME%%.sh}.out
+echo bar > ${DIR}/bar
+
+# retry until file appears for nfs
+local RET=1
+while [ ${RET} == 1 ] ; do
+ tail -f ${DIR}/bar > ${OUT} &
+ RET=$?
+ PID=$!
+ sleep 1
+done
+
+mv ${DIR}/bar ${DIR}/bar2
+echo 'bar2' >> ${DIR}/bar2
+mv ${DIR}/bar2 ${DIR}/bar
+echo 'bar' >> ${DIR}/bar
+
+# hey nfs !
+sleep 5
+kill ${PID}
+diff -u ${OUT} ${0%%.sh}.out || exit 1
+
+# cleanup if okay
+rm -Rf ${DIR}