summaryrefslogtreecommitdiffabout
path: root/tests
authorSergey Poznyakoff <gray@gnu.org>2019-06-02 08:57:42 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-06-02 08:57:42 (GMT)
commit685600d72b0c300f94c0c69dc0a16c4ebb230a21 (patch) (unidiff)
tree3a3ea6f43a8cdc543118e2cf81d29628dc82f61f /tests
parentcc298a11a131b162f291d6ee27ba1d7598a1b6c4 (diff)
downloadpies-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') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile.am6
-rwxr-xr-xtests/aux/respawn75
-rwxr-xr-xtests/aux/sleepexit8
-rwxr-xr-xtests/aux/startcheck22
-rwxr-xr-xtests/aux/touchfile10
-rw-r--r--tests/env.at7
-rw-r--r--tests/lines.c31
-rw-r--r--tests/redirect.at12
-rw-r--r--tests/respawn.at38
-rw-r--r--tests/ret-exec.at2
-rw-r--r--tests/ret-notify.at2
-rw-r--r--tests/shell.at48
-rw-r--r--tests/shutdown.at48
-rw-r--r--tests/startup.at67
-rw-r--r--tests/to.c74
16 files changed, 260 insertions, 192 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 276645a..459fa44 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,7 +1,9 @@
1atconfig 1atconfig
2atlocal 2atlocal
3envtest 3envtest
4lines
4package.m4 5package.m4
5testsuite 6testsuite
6testsuite.dir 7testsuite.dir
7testsuite.log 8testsuite.log
9to
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
23EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS) 25EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS)
24DISTCLEANFILES = atconfig $(check_SCRIPTS) 26DISTCLEANFILES = atconfig $(check_SCRIPTS)
@@ -62,7 +64,7 @@ TESTSUITE_AT = \
62TESTSUITE = $(srcdir)/testsuite 64TESTSUITE = $(srcdir)/testsuite
63M4=m4 65M4=m4
64 66
65noinst_PROGRAMS = envtest 67noinst_PROGRAMS = envtest to lines
66AM_CPPFLAGS = \ 68AM_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]
5 4
6append=0 5file=${1:?}
7unset name 6maxcount=${2:?}
8time=1
9tag=$0
10code=0
11 7
12while [ $# -ne 0 ] 8count=0
13do
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
57 esac
58done
59 9
60echo "$tag: start" 10if [ -f $file ]; then
61sleep $time 11 count=`cat $file`
62echo "$tag: stop" 12 if test -n "$count" && test $count -ge $maxcount; then
63exit $code 13 exit 1
14 fi
15fi
16
17count=$(($count + 1))
18echo "$count" > $file
19
20exit 0
21
22
diff --git a/tests/aux/sleepexit b/tests/aux/sleepexit
new file mode 100755
index 0000000..25a9a5b
--- a/dev/null
+++ b/tests/aux/sleepexit
@@ -0,0 +1,8 @@
1#! /bin/sh
2t=${1:?}
3c=${2:?}
4if test -n "$3"; then
5 echo $$ > $3
6fi
7sleep $t
8exit $c
diff --git a/tests/aux/startcheck b/tests/aux/startcheck
new file mode 100755
index 0000000..6e84959
--- a/dev/null
+++ b/tests/aux/startcheck
@@ -0,0 +1,22 @@
1#!/bin/sh
2
3# usage: startcheck FILE...
4
5for file
6do
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
14done
15
16exit 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
2dir=${1:?} 2file=${1:?}
3time=${2:?} 3time=${2:-0}
4tag=${3:?} 4tag=${3:-$file}
5 5
6touch $dir/$tag 6echo $tag > $file
7sleep $time 7test $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
23envtest -exec $abs_top_builddir/src/pies --foreground --stderr --config-file control.conf --config-file envtest.conf 2>errlog 23to 3 \
24 envtest -exec \
25 $abs_top_builddir/src/pies --foreground --stderr \
26 --config-file control.conf --config-file envtest.conf 2>errlog
24cat log 27cat log
25], 28],
26[0], 29[0],
@@ -63,3 +66,5 @@ PATH="/usr/local/bin:/usr/bin:/bin"
63PIES_INSTANCE="pies" 66PIES_INSTANCE="pies"
64USER="user" 67USER="user"
65]) 68])
69
70m4_popdef([ENVTEST])
diff --git a/tests/lines.c b/tests/lines.c
new file mode 100644
index 0000000..106491f
--- a/dev/null
+++ b/tests/lines.c
@@ -0,0 +1,31 @@
1#include <stdio.h>
2
3int
4main (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
+++ b/tests/redirect.at
@@ -15,16 +15,16 @@
15# along with GNU pies. If not, see <http://www.gnu.org/licenses/>. 15# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
16 16
17AT_SETUP([stdout redirection]) 17AT_SETUP([stdout redirection])
18AT_KEYWORDS([redirect])
18 19
19AT_CHECK([ 20AT_CHECK([
20PIES_XFAIL_CHECK 21PIES_XFAIL_CHECK
21PIES_CONTROL_INIT 22PIES_CONTROL_INIT
22comp_pid_file=$PWD/comp.pid
23outfile=$PWD/out 23outfile=$PWD/out
24cat > pies.conf <<_EOT 24cat > pies.conf <<_EOT
25component test { 25component test {
26 mode respawn; 26 mode respawn;
27 command "$auxdir/respawn -tag respawn -append -pid $comp_pid_file"; 27 command "echo pass";
28 stdout file "$outfile"; 28 stdout file "$outfile";
29} 29}
30_EOT 30_EOT
@@ -34,8 +34,8 @@ pies --config-file control.conf --config-file pies.conf
34n=0 34n=0
35while : 35while :
36do 36do
37 if test -f $comp_pid_file; then 37 if test -f $outfile; then
38 lines=`wc -l $comp_pid_file | awk '{print $1}'` 38 lines=`lines $outfile`
39 if test "$lines" -ge 2 ; then 39 if test "$lines" -ge 2 ; then
40 break 40 break
41 fi 41 fi
@@ -53,8 +53,8 @@ PIES_STOP
53head -2 $outfile 53head -2 $outfile
54], 54],
55[0], 55[0],
56[respawn: start 56[pass
57respawn: stop 57pass
58]) 58])
59 59
60AT_CLEANUP 60AT_CLEANUP
diff --git a/tests/respawn.at b/tests/respawn.at
index 6b51ca6..0ba60dc 100644
--- a/tests/respawn.at
+++ b/tests/respawn.at
@@ -19,34 +19,26 @@ AT_SETUP([Respawn components])
19AT_CHECK([ 19AT_CHECK([
20PIES_XFAIL_CHECK 20PIES_XFAIL_CHECK
21PIES_CONTROL_INIT 21PIES_CONTROL_INIT
22comp_pid_file=$PWD/comp.pid 22statefile=$PWD/state
23cat > pies.conf <<_EOT 23cat > pies.conf <<_EOT
24component test { 24component test {
25 mode respawn; 25 mode respawn;
26 command "$auxdir/respawn -append -pid $comp_pid_file"; 26 command "$auxdir/respawn $statefile 3";
27 chdir $PWD;
28 return-code 1 {
29 action disable;
30 exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
31 }
27} 32}
28_EOT 33_EOT
29 34
30pies --config-file control.conf --config-file pies.conf 35to 5 \
31 36 pies --foreground --stderr \
32n=0 37 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
33while : 38cat state
34do 39],
35 if test -f $comp_pid_file; then 40[0],
36 lines=`wc -l $comp_pid_file | awk '{print $1}'` 41[3
37 if test "$lines" -ge 2 ; then
38 break
39 fi
40 fi
41 sleep 1
42 n=$(($n + 1))
43 if test $n -gt 35; then
44 echo >&2 "timed out"
45 break
46 fi
47done
48
49PIES_STOP
50]) 42])
51 43
52AT_CLEANUP 44AT_CLEANUP
diff --git a/tests/ret-exec.at b/tests/ret-exec.at
index 0b3d716..6c27779 100644
--- a/tests/ret-exec.at
+++ b/tests/ret-exec.at
@@ -29,7 +29,7 @@ component test {
29 exec "$auxdir/retcode $report_file"; 29 exec "$auxdir/retcode $report_file";
30 action disable; 30 action disable;
31 } 31 }
32 command "$auxdir/respawn -sleep 2 -pid $comp_pid_file -exit 10"; 32 command "$auxdir/sleepexit 2 10 $comp_pid_file";
33} 33}
34_EOT 34_EOT
35 35
diff --git a/tests/ret-notify.at b/tests/ret-notify.at
index a7768aa..5ce1993 100644
--- a/tests/ret-notify.at
+++ b/tests/ret-notify.at
@@ -30,7 +30,7 @@ component test {
30 notify root; 30 notify root;
31 action disable; 31 action disable;
32 } 32 }
33 command "$auxdir/respawn -sleep 2 -exit 10"; 33 command "$auxdir/sleepexit 2 10";
34} 34}
35_EOT 35_EOT
36 36
diff --git a/tests/shell.at b/tests/shell.at
index 2f06f62..e3d104b 100644
--- a/tests/shell.at
+++ b/tests/shell.at
@@ -19,40 +19,38 @@ AT_SETUP([flags shell])
19AT_CHECK([ 19AT_CHECK([
20PIES_XFAIL_CHECK 20PIES_XFAIL_CHECK
21PIES_CONTROL_INIT 21PIES_CONTROL_INIT
22statefile=$PWD/state
22outfile=$PWD/respawn.out 23outfile=$PWD/respawn.out
23cat > pies.conf <<_EOT 24cat > pies.conf <<_EOT
24component test { 25component test {
25 mode respawn; 26 mode respawn;
26 flags shell; 27 flags shell;
27 command "$auxdir/respawn -tag respawn >> $outfile"; 28 command "if $auxdir/respawn $statefile 3; then echo pass; else exit 1; fi >> $outfile";
29 chdir $PWD;
30 return-code 1 {
31 action disable;
32 exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
33 }
28} 34}
29_EOT 35_EOT
30 36
31pies --config-file control.conf --config-file pies.conf 37set -e
38to 5 \
39 pies --foreground --stderr \
40 --config-file control.conf --config-file pies.conf --debug 1 2>errlog
32 41
33n=0 42echo state:
34while : 43cat $statefile
35do 44echo log:
36 if test -f $outfile; then 45cat $outfile
37 lines=`wc -l $outfile | awk '{print $1}'`
38 if test "$lines" -ge 2 ; then
39 break
40 fi
41 fi
42 sleep 1
43 n=$(($n + 1))
44 if test $n -gt 35; then
45 echo >&2 "timed out"
46 break
47 fi
48done
49
50PIES_STOP
51head -n2 $outfile
52], 46],
53[0], 47[0],
54[respawn: start 48[state:
55respawn: stop 493
50log:
51pass
52pass
53pass
56]) 54])
57 55
58AT_CLEANUP 56AT_CLEANUP
diff --git a/tests/shutdown.at b/tests/shutdown.at
index 79bec37..1c2a4ef 100644
--- a/tests/shutdown.at
+++ b/tests/shutdown.at
@@ -19,39 +19,35 @@ AT_SETUP([Shutdown components])
19AT_CHECK([ 19AT_CHECK([
20PIES_XFAIL_CHECK 20PIES_XFAIL_CHECK
21PIES_CONTROL_INIT 21PIES_CONTROL_INIT
22comp_pid_file=$PWD/comp.pid 22
23statefile=$PWD/state
23 24
24cat > pies.conf <<_EOT 25cat > pies.conf <<_EOT
25component s { 26component test {
26 mode shutdown; 27 mode respawn;
27 command "$auxdir/touchfile $PWD 0 shutdown"; 28 command "$auxdir/respawn $statefile 3";
29 chdir $PWD;
30 return-code 1 {
31 action disable;
32 exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
33 }
28} 34}
29 35
30component test { 36component s {
31 mode respawn; 37 mode shutdown;
32 command "$auxdir/respawn -append -pid $comp_pid_file"; 38 command "$auxdir/touchfile shutdown";
33} 39}
34_EOT 40_EOT
35 41
36pies --config-file control.conf --config-file pies.conf 42set -e
37 43to 5 \
38n=0 44 pies --foreground --stderr \
39while : 45 --config-file control.conf --config-file pies.conf 2>errlog
40do 46
41 if test -f $comp_pid_file; then 47cat shutdown
42 break 48],
43 fi 49[0],
44 sleep 1 50[shutdown
45 n=$(($n + 1))
46 if test $n -gt 10; then
47 echo >&2 "timed out"
48 break
49 fi
50done
51
52PIES_STOP
53
54test -f shutdown
55]) 51])
56 52
57AT_CLEANUP 53AT_CLEANUP
diff --git a/tests/startup.at b/tests/startup.at
index 440c249..22ad25b 100644
--- a/tests/startup.at
+++ b/tests/startup.at
@@ -19,65 +19,44 @@ AT_SETUP([Startup components])
19AT_CHECK([ 19AT_CHECK([
20PIES_XFAIL_CHECK 20PIES_XFAIL_CHECK
21PIES_CONTROL_INIT 21PIES_CONTROL_INIT
22comp_pid_file=$PWD/comp.pid
23 22
24cat > pies.conf <<_EOT 23cat > pies.conf <<_EOT
25component b1 { 24component b1 {
26 mode startup; 25 mode startup;
27 command "$auxdir/touchfile $PWD 1 b1"; 26 command "$auxdir/touchfile b1 1";
28} 27}
29 28
30component b2 { 29component b2 {
31 mode startup; 30 mode startup;
32 command "$auxdir/touchfile $PWD 2 b2"; 31 command "$auxdir/touchfile b2 2";
33} 32}
34 33
35component test { 34component test {
36 mode respawn; 35 mode respawn;
37 command "$auxdir/respawn -append -pid $comp_pid_file"; 36 command "$auxdir/startcheck b1 b2";
37 chdir $PWD;
38 stdout file "log.out";
39 stderr file "log.err";
40 return-code * {
41 action disable;
42 exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
43 }
38} 44}
39_EOT 45_EOT
40 46
41pies --config-file control.conf --config-file pies.conf 47set -e
48to 5 \
49 pies --foreground --stderr \
50 --config-file control.conf --config-file pies.conf 2>errlog
42 51
43n=0 52cat log.out
44res= 53cat log.err >&2
45b1=
46b2=
47while :
48do
49 echo "n=$n" >> tracefile
50 if test -z "$b1" && test -f b1; then
51 res="${res}b1"
52 b1=1
53 echo "got b1" >> tracefile
54 fi
55 if test -z "$b2" && test -f b2; then
56 res="${res}b2"
57 b2=1
58 echo "got b2" >> tracefile
59 fi
60 if test -f $comp_pid_file; then
61 echo "got pidfile" >> tracefile
62 res="${res}pid"
63 break
64 fi
65 sleep 1
66 n=$(($n + 1))
67 if test $n -gt 10; then
68 echo >&2 "timed out"
69 break
70 fi
71done
72
73PIES_STOP
74case $res in
75b1b2pid|b2b1pid) echo b1b2pid;;
76*) echo $res
77esac
78], 54],
79[0], 55[0],
80[b1b2pid 56[# b1
57b1
58# b2
59b2
81]) 60])
82 61
83AT_CLEANUP 62AT_CLEANUP
diff --git a/tests/to.c b/tests/to.c
new file mode 100644
index 0000000..6511a54
--- a/dev/null
+++ b/tests/to.c
@@ -0,0 +1,74 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <errno.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/wait.h>
7
8int
9main (int argc, char **argv)
10{
11 char *progname = argv[0];
12 unsigned long n;
13 char *p;
14 pid_t pid, ret;
15 int status;
16
17 if (argc < 3)
18 {
19 fprintf (stderr, "usage: %s TIMEOUT COMMAND ...\n", progname);
20 exit (1);
21 }
22 errno = 0;
23 n = strtoul (argv[1], &p, 10);
24 if (errno || *p || n == 0)
25 {
26 fprintf (stderr, "%s: %s is not a valid timeout\n", progname, argv[1]);
27 exit (1);
28 }
29
30 argc -= 2;
31 argv += 2;
32
33 pid = fork ();
34 if (pid == -1)
35 {
36 perror ("fork");
37 exit (127);
38 }
39
40 if (pid == 0)
41 {
42 execvp (argv[0], argv);
43 perror (argv[0]);
44 exit (127);
45 }
46
47 alarm (n);
48 ret = wait (&status);
49 alarm (0);
50
51 if (ret != pid)
52 {
53 perror ("wait");
54 exit (127);
55 }
56
57 if (WIFEXITED (status))
58 return WEXITSTATUS (status);
59
60 if (WIFSIGNALED (status))
61 fprintf (stderr, "%s: %s terminated on signal %d\n", progname, argv[0],
62 WTERMSIG (status));
63 else if (WIFSTOPPED (status))
64 fprintf (stderr, "%s: %s stopped\n", progname, argv[0]);
65 else
66 fprintf (stderr, "%s: %s exited with unrecognized status %d\n",
67 progname, argv[0], status);
68 return 127;
69}
70
71
72
73
74

Return to:

Send suggestions and report system problems to the System administrator.