aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac5
-rw-r--r--doc/pies.texi2
-rw-r--r--src/progman.c2
-rw-r--r--tests/.gitignore6
-rw-r--r--tests/Makefile.am71
-rw-r--r--tests/atlocal.in6
-rw-r--r--tests/control.at55
-rwxr-xr-xtests/mailer7
-rw-r--r--tests/redirect.at60
-rwxr-xr-xtests/respawn63
-rw-r--r--tests/respawn.at52
-rw-r--r--tests/ret-exec.at68
-rw-r--r--tests/ret-notify.at68
-rwxr-xr-xtests/retcode9
-rw-r--r--tests/testsuite.at65
-rw-r--r--tests/version.at28
17 files changed, 566 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 0358e8c..ff6f5db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,3 +18,3 @@ ACLOCAL_AMFLAGS = -I m4 -I am -I grecs/am -I imprimatur
-SUBDIRS=gnu grecs lib ident src imprimatur doc po
+SUBDIRS=gnu grecs lib ident src tests imprimatur doc po
diff --git a/configure.ac b/configure.ac
index 78702b4..6ee1084 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,2 +144,7 @@ IMPRIMATUR_INIT
+# Initialize the test suite.
+AC_CONFIG_TESTDIR(tests)
+AC_CONFIG_FILES([tests/Makefile tests/atlocal])
+AM_MISSING_PROG([AUTOM4TE], [autom4te])
+
AC_CONFIG_FILES([Makefile
diff --git a/doc/pies.texi b/doc/pies.texi
index 15c37e1..0e8af70 100644
--- a/doc/pies.texi
+++ b/doc/pies.texi
@@ -1870,3 +1870,3 @@ The table below lists all available variables and their expansions:
@item program_name @tab Program name of the @command{pies} binary.
-@item package @tab Package name (@samp{Pies}).
+@item package @tab Package name (@samp{GNU Pies}).
@item instance @tab Instance name (@pxref{instances}).
diff --git a/src/progman.c b/src/progman.c
index 5693011..fdb829a 100644
--- a/src/progman.c
+++ b/src/progman.c
@@ -2080,3 +2080,3 @@ notify (const char *tag, int status, struct action *act)
"canonical_program_name", "pies",
- "package", PACKAGE,
+ "package", PACKAGE_NAME,
"version", PACKAGE_VERSION,
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..93f8f46
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,6 @@
+atconfig
+atlocal
+package.m4
+testsuite
+testsuite.dir
+testsuite.log
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..668fe5e
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,71 @@
+# This file is part of GNU Pies.
+# Copyright (C) 2008-2016 Sergey Poznyakoff
+#
+# GNU Pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Pies. If not, see <http://www.gnu.org/licenses/>.
+
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 respawn retcode mailer
+DISTCLEANFILES = atconfig $(check_SCRIPTS)
+MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
+
+## ------------ ##
+## package.m4. ##
+## ------------ ##
+
+$(srcdir)/package.m4: $(top_srcdir)/configure.ac
+ { \
+ echo '# Signature of the current package.'; \
+ echo 'm4_define([AT_PACKAGE_NAME], [@PACKAGE_NAME@])'; \
+ echo 'm4_define([AT_PACKAGE_TARNAME], [@PACKAGE_TARNAME@])'; \
+ echo 'm4_define([AT_PACKAGE_VERSION], [@PACKAGE_VERSION@])'; \
+ echo 'm4_define([AT_PACKAGE_STRING], [@PACKAGE_STRING@])'; \
+ echo 'm4_define([AT_PACKAGE_BUGREPORT], [@PACKAGE_BUGREPORT@])'; \
+ } >$(srcdir)/package.m4
+
+#
+
+## ------------ ##
+## Test suite. ##
+## ------------ ##
+
+TESTSUITE_AT = \
+ testsuite.at\
+ control.at\
+ respawn.at\
+ redirect.at\
+ ret-exec.at\
+ ret-notify.at\
+ version.at
+
+TESTSUITE = $(srcdir)/testsuite
+M4=m4
+
+AUTOTEST = $(AUTOM4TE) --language=autotest
+$(TESTSUITE): package.m4 $(TESTSUITE_AT)
+ $(AM_V_GEN)$(AUTOTEST) -I $(srcdir) testsuite.at -o $@.tmp
+ $(AM_V_at)mv $@.tmp $@
+
+atconfig: $(top_builddir)/config.status
+ cd $(top_builddir) && ./config.status tests/$@
+
+clean-local:
+ @test ! -f $(TESTSUITE) || $(SHELL) $(TESTSUITE) --clean
+
+check-local: atconfig atlocal $(TESTSUITE)
+ @$(SHELL) $(TESTSUITE)
+
+# Run the test suite on the *installed* tree.
+#installcheck-local:
+# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+
+
diff --git a/tests/atlocal.in b/tests/atlocal.in
new file mode 100644
index 0000000..6cb3c43
--- /dev/null
+++ b/tests/atlocal.in
@@ -0,0 +1,6 @@
+# @configure_input@ -*- shell-script -*-
+# Configurable variable values for GNU Pies test suite.
+# Copyright (C) 2016 Sergey Poznyakoff
+
+PATH=@abs_builddir@:@abs_top_builddir@/src:$srcdir:$PATH
+XFAILFILE=$abs_builddir/.badversion
diff --git a/tests/control.at b/tests/control.at
new file mode 100644
index 0000000..95befdf
--- /dev/null
+++ b/tests/control.at
@@ -0,0 +1,55 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Control interface])
+
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+
+pies --config-file control.conf
+
+sleep 1
+if test -f $pidfile; then
+ pid0=`head -1 $pidfile`
+ pid1=`piesctl --url "$ctlsock" id PID|sed 's/^PID: //'`
+ if test "$pid1" = "$pid0"; then
+ if piesctl --url "$ctlsock" shutdown; then
+ sleep 1
+ if test -f $pidfile; then
+ PIES_XFAIL_MSG([pies does not respond to control commands])
+ kill -9 $pid0
+ exit 1
+ else
+ exit 0
+ fi
+ else
+ PIES_XFAIL_MSG([can't send control commands])
+ kill -9 $pid0
+ exit 1
+ fi
+ else
+ PIES_XFAIL_MSG([Control interface non-functional])
+ exit 1
+ fi
+else
+ PIES_XFAIL_MSG([pies failed to start])
+ exit 1
+fi
+],
+[0])
+
+AT_CLEANUP
diff --git a/tests/mailer b/tests/mailer
new file mode 100755
index 0000000..f832ff5
--- /dev/null
+++ b/tests/mailer
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+exec >${1:?}
+shift
+echo $*
+cat -
+
diff --git a/tests/redirect.at b/tests/redirect.at
new file mode 100644
index 0000000..e8d98d8
--- /dev/null
+++ b/tests/redirect.at
@@ -0,0 +1,60 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([stdout redirection])
+
+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 "$abs_srcdir/respawn -tag respawn -append -pid $comp_pid_file";
+ stdout file "$outfile";
+}
+_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 25; then
+ echo >&2 "timed out"
+ break
+ fi
+done
+
+PIES_STOP
+
+cat $outfile
+],
+[0],
+[respawn: start
+respawn: stop
+])
+
+AT_CLEANUP
diff --git a/tests/respawn b/tests/respawn
new file mode 100755
index 0000000..11d59f6
--- /dev/null
+++ b/tests/respawn
@@ -0,0 +1,63 @@
+#! /bin/sh
+
+# usage: respawn [-append] [-stderr FILE] [-stdout FILE] [-sleep TIME]
+# [-pid FILE] [-tag STRING] [-exit CODE]
+
+append=0
+unset name
+time=10
+tag=$0
+code=0
+
+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
+
+echo "$tag: start"
+sleep $time
+echo "$tag: stop"
+exit $code
diff --git a/tests/respawn.at b/tests/respawn.at
new file mode 100644
index 0000000..5b0082c
--- /dev/null
+++ b/tests/respawn.at
@@ -0,0 +1,52 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Respawn components])
+
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+comp_pid_file=$PWD/comp.pid
+cat > pies.conf <<_EOT
+component test {
+ mode respawn;
+ command "$abs_srcdir/respawn -append -pid $comp_pid_file";
+}
+_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 3 ; then
+ break
+ fi
+ fi
+ sleep 1
+ n=$(($n + 1))
+ if test $n -gt 35; then
+ echo >&2 "timed out"
+ break
+ fi
+done
+
+PIES_STOP
+])
+
+AT_CLEANUP
diff --git a/tests/ret-exec.at b/tests/ret-exec.at
new file mode 100644
index 0000000..f674d84
--- /dev/null
+++ b/tests/ret-exec.at
@@ -0,0 +1,68 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Exec on return code])
+AT_KEYWORDS([ret-exec])
+
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+comp_pid_file=$PWD/comp.pid
+report_file=$PWD/report
+cat > pies.conf <<_EOT
+component test {
+ mode respawn;
+ return-code 10 {
+ exec "$abs_srcdir/retcode $report_file";
+ action disable;
+ }
+ command "$abs_srcdir/respawn -sleep 2 -pid $comp_pid_file -exit 10";
+}
+_EOT
+
+>$report_file
+
+pies --config-file control.conf --config-file pies.conf
+
+n=0
+while test ! -s $report_file
+do
+ sleep 1
+ n=$(($n + 1))
+ if test $n -gt 4; then
+ echo >&2 "timed out"
+ break
+ fi
+done
+
+PIES_STOP
+
+if test -f $report_file; then
+ pid=`head $comp_pid_file`
+ sed "s/$pid/PID/" $report_file
+else
+ echo >&2 "no report file"
+fi
+],
+[0],
+[AT_PACKAGE_VERSION
+test
+PID
+10
+No signal
+])
+
+AT_CLEANUP
diff --git a/tests/ret-notify.at b/tests/ret-notify.at
new file mode 100644
index 0000000..2119ed5
--- /dev/null
+++ b/tests/ret-notify.at
@@ -0,0 +1,68 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Notify on return code])
+AT_KEYWORDS([ret-notify])
+
+AT_CHECK([
+PIES_XFAIL_CHECK
+PIES_CONTROL_INIT
+report_file=$PWD/report
+cat > pies.conf <<_EOT
+mailer-program "$abs_srcdir/mailer";
+mailer-command-line "$abs_srcdir/mailer $report_file";
+component test {
+ mode respawn;
+ return-code 10 {
+ notify root;
+ action disable;
+ }
+ command "$abs_srcdir/respawn -sleep 2 -exit 10";
+}
+_EOT
+
+>$report_file
+
+pies --config-file control.conf --config-file pies.conf
+
+n=0
+while test ! -s $report_file
+do
+ sleep 1
+ n=$(($n + 1))
+ if test $n -gt 4; then
+ echo >&2 "timed out"
+ break
+ fi
+done
+sleep 1
+PIES_STOP
+
+if test -f $report_file; then
+ cat $report_file
+else
+ echo >&2 "no report file"
+fi
+],
+[0],
+[root
+From: <>
+X-Agent: pies (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+Subject: Component test exited with code 10.
+
+])
+
+AT_CLEANUP
diff --git a/tests/retcode b/tests/retcode
new file mode 100755
index 0000000..b827ba9
--- /dev/null
+++ b/tests/retcode
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+exec >${1:?}
+
+echo $PIES_VERSION
+echo $PIES_COMPONENT
+echo $PIES_PID
+echo $PIES_STATUS
+echo ${PIES_SIGNAL:-No signal}
diff --git a/tests/testsuite.at b/tests/testsuite.at
new file mode 100644
index 0000000..fda54e0
--- /dev/null
+++ b/tests/testsuite.at
@@ -0,0 +1,65 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+m4_version_prereq([2.69])
+
+m4_define([PIES_SGN],[pies (AT_PACKAGE_NAME) AT_PACKAGE_VERSION])
+
+m4_define([PIES_XFAIL_MSG],[cat >$[]XFAILFILE <<'_EOT'
+==============================================================
+$*
+==============================================================
+_EOT
+])
+
+m4_define([PIES_XFAIL_CHECK],[AT_XFAIL_IF([test -f $[]XFAILFILE])])
+
+m4_define([PIES_CONTROL_INIT],[
+pidfile="$PWD/pies.pid"
+ctlsock="unix://$PWD/pies.ctl";
+cat > control.conf <<_EOT
+pidfile "$pidfile";
+control {
+ socket "$ctlsock";
+}
+_EOT
+])
+
+m4_define([PIES_STOP],[
+piesctl --url "$ctlsock" shutdown
+pies_stop_spinner=0
+while test -f $pidfile
+do
+ sleep 1
+ pies_stop_spinner=$(($pies_stop_spinner + 1))
+ if test $pies_stop_spinner -gt 3; then
+ kill `cat $pidfile`
+ echo >&2 "timed out waiting for shutdown"
+ fi
+done])
+
+AT_INIT
+
+AT_TESTED([pies])
+
+AT_BANNER([Initial])
+m4_include([version.at])
+m4_include([control.at])
+AT_BANNER([Components])
+m4_include([respawn.at])
+m4_include([redirect.at])
+m4_include([ret-exec.at])
+m4_include([ret-notify.at])
diff --git a/tests/version.at b/tests/version.at
new file mode 100644
index 0000000..31debce
--- /dev/null
+++ b/tests/version.at
@@ -0,0 +1,28 @@
+# This file is part of GNU pies testsuite. -*- Autotest -*-
+# Copyright (C) 2016 Sergey Poznyakoff
+#
+# GNU pies is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU pies is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU pies. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([GNU pies version])
+
+AT_CHECK([pies --version | sed '1{s/ *[\[.*\]]//;q}' ],
+ [0],
+ [pies (AT_PACKAGE_NAME) AT_PACKAGE_VERSION
+],
+[],
+[PIES_XFAIL_MSG([WARNING: Not using the proper version, *all* checks dubious...])
+],
+[rm -f $[]XFAILFILE])
+
+AT_CLEANUP

Return to:

Send suggestions and report system problems to the System administrator.