aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-06-02 11:57:42 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-06-02 11:57:42 +0300
commit685600d72b0c300f94c0c69dc0a16c4ebb230a21 (patch)
tree3a3ea6f43a8cdc543118e2cf81d29628dc82f61f
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.
-rw-r--r--src/pies.c10
-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
17 files changed, 265 insertions, 197 deletions
diff --git a/src/pies.c b/src/pies.c
index 39467a2..2387cef 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -928,14 +928,14 @@ _cb_redir (enum grecs_callback_command cmd,
{
grecs_error (locus, 0, _("unknown syslog priority %s"),
value->v.string);
- return 0;
+ return 1;
}
break;
case GRECS_TYPE_ARRAY:
if (assert_grecs_value_type (locus, value->v.arg.v[0],
GRECS_TYPE_STRING))
- return 0;
+ return 1;
if (strtotok (redirtab, value->v.arg.v[0]->v.string, &res))
grecs_error (locus, 0, _("%s: unrecognised redirector type"),
value->v.arg.v[0]->v.string);
@@ -946,11 +946,11 @@ _cb_redir (enum grecs_callback_command cmd,
if (value->v.arg.c != 2)
{
grecs_error (locus, 0, _("wrong number of arguments"));
- return 0;
+ return 1;
}
if (assert_grecs_value_type (locus, value->v.arg.v[1],
GRECS_TYPE_STRING))
- return 0;
+ return 1;
switch (res)
{
@@ -964,7 +964,7 @@ _cb_redir (enum grecs_callback_command cmd,
grecs_error (locus, 0,
_("unknown syslog priority %s"),
value->v.arg.v[1]->v.string);
- return 0;
+ return 1;
}
break;
diff --git a/tests/.gitignore b/tests/.gitignore
index 276645a..459fa44 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,7 +1,9 @@
atconfig
atlocal
envtest
+lines
package.m4
testsuite
testsuite.dir
testsuite.log
+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 = \
aux/respawn\
aux/retcode\
aux/mailer\
- aux/touchfile
+ aux/touchfile\
+ aux/sleepexit\
+ aux/startcheck
EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 $(AUXTOOLS)
DISTCLEANFILES = atconfig $(check_SCRIPTS)
@@ -62,7 +64,7 @@ TESTSUITE_AT = \
TESTSUITE = $(srcdir)/testsuite
M4=m4
-noinst_PROGRAMS = envtest
+noinst_PROGRAMS = envtest to lines
AM_CPPFLAGS = \
-I$(top_srcdir)/lib\
@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 @@
#! /bin/sh
-# usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME]
-# [-pid FILE] [-tag STRING] [-exit CODE]
+# usage: respawn FILE COUNT
-append=0
-unset name
-time=1
-tag=$0
-code=0
+file=${1:?}
+maxcount=${2:?}
-while [ $# -ne 0 ]
-do
- arg=$1
- shift
- case $arg in
- -append)
- append=1;;
- -stderr)
- name=${1:?missing argument for -stderr}
- shift
- if [ $append -eq 1 ]; then
- exec 2>>$name
- append=0
- else
- exec 2>$name
- fi;;
- -stdout)
- name=${1:?missing argument for -stdout}
- shift
- if [ $append -eq 1 ]; then
- exec >>$name
- append=0
- else
- exec >$name
- fi;;
- -sleep)
- time=${1:?missing argument for -sleep}
- shift;;
- -pid)
- name=${1:?missing argument for -pid}
- shift
- if [ $append -eq 1 ]; then
- echo $$ >>$name
- append=0
- else
- echo $$ >$name
- fi;;
- -tag)
- tag=${1:?missing argument for -tag}
- shift;;
- -exit)
- code=${1:?missing argument for -exit}
- shift;;
- *) echo >&2 "$tag: invalid argument: $arg"
- exit 1
- esac
-done
+count=0
-echo "$tag: start"
-sleep $time
-echo "$tag: stop"
-exit $code
+if [ -f $file ]; then
+ count=`cat $file`
+ if test -n "$count" && test $count -ge $maxcount; then
+ exit 1
+ fi
+fi
+
+count=$(($count + 1))
+echo "$count" > $file
+
+exit 0
+
+
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 @@
+#! /bin/sh
+t=${1:?}
+c=${2:?}
+if test -n "$3"; then
+ echo $$ > $3
+fi
+sleep $t
+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 @@
+#!/bin/sh
+
+# usage: startcheck FILE...
+
+for file
+do
+ if [ -f $file ]; then
+ echo "# $file"
+ cat $file
+ else
+ echo >&2 "$0: $file does not exist"
+ exit 1
+ fi
+done
+
+exit 0
+
+
+
+
+
+
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 @@
#!/bin/sh
-dir=${1:?}
-time=${2:?}
-tag=${3:?}
+file=${1:?}
+time=${2:-0}
+tag=${3:-$file}
-touch $dir/$tag
-sleep $time
+echo $tag > $file
+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 {
}
_EOT
-envtest -exec $abs_top_builddir/src/pies --foreground --stderr --config-file control.conf --config-file envtest.conf 2>errlog
+to 3 \
+ envtest -exec \
+ $abs_top_builddir/src/pies --foreground --stderr \
+ --config-file control.conf --config-file envtest.conf 2>errlog
cat log
],
[0],
@@ -63,3 +66,5 @@ PATH="/usr/local/bin:/usr/bin:/bin"
PIES_INSTANCE="pies"
USER="user"
])
+
+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 @@
+#include <stdio.h>
+
+int
+main (int argc, char **argv)
+{
+ char *progname = argv[0];
+ FILE *fp;
+ int c;
+ unsigned count;
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "usage: %s FILE\n", progname);
+ return 1;
+ }
+
+ fp = fopen (argv[1], "r");
+ if (!fp)
+ {
+ perror (argv[1]);
+ return 2;
+ }
+
+ count = 0;
+ while ((c = fgetc (fp)) != EOF)
+ if (c == '\n')
+ count++;
+ fclose (fp);
+ printf ("%u\n", count);
+ return 0;
+}
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 @@
# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
AT_SETUP([stdout redirection])
+AT_KEYWORDS([redirect])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
-comp_pid_file=$PWD/comp.pid
outfile=$PWD/out
cat > pies.conf <<_EOT
component test {
mode respawn;
- command "$auxdir/respawn -tag respawn -append -pid $comp_pid_file";
+ command "echo pass";
stdout file "$outfile";
}
_EOT
@@ -34,8 +34,8 @@ pies --config-file control.conf --config-file pies.conf
n=0
while :
do
- if test -f $comp_pid_file; then
- lines=`wc -l $comp_pid_file | awk '{print $1}'`
+ if test -f $outfile; then
+ lines=`lines $outfile`
if test "$lines" -ge 2 ; then
break
fi
@@ -53,8 +53,8 @@ PIES_STOP
head -2 $outfile
],
[0],
-[respawn: start
-respawn: stop
+[pass
+pass
])
AT_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])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
-comp_pid_file=$PWD/comp.pid
+statefile=$PWD/state
cat > pies.conf <<_EOT
component test {
- mode respawn;
- command "$auxdir/respawn -append -pid $comp_pid_file";
+ mode respawn;
+ command "$auxdir/respawn $statefile 3";
+ chdir $PWD;
+ return-code 1 {
+ action disable;
+ exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
+ }
}
_EOT
-pies --config-file control.conf --config-file pies.conf
-
-n=0
-while :
-do
- if test -f $comp_pid_file; then
- lines=`wc -l $comp_pid_file | awk '{print $1}'`
- if test "$lines" -ge 2 ; then
- break
- fi
- fi
- sleep 1
- n=$(($n + 1))
- if test $n -gt 35; then
- echo >&2 "timed out"
- break
- fi
-done
-
-PIES_STOP
+to 5 \
+ pies --foreground --stderr \
+ --config-file control.conf --config-file pies.conf --debug 1 2>errlog
+cat state
+],
+[0],
+[3
])
AT_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 {
exec "$auxdir/retcode $report_file";
action disable;
}
- command "$auxdir/respawn -sleep 2 -pid $comp_pid_file -exit 10";
+ command "$auxdir/sleepexit 2 10 $comp_pid_file";
}
_EOT
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 {
notify root;
action disable;
}
- command "$auxdir/respawn -sleep 2 -exit 10";
+ command "$auxdir/sleepexit 2 10";
}
_EOT
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])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
+statefile=$PWD/state
outfile=$PWD/respawn.out
cat > pies.conf <<_EOT
component test {
- mode respawn;
- flags shell;
- command "$auxdir/respawn -tag respawn >> $outfile";
+ mode respawn;
+ flags shell;
+ command "if $auxdir/respawn $statefile 3; then echo pass; else exit 1; fi >> $outfile";
+ chdir $PWD;
+ return-code 1 {
+ action disable;
+ exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
+ }
}
_EOT
-pies --config-file control.conf --config-file pies.conf
+set -e
+to 5 \
+ pies --foreground --stderr \
+ --config-file control.conf --config-file pies.conf --debug 1 2>errlog
-n=0
-while :
-do
- if test -f $outfile; then
- lines=`wc -l $outfile | awk '{print $1}'`
- if test "$lines" -ge 2 ; then
- break
- fi
- fi
- sleep 1
- n=$(($n + 1))
- if test $n -gt 35; then
- echo >&2 "timed out"
- break
- fi
-done
-
-PIES_STOP
-head -n2 $outfile
+echo state:
+cat $statefile
+echo log:
+cat $outfile
],
[0],
-[respawn: start
-respawn: stop
+[state:
+3
+log:
+pass
+pass
+pass
])
AT_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])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
-comp_pid_file=$PWD/comp.pid
+
+statefile=$PWD/state
cat > pies.conf <<_EOT
-component s {
- mode shutdown;
- command "$auxdir/touchfile $PWD 0 shutdown";
+component test {
+ mode respawn;
+ command "$auxdir/respawn $statefile 3";
+ chdir $PWD;
+ return-code 1 {
+ action disable;
+ exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
+ }
}
-component test {
- mode respawn;
- command "$auxdir/respawn -append -pid $comp_pid_file";
+component s {
+ mode shutdown;
+ command "$auxdir/touchfile shutdown";
}
_EOT
-pies --config-file control.conf --config-file pies.conf
-
-n=0
-while :
-do
- if test -f $comp_pid_file; then
- break
- fi
- sleep 1
- n=$(($n + 1))
- if test $n -gt 10; then
- echo >&2 "timed out"
- break
- fi
-done
-
-PIES_STOP
-
-test -f shutdown
+set -e
+to 5 \
+ pies --foreground --stderr \
+ --config-file control.conf --config-file pies.conf 2>errlog
+
+cat shutdown
+],
+[0],
+[shutdown
])
AT_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])
AT_CHECK([
PIES_XFAIL_CHECK
PIES_CONTROL_INIT
-comp_pid_file=$PWD/comp.pid
cat > pies.conf <<_EOT
component b1 {
- mode startup;
- command "$auxdir/touchfile $PWD 1 b1";
+ mode startup;
+ command "$auxdir/touchfile b1 1";
}
component b2 {
- mode startup;
- command "$auxdir/touchfile $PWD 2 b2";
+ mode startup;
+ command "$auxdir/touchfile b2 2";
}
component test {
- mode respawn;
- command "$auxdir/respawn -append -pid $comp_pid_file";
+ mode respawn;
+ command "$auxdir/startcheck b1 b2";
+ chdir $PWD;
+ stdout file "log.out";
+ stderr file "log.err";
+ return-code * {
+ action disable;
+ exec "piesctl --url unix:///$PWD/pies.ctl shutdown";
+ }
}
_EOT
-pies --config-file control.conf --config-file pies.conf
+set -e
+to 5 \
+ pies --foreground --stderr \
+ --config-file control.conf --config-file pies.conf 2>errlog
-n=0
-res=
-b1=
-b2=
-while :
-do
- echo "n=$n" >> tracefile
- if test -z "$b1" && test -f b1; then
- res="${res}b1"
- b1=1
- echo "got b1" >> tracefile
- fi
- if test -z "$b2" && test -f b2; then
- res="${res}b2"
- b2=1
- echo "got b2" >> tracefile
- fi
- if test -f $comp_pid_file; then
- echo "got pidfile" >> tracefile
- res="${res}pid"
- break
- fi
- sleep 1
- n=$(($n + 1))
- if test $n -gt 10; then
- echo >&2 "timed out"
- break
- fi
-done
-
-PIES_STOP
-case $res in
-b1b2pid|b2b1pid) echo b1b2pid;;
-*) echo $res
-esac
+cat log.out
+cat log.err >&2
],
[0],
-[b1b2pid
+[# b1
+b1
+# b2
+b2
])
AT_CLEANUP
diff --git a/tests/to.c b/tests/to.c
new file mode 100644
index 0000000..6511a54
--- /dev/null
+++ b/tests/to.c
@@ -0,0 +1,74 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int
+main (int argc, char **argv)
+{
+ char *progname = argv[0];
+ unsigned long n;
+ char *p;
+ pid_t pid, ret;
+ int status;
+
+ if (argc < 3)
+ {
+ fprintf (stderr, "usage: %s TIMEOUT COMMAND ...\n", progname);
+ exit (1);
+ }
+ errno = 0;
+ n = strtoul (argv[1], &p, 10);
+ if (errno || *p || n == 0)
+ {
+ fprintf (stderr, "%s: %s is not a valid timeout\n", progname, argv[1]);
+ exit (1);
+ }
+
+ argc -= 2;
+ argv += 2;
+
+ pid = fork ();
+ if (pid == -1)
+ {
+ perror ("fork");
+ exit (127);
+ }
+
+ if (pid == 0)
+ {
+ execvp (argv[0], argv);
+ perror (argv[0]);
+ exit (127);
+ }
+
+ alarm (n);
+ ret = wait (&status);
+ alarm (0);
+
+ if (ret != pid)
+ {
+ perror ("wait");
+ exit (127);
+ }
+
+ if (WIFEXITED (status))
+ return WEXITSTATUS (status);
+
+ if (WIFSIGNALED (status))
+ fprintf (stderr, "%s: %s terminated on signal %d\n", progname, argv[0],
+ WTERMSIG (status));
+ else if (WIFSTOPPED (status))
+ fprintf (stderr, "%s: %s stopped\n", progname, argv[0]);
+ else
+ fprintf (stderr, "%s: %s exited with unrecognized status %d\n",
+ progname, argv[0], status);
+ return 127;
+}
+
+
+
+
+

Return to:

Send suggestions and report system problems to the System administrator.