summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-08-23 09:25:10 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-08-25 19:29:47 (GMT)
commit33d60a8ce049c623cd4885a49e0a0a80ab11bc74 (patch) (side-by-side diff)
tree0d90f63b7586b5c0c031ec0ac0263c635427a020
parenta60dcd92df15705bb84f644c99fd166e101dc681 (diff)
downloaddirevent-33d60a8ce049c623cd4885a49e0a0a80ab11bc74.tar.gz
direvent-33d60a8ce049c623cd4885a49e0a0a80ab11bc74.tar.bz2
Add new tests + minor fixes.
* src/direvent.h (filpatlist_is_empty): New proto. * src/fnpat.c (filpatlist_is_empty): New function. * src/watcher.c (convert_watcher): Fix error handling. (watchpoint_init): Remove spurious notice. * tests/conv.at: New test. * tests/sent.at: New test. * tests/Makefile.am: Add new tests. * tests/testsuite.at: Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/direvent.h4
-rw-r--r--src/fnpat.c8
-rw-r--r--src/watcher.c17
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/conv.at63
-rw-r--r--tests/sent.at65
-rw-r--r--tests/testsuite.at25
7 files changed, 168 insertions, 16 deletions
diff --git a/src/direvent.h b/src/direvent.h
index d69fa34..416d833 100644
--- a/src/direvent.h
+++ b/src/direvent.h
@@ -304,11 +304,13 @@ int sigv_set_action(int sigc, int *sigv, struct sigaction *sa);
int sigv_set_all(void (*handler)(int), int sigc, int *sigv,
struct sigaction *retsa);
int sigv_set_tab(int sigc, struct sigtab *sigtab, struct sigaction *retsa);
int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa);
struct grecs_locus;
-int filpatlist_add(filpatlist_t *fptr, char const *arg, struct grecs_locus *loc);
+int filpatlist_add(filpatlist_t *fptr, char const *arg,
+ struct grecs_locus *loc);
void filpatlist_add_exact(filpatlist_t *fptr, char const *arg);
void filpatlist_destroy(filpatlist_t *fptr);
int filpatlist_match(filpatlist_t fp, const char *name);
+int filpatlist_is_empty(filpatlist_t fp);
diff --git a/src/fnpat.c b/src/fnpat.c
index 5a98053..3e282b3 100644
--- a/src/fnpat.c
+++ b/src/fnpat.c
@@ -134,12 +134,20 @@ filpatlist_destroy(filpatlist_t *fptr)
free(*fptr);
*fptr = NULL;
}
}
int
+filpatlist_is_empty(filpatlist_t fp)
+{
+ if (!fp)
+ return 1;
+ return grecs_list_size(fp->list) == 0;
+}
+
+int
filpatlist_match(filpatlist_t fp, const char *name)
{
struct grecs_list_entry *ep;
if (!fp || !fp->list)
return 0;
diff --git a/src/watcher.c b/src/watcher.c
index 7ac3d86..9b6c633 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -200,27 +200,33 @@ convert_watcher(struct watchpoint *wpt)
{
char *dirname;
char *filename;
char *new_dirname;
struct handler *hp;
handler_iterator_t itr;
-
+
+ filename = split_pathname(wpt, &dirname);
+
for_each_handler(wpt, itr, hp) {
- if (hp->fnames) {
- /* FIXME: Error message */
+ if (!filpatlist_is_empty(hp->fnames)
+ && filpatlist_match(hp->fnames, filename) == 0) {
+ unsplit_pathname(wpt);
+ diag(LOG_ERR,
+ _("can't convert file watcher %s to directory watcher"),
+ wpt->dirname);
return 1;
}
}
- filename = split_pathname(wpt, &dirname);
for_each_handler(wpt, itr, hp)
filpatlist_add_exact(&hp->fnames, filename);
new_dirname = estrdup(dirname);
unsplit_pathname(wpt);
- diag(LOG_NOTICE, _("watcher %s converted to %s"),
+ diag(LOG_NOTICE,
+ _("file watcher %s converted to directory watcher %s"),
wpt->dirname, new_dirname);
free(wpt->dirname);
wpt->dirname = new_dirname;
return 0;
}
@@ -299,13 +305,12 @@ watchpoint_init(struct watchpoint *wpt)
} else {
diag(LOG_ERR, _("cannot set watcher on %s: %s"),
wpt->dirname, strerror(errno));
return 1;
}
} else if (!S_ISDIR(st.st_mode)) {
- diag(LOG_NOTICE, _("%s is a regular file"), wpt->dirname);
convert_watcher(wpt);
}
for_each_handler(wpt, itr, hp) {
mask.sys_mask |= hp->ev_mask.sys_mask;
mask.gen_mask |= hp->ev_mask.gen_mask;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f797790..4b70e75 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,12 +38,13 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
## Test suite. ##
## ------------ ##
TESTSUITE_AT = \
attrib.at\
cmdexp.at\
+ conv.at\
create.at\
createrec.at\
delete.at\
env00.at\
env01.at\
env02.at\
@@ -54,12 +55,13 @@ TESTSUITE_AT = \
re02.at\
re03.at\
re04.at\
re05.at\
samepath.at\
shell.at\
+ sent.at\
testsuite.at\
write.at
TESTSUITE = $(srcdir)/testsuite
M4=m4
diff --git a/tests/conv.at b/tests/conv.at
new file mode 100644
index 0000000..d46f7f6
--- a/dev/null
+++ b/tests/conv.at
@@ -0,0 +1,63 @@
+# This file is part of Direvent testsuite. -*- Autotest -*-
+# Copyright (C) 2013-2016 Sergey Poznyakoff
+#
+# Direvent 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.
+#
+# Direvent 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 Direvent. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([File watcher])
+AT_KEYWORDS([special conv convert file])
+
+AT_DIREVENT_TEST_UNQUOTED([
+debug 10;
+syslog {
+ facility ${TESTSUITE_FACILITY:-local0};
+ tag direvent-test:create;
+}
+watcher {
+ path $cwd/file;
+ event (create,write,delete);
+ option (stdout,stderr);
+ command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid";
+}
+],
+[echo "foo" > file
+],
+[outfile=$cwd/dump
+echo "file" > file
+],
+[sed '/^argv\[[[0-9]]\]=-k/d' $outfile
+],
+[0],
+[# Dump of execution environment
+cwd is $cwd
+# Arguments
+argv[[0]]=$TESTDIR/envdump
+argv[[1]]=-s
+argv[[2]]=-i
+argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_
+argv[[4]]=-f
+argv[[5]]=$cwd/dump
+# Environment
+DIREVENT_FILE=file
+DIREVENT_GENEV_CODE=2
+DIREVENT_GENEV_NAME=write
+# End
+],
+[direvent: [[NOTICE]] file watcher $cwd/file converted to directory watcher $cwd
+])
+
+AT_CLEANUP
+
+
+
+
diff --git a/tests/sent.at b/tests/sent.at
new file mode 100644
index 0000000..1d8e152
--- a/dev/null
+++ b/tests/sent.at
@@ -0,0 +1,65 @@
+# This file is part of Direvent testsuite. -*- Autotest -*-
+# Copyright (C) 2013-2016 Sergey Poznyakoff
+#
+# Direvent 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.
+#
+# Direvent 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 Direvent. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Sentinel])
+AT_KEYWORDS([special sent sentinel])
+
+AT_DIREVENT_TEST_UNQUOTED([
+debug 10;
+syslog {
+ facility ${TESTSUITE_FACILITY:-local0};
+ tag direvent-test:create;
+}
+watcher {
+ path $cwd/dir/sub;
+ file "foo";
+ event (create);
+ option (stdout,stderr);
+ command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -a -f $outfile -k\$self_test_pid";
+}
+],
+[mkdir $cwd/dir
+mkdir $cwd/dir/sub
+echo "bar" > $cwd/dir/sub/bar
+echo "foo" > $cwd/dir/sub/foo
+],
+[outfile=$cwd/dump
+],
+[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile
+],
+[0],
+[# Dump of execution environment
+cwd is (CWD)/dir/sub
+# Arguments
+argv[[0]]=(TESTDIR)/envdump
+argv[[1]]=-s
+argv[[2]]=-i
+argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_
+argv[[4]]=-a
+argv[[5]]=-f
+argv[[6]]=(CWD)/dump
+# Environment
+DIREVENT_FILE=foo
+DIREVENT_GENEV_CODE=1
+DIREVENT_GENEV_NAME=create
+# End
+],
+[direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir/sub
+direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir
+])
+
+AT_CLEANUP
+
diff --git a/tests/testsuite.at b/tests/testsuite.at
index cbe9906..09538b5 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -15,34 +15,38 @@
# along with Direvent. If not, see <http://www.gnu.org/licenses/>.
m4_version_prereq([2.52g])
m4_define([AT_SKIP_TEST],[exit 77])
-dnl AT_DIREVENT_TEST([CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT],
+dnl m4_direvent_test([MOD],
+dnl [CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT],
dnl [STDERR])
-m4_define([AT_DIREVENT_TEST],[
-AT_CHECK([
+m4_define([m4_direvent_test],[
cwd=`pwd -P`
-$3
+AT_CHECK$1([
+$4
cat > test.conf <<EOT
-[$1]
+[$2]
EOT
cat > selftest.sh <<EOT
#!/bin/sh
-[$2]
+[$3]
sleep 10
exit 21
EOT
chmod +x selftest.sh
direvent -lnotice -f --self-test $cwd/selftest.sh test.conf || exit $?
-$4
+$5
],
-[$5],
[$6],
-[$7])])
+[$7],
+[$8])])
+
+m4_define([AT_DIREVENT_TEST],[m4_direvent_test([],$@)])
+m4_define([AT_DIREVENT_TEST_UNQUOTED],[m4_direvent_test([_UNQUOTED], $@)])
AT_INIT
AT_TESTED([direvent])
m4_include([create.at])
m4_include([createrec.at])
@@ -65,6 +69,9 @@ m4_include([glob02.at])
m4_include([re01.at])
m4_include([re02.at])
m4_include([re03.at])
m4_include([re04.at])
m4_include([re05.at])
+AT_BANNER([Special watchpoints])
+m4_include([conv.at])
+m4_include([sent.at])

Return to:

Send suggestions and report system problems to the System administrator.