[ovs-dev] [PATCH v2] tests: Simplify and improve the daemon tests.

2018-12-10 Thread Ben Pfaff
From: Scott Cheloha 

The daemon tests used files a lot when shell variables were easier to use
and easier to understand.  This commit changes that.

The tests created empty databases that aren't really needed anymore.  This
commit changes them to use the ovsdb-server --no-db option instead.

The tests had a lot of common code for checking the ancestry of processes.
This commit factors out a new shell function check_ancestors.

The tests tended to use random pidfile names.  This switches to just using
the defaults, which are fine.

The tests didn't check the names of the child processes.  This adds those
checks using the new check_process_name shell function.  This should avoid
regression of the bug fixed by commit 266f79e32c60 ("daemon-unix: Use
same name for original or restarted children.")

Other minor improvements too.

I only made small updates to the Windows-specific test, because it is hard
for me to verify.

Acked-by: Alin Gabriel Serdean 
Signed-off-by: Ben Pfaff 
---
v1->v2: Rebased, added ack.

 tests/daemon-py.at | 218 +
 tests/daemon.at| 212 ---
 tests/odp.at   |  12 +--
 3 files changed, 224 insertions(+), 218 deletions(-)

diff --git a/tests/daemon-py.at b/tests/daemon-py.at
index b7236b1f3622..6adea3c85dfc 100644
--- a/tests/daemon-py.at
+++ b/tests/daemon-py.at
@@ -6,20 +6,23 @@ m4_define([DAEMON_PYN],
# Skip this test for Windows, echo $! gives shell pid instead of parent 
process
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
AT_KEYWORDS([python daemon])
-   AT_CAPTURE_FILE([pid])
-   AT_CAPTURE_FILE([expected])
+
+   on_exit 'kill $(cat *.pid)'
+   pidfile=test-daemon.py.pid
+
# Start the daemon and wait for the pidfile to get created
# and that its contents are the correct pid.
-   AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid& echo $! > expected], [0])
-   OVS_WAIT_UNTIL([test -s pid], [kill `cat expected`])
-   AT_CHECK(
- [pid=`cat pid` && expected=`cat expected` && test "$pid" = "$expected"],
- [0], [], [], [kill `cat expected`])
-   AT_CHECK([kill -0 `cat pid`], [0], [], [], [kill `cat expected`])
+   AT_CHECK([$3 $srcdir/test-daemon.py --pidfile & echo $!], [0], [stdout])
+   pid=$(cat stdout)
+
+   OVS_WAIT_UNTIL([test -s $pidfile], [kill $pid])
+   AT_CHECK([test $pid = $(cat $pidfile)])
+   AT_CHECK([kill -0 $pid])
+
# Kill the daemon and make sure that the pidfile gets deleted.
-   kill `cat expected`
-   OVS_WAIT_WHILE([kill -0 `cat expected`])
-   AT_CHECK([test ! -e pid])
+   kill $pid
+   OVS_WAIT_WHILE([kill -0 $pid])
+   AT_CHECK([test ! -e $pidfile])
AT_CLEANUP])
 
 DAEMON_PYN([Python2], [$HAVE_PYTHON2], [$PYTHON2])
@@ -28,42 +31,38 @@ DAEMON_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
 m4_define([DAEMON_MONITOR_PYN],
   [AT_SETUP([daemon --monitor - $1])
AT_SKIP_IF([test $2 = no])
+
# Skip this test for Windows, echo $! gives shell pid instead of parent 
process
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
-   AT_CAPTURE_FILE([pid])
-   AT_CAPTURE_FILE([parent])
-   AT_CAPTURE_FILE([parentpid])
-   AT_CAPTURE_FILE([newpid])
+
+   on_exit 'kill $(cat *.pid)'
+   pidfile=test-daemon.py.pid
+
# Start the daemon and wait for the pidfile to get created.
-   AT_CHECK([$3 $srcdir/test-daemon.py --pidfile=pid --monitor& echo $! > 
parent], [0])
-   on_exit 'kill `cat parent`'
-   OVS_WAIT_UNTIL([test -s pid])
+   AT_CHECK([$3 $srcdir/test-daemon.py --pidfile --monitor & echo $!], [0], 
[stdout])
+   monitor=$(cat stdout)
+   OVS_WAIT_UNTIL([test -s $pidfile])
+   child=$(cat $pidfile)
+
# Check that the pidfile names a running process,
# and that the parent process of that process is our child process.
-   AT_CHECK([kill -0 `cat pid`])
-   AT_CHECK([parent_pid `cat pid` > parentpid])
-   AT_CHECK(
- [parentpid=`cat parentpid` &&
-  parent=`cat parent` &&
-  test $parentpid = $parent])
+   check_ancestors $child $monitor
+
# Kill the daemon process, making it look like a segfault,
# and wait for a new child process to get spawned.
-   AT_CHECK([cp pid oldpid])
-   AT_CHECK([kill -SEGV `cat pid`], [0], [], [ignore])
-   OVS_WAIT_WHILE([kill -0 `cat oldpid`])
-   OVS_WAIT_UNTIL([test -s pid && test `cat pid` != `cat oldpid`])
-   AT_CHECK([cp pid newpid])
+   AT_CHECK([kill -SEGV $child])
+   OVS_WAIT_WHILE([kill -0 $child])
+   OVS_WAIT_UNTIL([test -s $pidfile && test $(cat $pidfile) != $child])
+   child2=$(cat $pidfile)
+
# Check that the pidfile names a running process,
# and that the parent process of that process is our child process.
-   AT_CHECK([parent_pid `cat pid` > parentpid])
-   AT_CHECK(
- [parentpid=`cat parentpid` &&
-  parent=`cat parent` &&
-  test $parentpid = $parent])
+   check_ancestors $child2 $monitor
+
# Kill the daemon process with SIGTERM, and wait for the daemon
# and the monitor processes to go away and the pidfile to get deleted.
-   

Re: [ovs-dev] [PATCH v2] tests: Simplify and improve the daemon tests.

2018-12-10 Thread Ben Pfaff
Obviously this version is screwed up because I accidentally squashed two
unrelated patches.  I'll post v3.
___
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev