diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2014-08-17 18:31:17 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2014-08-17 18:39:23 +0300 |
commit | 1954d41325a0dfe692d0c8346feb855c728a43c9 (patch) | |
tree | 905c1414f3519616d7529025428ff4a284e73500 | |
parent | d2b3be6e927d6585a4e9d9f7dd566763bbb6c539 (diff) | |
download | direvent-1954d41325a0dfe692d0c8346feb855c728a43c9.tar.gz direvent-1954d41325a0dfe692d0c8346feb855c728a43c9.tar.bz2 |
Rewrite testsuite.
Get rid of the kludgy waitpid; use the built-in self-test mode instead.
* src/cmdline.opt: New option --self-test.
* src/direvent.c (self_test_prog,self_test_pid)
(exit_code): New globals.
(self_test): New function.
(main): Call self_test if required.
If stop is set, break the loop immediately.
Return exit_code.
* src/direvent.h (stop,self_test_pid,exit_code): New externs.
* src/environ.c (environ_setup): Always define DIREVENT_SELF_TEST_PID
when in self-test mode.
* src/progman.c (process_cleanup): Special handling for termination of
the self-test script.
(runcmd): Define self_test_pid envvar in self-test mode.
* tests/Makefile.am: Remove waitpid.
* tests/waitfile.c: Removed.
* tests/printname: Send HUP to the self-test PID if sentinel file is created.
* tests/envdump.c (read_pid_and_sig): Restore arg to its pristine state
before exiting.
* tests/testsuite.at (AT_DIREVENT_TEST): New macro.
* tests/attrib.at: Rewrite using AT_DIREVENT_TEST.
* tests/cmdexp.at: Likewise.
* tests/create.at: Likewise.
* tests/createrec.at: Likewise.
* tests/delete.at: Likewise.
* tests/env00.at: Likewise.
* tests/env01.at: Likewise.
* tests/env02.at: Likewise.
* tests/env03.at: Likewise.
* tests/glob01.at: Likewise.
* tests/glob02.at: Likewise.
* tests/re01.at: Likewise.
* tests/re02.at: Likewise.
* tests/re03.at: Likewise.
* tests/re04.at: Likewise.
* tests/re05.at: Likewise.
* tests/write.at: Likewise.
* grecs (untracked content)
-rw-r--r-- | src/cmdline.opt | 6 | ||||
-rw-r--r-- | src/direvent.c | 46 | ||||
-rw-r--r-- | src/direvent.h | 4 | ||||
-rw-r--r-- | src/environ.c | 10 | ||||
-rw-r--r-- | src/progman.c | 63 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/attrib.at | 26 | ||||
-rw-r--r-- | tests/cmdexp.at | 32 | ||||
-rw-r--r-- | tests/create.at | 24 | ||||
-rw-r--r-- | tests/createrec.at | 40 | ||||
-rw-r--r-- | tests/delete.at | 24 | ||||
-rw-r--r-- | tests/env00.at | 30 | ||||
-rw-r--r-- | tests/env01.at | 28 | ||||
-rw-r--r-- | tests/env02.at | 28 | ||||
-rw-r--r-- | tests/env03.at | 28 | ||||
-rw-r--r-- | tests/envdump.c | 4 | ||||
-rw-r--r-- | tests/glob01.at | 25 | ||||
-rw-r--r-- | tests/glob02.at | 25 | ||||
-rwxr-xr-x | tests/printname | 2 | ||||
-rw-r--r-- | tests/re01.at | 25 | ||||
-rw-r--r-- | tests/re02.at | 24 | ||||
-rw-r--r-- | tests/re03.at | 25 | ||||
-rw-r--r-- | tests/re04.at | 25 | ||||
-rw-r--r-- | tests/re05.at | 25 | ||||
-rw-r--r-- | tests/testsuite.at | 23 | ||||
-rw-r--r-- | tests/waitfile.c | 50 | ||||
-rw-r--r-- | tests/write.at | 28 |
27 files changed, 288 insertions, 384 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index 914922a..ecd17ef 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -34,6 +34,12 @@ BEGIN opt_foreground++; END +OPTION(self-test,T,PROG, + [<self-test mode>]) +BEGIN + self_test_prog = optarg; +END + OPTION(pidfile,P,FILE, [<set PID file>]) BEGIN diff --git a/src/direvent.c b/src/direvent.c index accf923..7cdd2c1 100644 --- a/src/direvent.c +++ b/src/direvent.c @@ -22,6 +22,7 @@ #include <grp.h> #include <signal.h> #include <grecs.h> +#include "wordsplit.h" #ifndef SYSCONFDIR # define SYSCONFDIR "/etc" @@ -32,6 +33,7 @@ const char *program_name; /* This program name */ const char *conffile = DEFAULT_CONFFILE; int foreground; /* Remain in the foreground */ +char *self_test_prog; char *tag; /* Syslog tag */ int facility = -1; /* Use this syslog facility for logging. -1 means log to stderr */ @@ -387,6 +389,9 @@ genev_init() int signo = 0; int stop = 0; +pid_t self_test_pid; +int exit_code = 0; + void sigmain(int sig) { @@ -399,6 +404,40 @@ sigmain(int sig) stop = 1; } } +extern char **environ; + +void +self_test() +{ + pid_t pid; + struct wordsplit ws; + + ws.ws_env = (const char **)environ; + if (wordsplit(self_test_prog, &ws, + WRDSF_NOCMD | WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS | + WRDSF_CESCAPES | WRDSF_ENV)) { + diag(LOG_CRIT, "wordsplit: %s", wordsplit_strerror (&ws)); + exit(2); + } + + pid = fork(); + if (pid == (pid_t)-1) { + diag(LOG_CRIT, + "cannot run `%s': fork failed: %s", + self_test_prog, strerror(errno)); + exit(2); + } + + if (pid != 0) { + self_test_pid = pid; + return; + } + + execv(ws.ws_wordv[0], ws.ws_wordv); + + diag(LOG_ERR, "execv: %s: %s", ws.ws_wordv[0], strerror(errno)); + _exit(127); +} #if USE_IFACE == IFACE_INOTIFY @@ -492,8 +531,11 @@ main(int argc, char **argv) signal_setup(sigmain); + if (self_test_prog) + self_test(); + /* Main loop */ - while (sysev_select() == 0 && !stop) { + while (!stop && sysev_select() == 0) { process_timeouts(); process_cleanup(0); } @@ -503,5 +545,5 @@ main(int argc, char **argv) if (pidfile) unlink(pidfile); - return 0; + return exit_code; } diff --git a/src/direvent.h b/src/direvent.h index 94702cf..33fa768 100644 --- a/src/direvent.h +++ b/src/direvent.h @@ -109,6 +109,10 @@ extern char *user; extern unsigned opt_timeout; extern unsigned opt_flags; extern int signo; +extern int stop; + +extern pid_t self_test_pid; +extern int exit_code; void *emalloc(size_t size); diff --git a/src/environ.c b/src/environ.c index 3c65704..5fbd0ac 100644 --- a/src/environ.c +++ b/src/environ.c @@ -141,7 +141,9 @@ environ_setup(char **hint, char **kve) for (i = 0; hint[i]; i++) count++; - + + if (self_test_pid) + count++; /* Allocate new environment. */ new_env = ecalloc(count + 1, sizeof new_env[0]); @@ -203,6 +205,12 @@ environ_setup(char **hint, char **kve) new_env[n++] = p; } } + if (self_test_pid) { + char buf[512]; + snprintf(buf, sizeof buf, "DIREVENT_SELF_TEST_PID=%lu", + (unsigned long)self_test_pid); + new_env[n++] = estrdup(buf);; + } new_env[n] = NULL; if (wsflags & WRDSF_REUSE) diff --git a/src/progman.c b/src/progman.c index cc7d4a9..f32e896 100644 --- a/src/progman.c +++ b/src/progman.c @@ -176,28 +176,45 @@ process_cleanup(int expect_term) while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { sigset_t set; - struct process *p = process_lookup(pid); - sigemptyset(&set); - if (expect_term) - sigaddset(&set, SIGTERM); - if (!p) { - sigaddset(&set, SIGTERM); - sigaddset(&set, SIGKILL); - } - print_status(pid, status, &set); - if (!p) - continue; - if (p->type == PROC_HANDLER) { - if (p->v.redir[REDIR_OUT]) - p->v.redir[REDIR_OUT]->v.master = NULL; - if (p->v.redir[REDIR_ERR]) - p->v.redir[REDIR_ERR]->v.master = NULL; + if (pid == self_test_pid) { + sigaddset(&set, SIGHUP); + print_status(pid, status, &set); + + if (WIFEXITED(status)) + exit_code = WEXITSTATUS(status); + else if (WIFSIGNALED(status)) { + if (WTERMSIG(status) == SIGHUP) + exit_code = 0; + else + exit_code = 2; + } else + exit_code = 2; + stop = 1; + } else { + struct process *p = process_lookup(pid); + + if (expect_term) + sigaddset(&set, SIGTERM); + if (!p) { + sigaddset(&set, SIGTERM); + sigaddset(&set, SIGKILL); + } + print_status(pid, status, &set); + if (!p) + continue; + + if (p->type == PROC_HANDLER) { + if (p->v.redir[REDIR_OUT]) + p->v.redir[REDIR_OUT]->v.master = NULL; + if (p->v.redir[REDIR_ERR]) + p->v.redir[REDIR_ERR]->v.master = NULL; + } + p->pid = 0; + proc_unlink(&proc_list, p); + proc_push(&proc_avail, p); } - p->pid = 0; - proc_unlink(&proc_list, p); - proc_push(&proc_avail, p); } } @@ -351,7 +368,7 @@ open_redirector(const char *tag, int prio, struct process **return_proc) static void runcmd(const char *cmd, char **envhint, event_mask *event, const char *file) { - char *kve[11]; + char *kve[13]; char *p,*q; char buf[1024]; int i = 0, j; @@ -363,6 +380,12 @@ runcmd(const char *cmd, char **envhint, event_mask *event, const char *file) snprintf(buf, sizeof buf, "%d", event->sys_mask); kve[i++] = "sysev_code"; kve[i++] = estrdup(buf); + + if (self_test_pid) { + snprintf(buf, sizeof buf, "%lu", (unsigned long)self_test_pid); + kve[i++] = "self_test_pid"; + kve[i++] = estrdup(buf); + } q = buf; for (p = trans_tokfirst(sysev_transtab, event->sys_mask, &j); p; diff --git a/tests/Makefile.am b/tests/Makefile.am index 37f471e..d89dfcb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -76,4 +76,4 @@ check-local: atconfig atlocal $(TESTSUITE) @$(SHELL) $(TESTSUITE) -noinst_PROGRAMS=envdump waitfile +noinst_PROGRAMS=envdump diff --git a/tests/attrib.at b/tests/attrib.at index c11545a..299055c 100644 --- a/tests/attrib.at +++ b/tests/attrib.at @@ -17,13 +17,7 @@ AT_SETUP([Attrib]) AT_KEYWORDS([attrib]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,21 +26,17 @@ syslog { watcher { path $cwd/dir; event attrib; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - +], +[chmod 644 dir/file], +[outfile=$cwd/dump +mkdir dir > dir/file chmod 600 dir/file - -direvent -lnotice test.conf || exit 1 - -chmod 644 dir/file - -waitfile $outfile 6 || exit 2 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/cmdexp.at b/tests/cmdexp.at index 1d80c46..e577367 100644 --- a/tests/cmdexp.at +++ b/tests/cmdexp.at @@ -17,13 +17,7 @@ AT_SETUP([Command line expansions]) AT_KEYWORDS([cmdexp]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,26 +26,20 @@ syslog { watcher { path $cwd/dir; event write; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile file=\$file event=\$genev_name"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid file=\$file event=\$genev_name"; option (stdout,stderr); } -EOT - +], +[echo "to come to" >> dir/testfile], +[outfile=$cwd/dump +mkdir dir cat > dir/testfile <<EOT now is the time for all men EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -echo "to come to" >> dir/testfile - -waitfile $outfile 6 -res=$? -kill `cat $pidfile` -test $? -ne 0 && exit 1 -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile ], [0], [# Dump of execution environment @@ -63,8 +51,8 @@ argv[[2]]=-i argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_ argv[[4]]=-f argv[[5]]=(CWD)/dump -argv[[6]]=file=testfile -argv[[7]]=event=write +argv[[7]]=file=testfile +argv[[8]]=event=write # Environment DIREVENT_FILE=testfile DIREVENT_GENEV_CODE=2 diff --git a/tests/create.at b/tests/create.at index 3959fcb..ec80804 100644 --- a/tests/create.at +++ b/tests/create.at @@ -17,13 +17,7 @@ AT_SETUP([Create]) AT_KEYWORDS([create create01]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,17 +26,15 @@ syslog { watcher { path $cwd/dir; event create; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/file -waitfile $outfile 6 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[> dir/file], +[outfile=$cwd/dump +mkdir dir +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/createrec.at b/tests/createrec.at index 0304b40..f701e70 100644 --- a/tests/createrec.at +++ b/tests/createrec.at @@ -17,21 +17,7 @@ AT_SETUP([Create recursive]) AT_KEYWORDS([create createrec]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -#sleep 1 -mkdir a -mkdir a/b -mkdir a/b/c -> a/af -> a/af1 -> a/b/bf - -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -43,15 +29,20 @@ watcher { command "$SRCDIR/printname $outfile"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -cp -r a dir -waitfile $outfile 6 -kill `cat $pidfile` - -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile | sort +], +[cp -r a dir +touch dir/sentinel +], +[outfile=$cwd/dump +mkdir dir +mkdir a +mkdir a/b +mkdir a/b/c +> a/af +> a/af1 +> a/b/bf +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile | sort ], [0], [(CWD)/dir/a @@ -60,6 +51,7 @@ sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile | sort (CWD)/dir/a/b (CWD)/dir/a/b/bf (CWD)/dir/a/b/c +(CWD)/dir/sentinel ]) AT_CLEANUP diff --git a/tests/delete.at b/tests/delete.at index 06855cf..1f62dba 100644 --- a/tests/delete.at +++ b/tests/delete.at @@ -17,13 +17,7 @@ AT_SETUP([Delete]) AT_KEYWORDS([delete]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,18 +26,16 @@ syslog { watcher { path $cwd/dir; event delete; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - +], +[rm dir/file], +[outfile=$cwd/dump +mkdir dir > dir/file -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -rm dir/file -waitfile $outfile 6 || exit 2 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/env00.at b/tests/env00.at index ee60a0a..5dbe76e 100644 --- a/tests/env00.at +++ b/tests/env00.at @@ -17,13 +17,7 @@ AT_SETUP([modify]) AT_KEYWORDS([environ env00]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,31 +26,25 @@ syslog { watcher { path $cwd/dir; event write; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_:VAR1=:VAR2=:VAR3=:FILE= -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_:VAR1=:VAR2=:VAR3=:FILE= -f $outfile -k\$self_test_pid"; option (stdout,stderr); environ ("VAR3=qux", "FILE=\$file"); } -EOT - +], +[echo "to come to" >> dir/testfile], +[outfile=$cwd/dump +mkdir dir cat > dir/testfile <<EOT now is the time for all men EOT - VAR1=foo VAR2=bar export VAR1 VAR2 - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -echo "to come to" >> dir/testfile - -waitfile $outfile 6 -res=$? -kill `cat $pidfile` -test $? -ne 0 && exit 1 -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^" $outfile +], +[ +sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^;/^argv\[[[0-9]]\]=-k/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/env01.at b/tests/env01.at index 23acb49..f37958c 100644 --- a/tests/env01.at +++ b/tests/env01.at @@ -17,13 +17,7 @@ AT_SETUP([clear environment]) AT_KEYWORDS([environ env01]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,27 +26,21 @@ syslog { watcher { path $cwd/dir; event write; - command "$TESTDIR/envdump -s -f $outfile"; + command "$TESTDIR/envdump -s -f $outfile -k\$self_test_pid"; option (stdout,stderr); environ -; } -EOT - +], +[echo "to come to" >> dir/testfile], +[outfile=$cwd/dump +mkdir dir cat > dir/testfile <<EOT now is the time for all men EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -echo "to come to" >> dir/testfile - -waitfile $outfile 6 -res=$? -kill `cat $pidfile` -test $? -ne 0 && exit 1 -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/env02.at b/tests/env02.at index 28a0f64..35aff72 100644 --- a/tests/env02.at +++ b/tests/env02.at @@ -17,13 +17,7 @@ AT_SETUP([clear all environment]) AT_KEYWORDS([environ env02]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,27 +26,21 @@ syslog { watcher { path $cwd/dir; event write; - command "$TESTDIR/envdump -s -f $outfile"; + command "$TESTDIR/envdump -s -f $outfile -k\$self_test_pid"; option (stdout,stderr); environ --; } -EOT - +], +[echo "to come to" >> dir/testfile], +[outfile=$cwd/dump +mkdir dir cat > dir/testfile <<EOT now is the time for all men EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -echo "to come to" >> dir/testfile - -waitfile $outfile 6 -res=$? -kill `cat $pidfile` -test $? -ne 0 && exit 1 -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/env03.at b/tests/env03.at index 65c50ca..dfe98ac 100644 --- a/tests/env03.at +++ b/tests/env03.at @@ -17,13 +17,7 @@ AT_SETUP([clear and modify]) AT_KEYWORDS([environ env03]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -32,12 +26,14 @@ syslog { watcher { path $cwd/dir; event write; - command "$TESTDIR/envdump -s -f $outfile"; + command "$TESTDIR/envdump -s -f $outfile -k\$self_test_pid"; option (stdout,stderr); environ (--, VAR1, "VAR2=baz", "FILE=\$file", "EVENT=\$genev_name"); } -EOT - +], +[echo "to come to" >> dir/testfile], +[outfile=$cwd/dump +mkdir dir cat > dir/testfile <<EOT now is the time for all @@ -47,16 +43,8 @@ EOT VAR1=foo VAR2=bar export VAR1 VAR2 - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -echo "to come to" >> dir/testfile - -waitfile $outfile 6 -res=$? -kill `cat $pidfile` -test $? -ne 0 && exit 1 -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^" $outfile +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;s^\(DIREVENT_SYS.*\)=.*^\1=X^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/envdump.c b/tests/envdump.c index ac2d29d..7d8162d 100644 --- a/tests/envdump.c +++ b/tests/envdump.c @@ -165,8 +165,10 @@ read_pid_and_sig(char *arg, pid_t *pid, int *sig) } } - if (p) + if (p) { *sig = strtosig(p); + p[-1] = ':'; + } } int diff --git a/tests/glob01.at b/tests/glob01.at index 8554889..19b4675 100644 --- a/tests/glob01.at +++ b/tests/glob01.at @@ -17,13 +17,7 @@ AT_SETUP([Globbing pattern]) AT_KEYWORDS([create fname glob glob01]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -33,18 +27,17 @@ watcher { path $cwd/dir; event create; file temp.*; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/tempfile +], +[> dir/tempfile > dir/temp.txt -waitfile $outfile 6 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[outfile=$cwd/dump +mkdir dir +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/glob02.at b/tests/glob02.at index 7377730..298e4ce 100644 --- a/tests/glob02.at +++ b/tests/glob02.at @@ -17,13 +17,7 @@ AT_SETUP([Globbing pattern negation]) AT_KEYWORDS([create fname glob glob02 neg]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -33,18 +27,17 @@ watcher { path $cwd/dir; event create; file "!*.tmp"; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -a"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -a -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/tempfile +], +[> dir/tempfile > dir/file.tmp -waitfile $outfile 6 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[outfile=$cwd/dump +mkdir dir +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/printname b/tests/printname index 279caf8..1a6eb1b 100755 --- a/tests/printname +++ b/tests/printname @@ -1,2 +1,4 @@ #! /bin/sh echo `pwd`/$DIREVENT_FILE >> $1 +if test $DIREVENT_FILE = sentinel; then kill -HUP $DIREVENT_SELF_TEST_PID; fi + diff --git a/tests/re01.at b/tests/re01.at index 0b82b03..b3a36a5 100644 --- a/tests/re01.at +++ b/tests/re01.at @@ -17,13 +17,7 @@ AT_SETUP([Extended case-sensitive]) AT_KEYWORDS([create fname regexp re re01]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -33,18 +27,17 @@ watcher { path $cwd/dir; event create; file /temp.*/; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/file +], +[> dir/file > dir/tempfile -waitfile $outfile 6 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile +], +[outfile=$cwd/dump +mkdir dir +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile ], [0], [# Dump of execution environment diff --git a/tests/re02.at b/tests/re02.at index 3fd269f..3d9dd82 100644 --- a/tests/re02.at +++ b/tests/re02.at @@ -17,13 +17,7 @@ AT_SETUP([Extended case-insensitive]) AT_KEYWORDS([create fname regexp re re02]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -33,19 +27,17 @@ watcher { path $cwd/dir; event create; file /temp.*/i; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/file +], +[> dir/file > dir/TEMPFILE -waitfile $outfile 6 -kill `cat $pidfile` -sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^" $outfile ], +[outfile=$cwd/dump +mkdir dir +], +[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d;/DIREVENT_SELF_TEST_PID/d" $outfile], [0], [# Dump of execution environment cwd is (CWD)/dir diff --git a/tests/re03.at b/tests/re03.at index 2c36314..af17800 100644 --- a/tests/re03.at +++ b/tests/re03.at @@ -17,13 +17,7 @@ AT_SETUP([Basic case-sensitive]) AT_KEYWORDS([create fname regexp re re03]) -AT_CHECK([ -cwd=`pwd -P` -pidfile=$cwd/direvent.pid -outfile=$cwd/dump -mkdir dir -cat > test.conf <<EOT -pidfile $pidfile; +AT_DIREVENT_TEST([ debug 10; syslog { facility ${TESTSUITE_FACILITY:-local0}; @@ -33,18 +27,17 @@ watcher { path $cwd/dir; event create; file "/a{2}.*/b"; - command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile"; + command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid"; option (stdout,stderr); } -EOT - -direvent -lnotice test.conf || exit 1 -waitfile $pidfile 2 -> dir/file +] |