[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tlsdate/master] Add integration testing.



commit 234454e5faadda2094e7e454563bcd538984b403
Author: elly <elly@xxxxxxxxxxxxxx>
Date:   Mon Jul 8 10:21:15 2013 -0400

    Add integration testing.
    
    These new integration tests mostly focus on tlsdated's subprocess code.
    
    Signed-off-by: Elly Fong-Jones <elly@xxxxxxxxxxxxxx>
---
 run-tests                      |   40 ++++++++++++++++++++++++++++++++++++++++
 test.conf                      |    2 ++
 tests/README                   |    1 +
 tests/common.sh                |   32 ++++++++++++++++++++++++++++++++
 tests/run-idle/output          |    1 +
 tests/run-idle/runs            |    1 +
 tests/run-idle/setup           |    4 ++++
 tests/run-idle/subproc.sh      |    6 ++++++
 tests/run-idle/teardown        |    4 ++++
 tests/run-idle/test.conf       |    2 ++
 tests/run-once/output          |    1 +
 tests/run-once/run-error       |    1 +
 tests/run-once/subproc.sh      |    5 +++++
 tests/run-routeup/input        |    1 +
 tests/run-routeup/output       |    1 +
 tests/run-routeup/runs         |    1 +
 tests/run-routeup/setup        |    4 ++++
 tests/run-routeup/subproc.sh   |    6 ++++++
 tests/run-routeup/teardown     |    4 ++++
 tests/subproc-retry/input      |    1 +
 tests/subproc-retry/output     |    3 +++
 tests/subproc-retry/runs       |    1 +
 tests/subproc-retry/setup      |    4 ++++
 tests/subproc-retry/subproc.sh |   10 ++++++++++
 tests/subproc-retry/teardown   |    4 ++++
 tests/wait-idle/subproc.sh     |    7 +++++++
 26 files changed, 147 insertions(+)

diff --git a/run-tests b/run-tests
new file mode 100755
index 0000000..693fa59
--- /dev/null
+++ b/run-tests
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+run_test() {
+	[ -x "$1"/setup ] && "$1"/setup
+	if [ -r "$1"/tlsdated-flags ]; then
+		flags=$(cat "$1"/tlsdated-flags | sed "s/@TESTDIR@/$1/g")
+	elif [ -r "$1"/test.conf ]; then
+		flags="-w -p -r -l -s -f $1/test.conf"
+	else
+		flags="-w -p -r -l -s -f test.conf"
+	fi
+	# flags are deliberately unquoted here so that they'll be interpolated
+	timeout 5 src/tlsdated $flags -- "$1"/subproc.sh <"$1"/input >"$1"/run-output \
+                     2>"$1"/run-err
+	[ -x "$1"/teardown ] && "$1"/teardown
+}
+
+test_passed() {
+	diff "$t"/output "$t"/run-output >/dev/null
+}
+
+total=0
+passed=0
+
+for t in tests/*; do
+	[ ! -d "$t" ] && continue
+	name="$(basename "$t")"
+	echo -n "$name: "
+	run_test "$t"
+	if test_passed "$t"; then
+		echo "ok"
+		passed=$((passed + 1))
+	else
+		echo "failed"
+	fi
+	total=$((total + 1))
+done
+echo "Passed: $passed/$total"
+[ $passed != $total ]
+exit $?
diff --git a/test.conf b/test.conf
new file mode 100644
index 0000000..96827ef
--- /dev/null
+++ b/test.conf
@@ -0,0 +1,2 @@
+min-steady-state-interval 0
+wait-between-tries 1
diff --git a/tests/README b/tests/README
new file mode 100644
index 0000000..e0c0e00
--- /dev/null
+++ b/tests/README
@@ -0,0 +1 @@
+Integration tests for tlsdate/tlsdated.
diff --git a/tests/common.sh b/tests/common.sh
new file mode 100644
index 0000000..96ba238
--- /dev/null
+++ b/tests/common.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+kill_tlsdated() {
+	kill -9 $PPID
+}
+
+passed() {
+	kill_tlsdated
+	echo "ok"
+}
+
+failed() {
+	kill_tlsdated
+	echo "failed"
+}
+
+mydir() {
+	echo "$(dirname "$0")"
+}
+
+counter() {
+	cat "$(mydir)"/"$1"
+}
+
+inc_counter() {
+	c=$(counter "$1")
+	echo $((c + 1)) >"$(mydir)"/"$1"
+}
+
+reset_counter() {
+	echo 0 > "$(mydir)"/"$1"
+}
diff --git a/tests/run-idle/input b/tests/run-idle/input
new file mode 100644
index 0000000..e69de29
diff --git a/tests/run-idle/output b/tests/run-idle/output
new file mode 100644
index 0000000..9766475
--- /dev/null
+++ b/tests/run-idle/output
@@ -0,0 +1 @@
+ok
diff --git a/tests/run-idle/runs b/tests/run-idle/runs
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/tests/run-idle/runs
@@ -0,0 +1 @@
+2
diff --git a/tests/run-idle/setup b/tests/run-idle/setup
new file mode 100755
index 0000000..c4afd68
--- /dev/null
+++ b/tests/run-idle/setup
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/run-idle/subproc.sh b/tests/run-idle/subproc.sh
new file mode 100755
index 0000000..649a18e
--- /dev/null
+++ b/tests/run-idle/subproc.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+. "$(dirname $0)"/../common.sh
+
+inc_counter "runs"
+c=$(counter "runs")
+[ $c -eq 2 ] && passed
diff --git a/tests/run-idle/teardown b/tests/run-idle/teardown
new file mode 100644
index 0000000..c4afd68
--- /dev/null
+++ b/tests/run-idle/teardown
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/run-idle/test.conf b/tests/run-idle/test.conf
new file mode 100644
index 0000000..713e8f7
--- /dev/null
+++ b/tests/run-idle/test.conf
@@ -0,0 +1,2 @@
+min-steady-state-interval 0
+steady-state-interval 2
diff --git a/tests/run-once/input b/tests/run-once/input
new file mode 100644
index 0000000..e69de29
diff --git a/tests/run-once/output b/tests/run-once/output
new file mode 100644
index 0000000..9766475
--- /dev/null
+++ b/tests/run-once/output
@@ -0,0 +1 @@
+ok
diff --git a/tests/run-once/run-error b/tests/run-once/run-error
new file mode 100644
index 0000000..f84e1cf
--- /dev/null
+++ b/tests/run-once/run-error
@@ -0,0 +1 @@
+Killed
diff --git a/tests/run-once/subproc.sh b/tests/run-once/subproc.sh
new file mode 100755
index 0000000..7ccb759
--- /dev/null
+++ b/tests/run-once/subproc.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+. "$(dirname $0)"/../common.sh
+
+echo "ok"
+kill_tlsdated
diff --git a/tests/run-routeup/input b/tests/run-routeup/input
new file mode 100644
index 0000000..4ae8ef0
--- /dev/null
+++ b/tests/run-routeup/input
@@ -0,0 +1 @@
+u
diff --git a/tests/run-routeup/output b/tests/run-routeup/output
new file mode 100644
index 0000000..9766475
--- /dev/null
+++ b/tests/run-routeup/output
@@ -0,0 +1 @@
+ok
diff --git a/tests/run-routeup/runs b/tests/run-routeup/runs
new file mode 100644
index 0000000..0cfbf08
--- /dev/null
+++ b/tests/run-routeup/runs
@@ -0,0 +1 @@
+2
diff --git a/tests/run-routeup/setup b/tests/run-routeup/setup
new file mode 100755
index 0000000..c4afd68
--- /dev/null
+++ b/tests/run-routeup/setup
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/run-routeup/subproc.sh b/tests/run-routeup/subproc.sh
new file mode 100755
index 0000000..649a18e
--- /dev/null
+++ b/tests/run-routeup/subproc.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+. "$(dirname $0)"/../common.sh
+
+inc_counter "runs"
+c=$(counter "runs")
+[ $c -eq 2 ] && passed
diff --git a/tests/run-routeup/teardown b/tests/run-routeup/teardown
new file mode 100644
index 0000000..c4afd68
--- /dev/null
+++ b/tests/run-routeup/teardown
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/subproc-retry/input b/tests/subproc-retry/input
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/tests/subproc-retry/input
@@ -0,0 +1 @@
+a
diff --git a/tests/subproc-retry/output b/tests/subproc-retry/output
new file mode 100644
index 0000000..0dae225
--- /dev/null
+++ b/tests/subproc-retry/output
@@ -0,0 +1,3 @@
+dying
+dying
+ok
diff --git a/tests/subproc-retry/runs b/tests/subproc-retry/runs
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/tests/subproc-retry/runs
@@ -0,0 +1 @@
+3
diff --git a/tests/subproc-retry/setup b/tests/subproc-retry/setup
new file mode 100755
index 0000000..c4afd68
--- /dev/null
+++ b/tests/subproc-retry/setup
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/subproc-retry/subproc.sh b/tests/subproc-retry/subproc.sh
new file mode 100755
index 0000000..c725aa1
--- /dev/null
+++ b/tests/subproc-retry/subproc.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+. "$(dirname $0)"/../common.sh
+
+inc_counter "runs"
+if [ $(counter "runs") -lt 3 ]; then
+	echo "dying"
+	echo "$$" >> /tmp/pidz
+	exit 1
+fi
+passed
diff --git a/tests/subproc-retry/teardown b/tests/subproc-retry/teardown
new file mode 100644
index 0000000..c4afd68
--- /dev/null
+++ b/tests/subproc-retry/teardown
@@ -0,0 +1,4 @@
+#!/bin/sh
+. "$(dirname "$0")"/../common.sh
+
+reset_counter "runs"
diff --git a/tests/wait-idle/input b/tests/wait-idle/input
new file mode 100644
index 0000000..e69de29
diff --git a/tests/wait-idle/output b/tests/wait-idle/output
new file mode 100644
index 0000000..e69de29
diff --git a/tests/wait-idle/subproc.sh b/tests/wait-idle/subproc.sh
new file mode 100644
index 0000000..21f5871
--- /dev/null
+++ b/tests/wait-idle/subproc.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+. "$(dirname $0)"/../common.sh
+
+inc_counter "runs"
+c=$(counter "runs")
+[ $c -eq 2 ] && failed
+



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits