diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/README | 1 | ||||
-rw-r--r-- | tests/common.sh | 56 | ||||
-rw-r--r-- | tests/run-idle/output | 1 | ||||
-rwxr-xr-x | tests/run-idle/setup | 5 | ||||
-rwxr-xr-x | tests/run-idle/subproc.sh | 12 | ||||
-rw-r--r-- | tests/run-idle/teardown | 15 | ||||
-rw-r--r-- | tests/run-idle/test.conf | 4 | ||||
-rw-r--r-- | tests/run-once/output | 1 | ||||
-rw-r--r-- | tests/run-once/run-error | 1 | ||||
-rwxr-xr-x | tests/run-once/subproc.sh | 3 | ||||
-rwxr-xr-x | tests/run-routeup/input.sh | 8 | ||||
-rw-r--r-- | tests/run-routeup/output | 1 | ||||
-rwxr-xr-x | tests/run-routeup/setup | 4 | ||||
-rwxr-xr-x | tests/run-routeup/subproc.sh | 9 | ||||
-rw-r--r-- | tests/run-routeup/teardown | 4 | ||||
-rw-r--r-- | tests/run-routeup/test.conf | 4 | ||||
-rw-r--r-- | tests/subproc-retry/output | 3 | ||||
-rwxr-xr-x | tests/subproc-retry/setup | 4 | ||||
-rwxr-xr-x | tests/subproc-retry/subproc.sh | 9 | ||||
-rw-r--r-- | tests/subproc-retry/teardown | 4 | ||||
-rw-r--r-- | tests/wait-idle/output | 0 | ||||
-rwxr-xr-x | tests/wait-idle/setup | 5 | ||||
-rwxr-xr-x | tests/wait-idle/subproc.sh | 13 |
23 files changed, 167 insertions, 0 deletions
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..9e488db --- /dev/null +++ b/tests/common.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +kill_tlsdated() { + kill -TERM $PPID +} + +result_passed() { + res=$(cat "$(mydir)"/"result") + if [ $res = "ok" ]; then + return 0 + fi + return 1 +} + +check_err() { + grep -q "$1" "$(mydir)"/"run-err" +} + +passed_if_timed_out() { + echo "ok" > "$(mydir)"/"result" +} + +passed() { + echo "ok" > "$(mydir)"/"result" + kill_tlsdated +} + +failed() { + echo "failed" > "$(mydir)"/"result" + kill_tlsdated +} + +mydir() { + echo "$(dirname "$0")" +} + +counter() { + cat "$(mydir)"/"$1" +} + +inc_counter() { + c=$(counter "$1") + echo $((c + 1)) >"$(mydir)"/"$1" +} + +reset_counter() { + echo 0 > "$(mydir)"/"$1" +} + +reset_time() { + date +%s > "$(mydir)"/"$1" +} + +emit_time() { + src/test/emit `cat "$(mydir)"/"$1"` +} 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/setup b/tests/run-idle/setup new file mode 100755 index 0000000..bd12ed6 --- /dev/null +++ b/tests/run-idle/setup @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname "$0")"/../common.sh + +reset_time "timestamp" +reset_counter "runs" diff --git a/tests/run-idle/subproc.sh b/tests/run-idle/subproc.sh new file mode 100755 index 0000000..f01a814 --- /dev/null +++ b/tests/run-idle/subproc.sh @@ -0,0 +1,12 @@ +#!/bin/sh +. "$(dirname $0)"/../common.sh + +inc_counter "runs" +c=$(counter "runs") +[ $c -eq 3 ] && passed + +# Bump it three seconds to overcome the steady state interval. +inc_counter "timestamp" +inc_counter "timestamp" +inc_counter "timestamp" +emit_time "timestamp" diff --git a/tests/run-idle/teardown b/tests/run-idle/teardown new file mode 100644 index 0000000..b153b10 --- /dev/null +++ b/tests/run-idle/teardown @@ -0,0 +1,15 @@ +#!/bin/sh +. "$(dirname "$0")"/../common.sh + +reset_counter "runs" +# If the run count passed, then make sure the +# time was being set and it wasn't error calls. +if result_passed; then + if check_err 'time set from the network'; then + passed + else + failed + fi +fi + + diff --git a/tests/run-idle/test.conf b/tests/run-idle/test.conf new file mode 100644 index 0000000..c97ac9b --- /dev/null +++ b/tests/run-idle/test.conf @@ -0,0 +1,4 @@ +min-steady-state-interval 0 +steady-state-interval 1 +subprocess-tries 1 +subprocess-wait-between-tries 2 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..5bf92e1 --- /dev/null +++ b/tests/run-once/subproc.sh @@ -0,0 +1,3 @@ +#!/bin/sh +. "$(dirname $0)"/../common.sh +passed diff --git a/tests/run-routeup/input.sh b/tests/run-routeup/input.sh new file mode 100755 index 0000000..fd33215 --- /dev/null +++ b/tests/run-routeup/input.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Wake up from stdin twice. +c=0 +while [ $c -lt 120 ]; do + echo + sleep 0.2 + c=$((c+1)) +done 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/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..18bb5c9 --- /dev/null +++ b/tests/run-routeup/subproc.sh @@ -0,0 +1,9 @@ +#!/bin/sh +. "$(dirname $0)"/../common.sh + +inc_counter "runs" +c=$(counter "runs") +[ $c -eq 2 ] && passed + +# Always emit a bogus time so that stdin retriggers. +src/test/emit "0" 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/run-routeup/test.conf b/tests/run-routeup/test.conf new file mode 100644 index 0000000..14a7747 --- /dev/null +++ b/tests/run-routeup/test.conf @@ -0,0 +1,4 @@ +# Don't let steady state trigger the next call. +min-steady-state-interval 10 +steady-state-interval 30 +wait-between-tries 1 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/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..b3fded7 --- /dev/null +++ b/tests/subproc-retry/subproc.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Die on the first three attempts. +. "$(dirname $0)"/../common.sh + +inc_counter "runs" +if [ $(counter "runs") -lt 3 ]; then + 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/output b/tests/wait-idle/output new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/wait-idle/output diff --git a/tests/wait-idle/setup b/tests/wait-idle/setup new file mode 100755 index 0000000..bd12ed6 --- /dev/null +++ b/tests/wait-idle/setup @@ -0,0 +1,5 @@ +#!/bin/sh +. "$(dirname "$0")"/../common.sh + +reset_time "timestamp" +reset_counter "runs" diff --git a/tests/wait-idle/subproc.sh b/tests/wait-idle/subproc.sh new file mode 100755 index 0000000..2994a5c --- /dev/null +++ b/tests/wait-idle/subproc.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# Make sure that a longer steady state after a successful run +# doesn't call again too soon. +. "$(dirname $0)"/../common.sh + +emit_time "timestamp" +# This one expects a timeout to end it. +passed_if_timed_out + +inc_counter "runs" +c=$(counter "runs") +[ $c -eq 2 ] && failed + |