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) (unidiff)
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
@@ -307,8 +307,10 @@ int sigv_set_tab(int sigc, struct sigtab *sigtab, struct sigaction *retsa);
307int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa); 307int sigv_set_action_tab(int sigc, struct sigtab *sigtab, struct sigaction *sa);
308 308
309struct grecs_locus; 309struct grecs_locus;
310int filpatlist_add(filpatlist_t *fptr, char const *arg, struct grecs_locus *loc); 310int filpatlist_add(filpatlist_t *fptr, char const *arg,
311 struct grecs_locus *loc);
311void filpatlist_add_exact(filpatlist_t *fptr, char const *arg); 312void filpatlist_add_exact(filpatlist_t *fptr, char const *arg);
312void filpatlist_destroy(filpatlist_t *fptr); 313void filpatlist_destroy(filpatlist_t *fptr);
313int filpatlist_match(filpatlist_t fp, const char *name); 314int filpatlist_match(filpatlist_t fp, const char *name);
315int filpatlist_is_empty(filpatlist_t fp);
314 316
diff --git a/src/fnpat.c b/src/fnpat.c
index 5a98053..3e282b3 100644
--- a/src/fnpat.c
+++ b/src/fnpat.c
@@ -137,6 +137,14 @@ filpatlist_destroy(filpatlist_t *fptr)
137} 137}
138 138
139int 139int
140filpatlist_is_empty(filpatlist_t fp)
141{
142 if (!fp)
143 return 1;
144 return grecs_list_size(fp->list) == 0;
145}
146
147int
140filpatlist_match(filpatlist_t fp, const char *name) 148filpatlist_match(filpatlist_t fp, const char *name)
141{ 149{
142 struct grecs_list_entry *ep; 150 struct grecs_list_entry *ep;
diff --git a/src/watcher.c b/src/watcher.c
index 7ac3d86..9b6c633 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -203,21 +203,27 @@ convert_watcher(struct watchpoint *wpt)
203 char *new_dirname; 203 char *new_dirname;
204 struct handler *hp; 204 struct handler *hp;
205 handler_iterator_t itr; 205 handler_iterator_t itr;
206 206
207 filename = split_pathname(wpt, &dirname);
208
207 for_each_handler(wpt, itr, hp) { 209 for_each_handler(wpt, itr, hp) {
208 if (hp->fnames) { 210 if (!filpatlist_is_empty(hp->fnames)
209 /* FIXME: Error message */ 211 && filpatlist_match(hp->fnames, filename) == 0) {
212 unsplit_pathname(wpt);
213 diag(LOG_ERR,
214 _("can't convert file watcher %s to directory watcher"),
215 wpt->dirname);
210 return 1; 216 return 1;
211 } 217 }
212 } 218 }
213 219
214 filename = split_pathname(wpt, &dirname);
215 for_each_handler(wpt, itr, hp) 220 for_each_handler(wpt, itr, hp)
216 filpatlist_add_exact(&hp->fnames, filename); 221 filpatlist_add_exact(&hp->fnames, filename);
217 222
218 new_dirname = estrdup(dirname); 223 new_dirname = estrdup(dirname);
219 unsplit_pathname(wpt); 224 unsplit_pathname(wpt);
220 diag(LOG_NOTICE, _("watcher %s converted to %s"), 225 diag(LOG_NOTICE,
226 _("file watcher %s converted to directory watcher %s"),
221 wpt->dirname, new_dirname); 227 wpt->dirname, new_dirname);
222 228
223 free(wpt->dirname); 229 free(wpt->dirname);
@@ -302,7 +308,6 @@ watchpoint_init(struct watchpoint *wpt)
302 return 1; 308 return 1;
303 } 309 }
304 } else if (!S_ISDIR(st.st_mode)) { 310 } else if (!S_ISDIR(st.st_mode)) {
305 diag(LOG_NOTICE, _("%s is a regular file"), wpt->dirname);
306 convert_watcher(wpt); 311 convert_watcher(wpt);
307 } 312 }
308 313
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f797790..4b70e75 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,6 +41,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
41TESTSUITE_AT = \ 41TESTSUITE_AT = \
42 attrib.at\ 42 attrib.at\
43 cmdexp.at\ 43 cmdexp.at\
44 conv.at\
44 create.at\ 45 create.at\
45 createrec.at\ 46 createrec.at\
46 delete.at\ 47 delete.at\
@@ -57,6 +58,7 @@ TESTSUITE_AT = \
57 re05.at\ 58 re05.at\
58 samepath.at\ 59 samepath.at\
59 shell.at\ 60 shell.at\
61 sent.at\
60 testsuite.at\ 62 testsuite.at\
61 write.at 63 write.at
62 64
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 @@
1# This file is part of Direvent testsuite. -*- Autotest -*-
2# Copyright (C) 2013-2016 Sergey Poznyakoff
3#
4# Direvent is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Direvent is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Direvent. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([File watcher])
18AT_KEYWORDS([special conv convert file])
19
20AT_DIREVENT_TEST_UNQUOTED([
21debug 10;
22syslog {
23 facility ${TESTSUITE_FACILITY:-local0};
24 tag direvent-test:create;
25}
26watcher {
27 path $cwd/file;
28 event (create,write,delete);
29 option (stdout,stderr);
30 command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -f $outfile -k\$self_test_pid";
31}
32],
33[echo "foo" > file
34],
35[outfile=$cwd/dump
36echo "file" > file
37],
38[sed '/^argv\[[[0-9]]\]=-k/d' $outfile
39],
40[0],
41[# Dump of execution environment
42cwd is $cwd
43# Arguments
44argv[[0]]=$TESTDIR/envdump
45argv[[1]]=-s
46argv[[2]]=-i
47argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_
48argv[[4]]=-f
49argv[[5]]=$cwd/dump
50# Environment
51DIREVENT_FILE=file
52DIREVENT_GENEV_CODE=2
53DIREVENT_GENEV_NAME=write
54# End
55],
56[direvent: [[NOTICE]] file watcher $cwd/file converted to directory watcher $cwd
57])
58
59AT_CLEANUP
60
61
62
63
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 @@
1# This file is part of Direvent testsuite. -*- Autotest -*-
2# Copyright (C) 2013-2016 Sergey Poznyakoff
3#
4# Direvent is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# Direvent is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Direvent. If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([Sentinel])
18AT_KEYWORDS([special sent sentinel])
19
20AT_DIREVENT_TEST_UNQUOTED([
21debug 10;
22syslog {
23 facility ${TESTSUITE_FACILITY:-local0};
24 tag direvent-test:create;
25}
26watcher {
27 path $cwd/dir/sub;
28 file "foo";
29 event (create);
30 option (stdout,stderr);
31 command "$TESTDIR/envdump -s -i DIREVENT_FILE=:DIREVENT_GENEV_ -a -f $outfile -k\$self_test_pid";
32}
33],
34[mkdir $cwd/dir
35mkdir $cwd/dir/sub
36echo "bar" > $cwd/dir/sub/bar
37echo "foo" > $cwd/dir/sub/foo
38],
39[outfile=$cwd/dump
40],
41[sed "s^$cwd^(CWD)^;s^$TESTDIR^(TESTDIR)^;/^argv\[[[0-9]]\]=-k/d" $outfile
42],
43[0],
44[# Dump of execution environment
45cwd is (CWD)/dir/sub
46# Arguments
47argv[[0]]=(TESTDIR)/envdump
48argv[[1]]=-s
49argv[[2]]=-i
50argv[[3]]=DIREVENT_FILE=:DIREVENT_GENEV_
51argv[[4]]=-a
52argv[[5]]=-f
53argv[[6]]=(CWD)/dump
54# Environment
55DIREVENT_FILE=foo
56DIREVENT_GENEV_CODE=1
57DIREVENT_GENEV_NAME=create
58# End
59],
60[direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir/sub
61direvent: [[NOTICE]] installing CREATE sentinel for $cwd/dir
62])
63
64AT_CLEANUP
65
diff --git a/tests/testsuite.at b/tests/testsuite.at
index cbe9906..09538b5 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -18,28 +18,32 @@ m4_version_prereq([2.52g])
18 18
19m4_define([AT_SKIP_TEST],[exit 77]) 19m4_define([AT_SKIP_TEST],[exit 77])
20 20
21dnl AT_DIREVENT_TEST([CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT], 21dnl m4_direvent_test([MOD],
22dnl [CONFIG],[SELFTEST],[PROLOGUE],[EPILOGUE],[CODE],[STDOUT],
22dnl [STDERR]) 23dnl [STDERR])
23m4_define([AT_DIREVENT_TEST],[ 24m4_define([m4_direvent_test],[
24AT_CHECK([
25cwd=`pwd -P` 25cwd=`pwd -P`
26$3 26AT_CHECK$1([
27$4
27cat > test.conf <<EOT 28cat > test.conf <<EOT
28[$1] 29[$2]
29EOT 30EOT
30cat > selftest.sh <<EOT 31cat > selftest.sh <<EOT
31#!/bin/sh 32#!/bin/sh
32[$2] 33[$3]
33sleep 10 34sleep 10
34exit 21 35exit 21
35EOT 36EOT
36chmod +x selftest.sh 37chmod +x selftest.sh
37direvent -lnotice -f --self-test $cwd/selftest.sh test.conf || exit $? 38direvent -lnotice -f --self-test $cwd/selftest.sh test.conf || exit $?
38$4 39$5
39], 40],
40[$5],
41[$6], 41[$6],
42[$7])]) 42[$7],
43[$8])])
44
45m4_define([AT_DIREVENT_TEST],[m4_direvent_test([],$@)])
46m4_define([AT_DIREVENT_TEST_UNQUOTED],[m4_direvent_test([_UNQUOTED], $@)])
43 47
44AT_INIT 48AT_INIT
45AT_TESTED([direvent]) 49AT_TESTED([direvent])
@@ -68,3 +72,6 @@ m4_include([re03.at])
68m4_include([re04.at]) 72m4_include([re04.at])
69m4_include([re05.at]) 73m4_include([re05.at])
70 74
75AT_BANNER([Special watchpoints])
76m4_include([conv.at])
77m4_include([sent.at])

Return to:

Send suggestions and report system problems to the System administrator.