diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 11:57:42 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-06-02 11:57:42 +0300 |
commit | 685600d72b0c300f94c0c69dc0a16c4ebb230a21 (patch) | |
tree | 3a3ea6f43a8cdc543118e2cf81d29628dc82f61f /tests | |
parent | cc298a11a131b162f291d6ee27ba1d7598a1b6c4 (diff) | |
download | pies-685600d72b0c300f94c0c69dc0a16c4ebb230a21.tar.gz pies-685600d72b0c300f94c0c69dc0a16c4ebb230a21.tar.bz2 |
Rewrite the testsuite
The aim is to run pies in foreground if possible. Limit execution time
using external wrapper.
* src/pies.c: (_cb_redir): Consistently return 1 on errors.
* tests/aux/sleepexit: New file.
* tests/aux/startcheck: New file.
* tests/aux/touchfile: Change arguments.
* tests/aux/respawn: Rewrite.
* tests/lines.c: New noinst program.
* tests/to.c: New noinst program.
* tests/.gitignore: Add new programs.
* tests/Makefile.am: Update.
* tests/env.at: Use to to avoid hanging forever.
Add missing popdef.
* tests/redirect.at: Use echo as component program.
* tests/respawn.at: Run pies in foreground. Use to to limit execution
time.
* tests/shell.at: Likewise.
* tests/shutdown.at: Likewise.
* tests/startup.at: Likewise.
* tests/ret-exec.at: Use sleepexit as component program.
* tests/ret-notify.at: Likewise.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 6 | ||||
-rwxr-xr-x | tests/aux/respawn | 77 | ||||
-rwxr-xr-x | tests/aux/sleepexit | 8 | ||||
-rwxr-xr-x | tests/aux/startcheck | 22 | ||||
-rwxr-xr-x | tests/aux/touchfile | 10 | ||||
-rw-r--r-- | tests/env.at | 7 | ||||
-rw-r--r-- | tests/lines.c | 31 | ||||
-rw-r--r-- | tests/redirect.at | 12 | ||||
-rw-r--r-- | tests/respawn.at | 36 | ||||
-rw-r--r-- | tests/ret-exec.at | 2 | ||||
-rw-r--r-- | tests/ret-notify.at | 2 | ||||
-rw-r--r-- | tests/shell.at | 44 | ||||
-rw-r--r-- | tests/shutdown.at | 48 | ||||
-rw-r--r-- | tests/startup.at | 61 | ||||
-rw-r--r-- | tests/to.c | 74 |
16 files changed, 255 insertions, 187 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index 276645a..459fa44 100644 --- a/tests/.gitignore +++ b/tests/.gitignore | |||
@@ -1,7 +1,9 @@ | |||
1 | atconfig | 1 | atconfig |
2 | atlocal | 2 | atlocal |
3 | envtest | 3 | envtest |
4 | lines | ||
4 | package.m4 | 5 | package.m4 |
5 | testsuite | 6 | testsuite |
6 | testsuite.dir | 7 | testsuite.dir |
7 | testsuite.log | 8 | testsuite.log |
9 | to | ||
diff --git a/tests/Makefile.am b/tests/Makefile.am index 419818b..14f5b4f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am | |||
@@ -18,7 +18,9 @@ AUXTOOLS = \ | |||
18 | aux/respawn\ | 18 | aux/respawn\ |
19 | aux/retcode\ | 19 | aux/retcode\ |
20 | aux/mailer\ | 20 | aux/mailer\ |
21 | aux/touchfile | 21 | aux/touchfile\ |
22 | aux/sleepexit\ | ||
23 | aux/startcheck | ||
22 | 24 | ||
23 | EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS) | 25 | EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS) |
24 | DISTCLEANFILES = atconfig $(check_SCRIPTS) | 26 | DISTCLEANFILES = atconfig $(check_SCRIPTS) |
@@ -62,7 +64,7 @@ TESTSUITE_AT = \ | |||
62 | TESTSUITE = $(srcdir)/testsuite | 64 | TESTSUITE = $(srcdir)/testsuite |
63 | M4=m4 | 65 | M4=m4 |
64 | 66 | ||
65 | noinst_PROGRAMS = envtest | 67 | noinst_PROGRAMS = envtest to lines |
66 | AM_CPPFLAGS = \ | 68 | AM_CPPFLAGS = \ |
67 | -I$(top_srcdir)/lib\ | 69 | -I$(top_srcdir)/lib\ |
68 | @GRECS_INCLUDES@ | 70 | @GRECS_INCLUDES@ |
diff --git a/tests/aux/respawn b/tests/aux/respawn index cd9687a..afed85b 100755 --- a/tests/aux/respawn +++ b/tests/aux/respawn | |||
@@ -1,63 +1,22 @@ | |||
1 | #! /bin/sh | 1 | #! /bin/sh |
2 | 2 | ||
3 | # usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME] | 3 | # usage: respawn FILE COUNT |
4 | # [-pid FILE] [-tag STRING] [-exit CODE] | 4 | |
5 | 5 | file=${1:?} | |
6 | append=0 | 6 | maxcount=${2:?} |
7 | unset name | 7 | |
8 | time=1 | 8 | count=0 |
9 | tag=$0 | 9 | |
10 | code=0 | 10 | if [ -f $file ]; then |
11 | 11 | count=`cat $file` | |
12 | while [ $# -ne 0 ] | 12 | if test -n "$count" && test $count -ge $maxcount; then |
13 | do | ||
14 | arg=$1 | ||
15 | shift | ||
16 | case $arg in | ||
17 | -append) | ||
18 | append=1;; | ||
19 | -stderr) | ||
20 | name=${1:?missing argument for -stderr} | ||
21 | shift | ||
22 | if [ $append -eq 1 ]; then | ||
23 | exec 2>>$name | ||
24 | append=0 | ||
25 | else | ||
26 | exec 2>$name | ||
27 | fi;; | ||
28 | -stdout) | ||
29 | name=${1:?missing argument for -stdout} | ||
30 | shift | ||
31 | if [ $append -eq 1 ]; then | ||
32 | exec >>$name | ||
33 | append=0 | ||
34 | else | ||
35 | exec >$name | ||
36 | fi;; | ||
37 | -sleep) | ||
38 | time=${1:?missing argument for -sleep} | ||
39 | shift;; | ||
40 | -pid) | ||
41 | name=${1:?missing argument for -pid} | ||
42 | shift | ||
43 | if [ $append -eq 1 ]; then | ||
44 | echo $$ >>$name | ||
45 | append=0 | ||
46 | else | ||
47 | echo $$ >$name | ||
48 | fi;; | ||
49 | -tag) | ||
50 | tag=${1:?missing argument for -tag} | ||
51 | shift;; | ||
52 | -exit) | ||
53 | code=${1:?missing argument for -exit} | ||
54 | shift;; | ||
55 | *) echo >&2 "$tag: invalid argument: $arg" | ||
56 | exit 1 | 13 | exit 1 |
57 | esac | 14 | fi |
58 | done | 15 | fi |
16 | |||
17 | count=$(($count + 1)) | ||
18 | echo "$count" > $file | ||
19 | |||
20 | exit 0 | ||
21 | |||
59 | 22 | ||
60 | echo "$tag: start" | ||
61 | sleep $time | ||
62 | echo "$tag: stop" | ||
63 | exit $code | ||
diff --git a/tests/aux/sleepexit b/tests/aux/sleepexit new file mode 100755 index 0000000..25a9a5b --- /dev/null +++ b/tests/aux/sleepexit | |||
@@ -0,0 +1,8 @@ | |||
1 | #! /bin/sh | ||
2 | t=${1:?} | ||
3 | c=${2:?} | ||
4 | if test -n "$3"; then | ||
5 | echo $$ > $3 | ||
6 | fi | ||
7 | sleep $t | ||
8 | exit $c | ||
diff --git a/tests/aux/startcheck b/tests/aux/startcheck new file mode 100755 index 0000000..6e84959 --- /dev/null +++ b/tests/aux/startcheck | |||
@@ -0,0 +1,22 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # usage: startcheck FILE... | ||
4 | |||
5 | for file | ||
6 | do | ||
7 | if [ -f $file ]; then | ||
8 | echo "# $file" | ||
9 | cat $file | ||
10 | else | ||
11 | echo >&2 "$0: $file does not exist" | ||
12 | exit 1 | ||
13 | fi | ||
14 | done | ||
15 | |||
16 | exit 0 | ||
17 | |||
18 | |||
19 | |||
20 | |||
21 | |||
22 | |||
diff --git a/tests/aux/touchfile b/tests/aux/touchfile index b9d92a3..a3a2668 100755 --- a/tests/aux/touchfile +++ b/tests/aux/touchfile | |||
@@ -1,7 +1,7 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | dir=${1:?} | 2 | file=${1:?} |
3 | time=${2:?} | 3 | time=${2:-0} |
4 | tag=${3:?} | 4 | tag=${3:-$file} |
5 | 5 | ||
6 | touch $dir/$tag | 6 | echo $tag > $file |
7 | sleep $time | 7 | test $time -ne 0 && sleep $time |
diff --git a/tests/env.at b/tests/env.at index 26fe866..c293c65 100644 --- a/tests/env.at +++ b/tests/env.at | |||
@@ -20,7 +20,10 @@ component envtest { | |||
20 | } | 20 | } |
21 | _EOT | 21 | _EOT |
22 | 22 | ||
23 | envtest -exec $abs_top_builddir/src/pies --foreground --stderr --config-file control.conf --config-file envtest.conf 2>errlog | 23 | to 3 \ |
24 | envtest -exec \ | ||
25 | $abs_top_builddir/src/pies --foreground --stderr \ | ||
26 | --config-file control.conf --config-file envtest.conf 2>errlog | ||
24 | cat log | 27 | cat log |
25 | ], | 28 | ], |
26 | [0], | 29 | [0], |
@@ -63,3 +66,5 @@ PATH="/usr/local/bin:/usr/bin:/bin" | |||
63 | PIES_INSTANCE="pies" | 66 | PIES_INSTANCE="pies" |
64 | USER="user" | 67 | USER="user" |
65 | ]) | 68 | ]) |
69 | |||
70 | m4_popdef([ENVTEST]) | ||
diff --git a/tests/lines.c b/tests/lines.c new file mode 100644 index 0000000..106491f --- /dev/null +++ b/tests/lines.c | |||
@@ -0,0 +1,31 @@ | |||
1 | #include <stdio.h> | ||
2 | |||
3 | int | ||
4 | main (int argc, char **argv) | ||
5 | { | ||
6 | char *progname = argv[0]; | ||
7 | FILE *fp; | ||
8 | int c; | ||
9 | unsigned count; | ||
10 | |||
11 | if (argc != 2) | ||
12 | { | ||
13 | fprintf (stderr, "usage: %s FILE\n", progname); | ||
14 | return 1; | ||
15 | } | ||
16 | |||
17 | fp = fopen (argv[1], "r"); | ||
18 | if (!fp) | ||
19 | { | ||
20 | perror (argv[1]); | ||
21 | return 2; | ||
22 | } | ||
23 | |||
24 | count = 0; | ||
25 | while ((c = fgetc (fp)) != EOF) | ||
26 | if (c == '\n') | ||
27 | count++; | ||
28 | fclose (fp); | ||
29 | printf ("%u\n", count); | ||
30 | return 0; | ||
31 | } | ||
diff --git a/tests/redirect.at b/tests/redirect.at index 7860736..12fb20f 100644 --- a/tests/redirect.at |