summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndy Zhou <azhou@ovn.org>2016-07-22 13:59:03 -0700
committerAndy Zhou <azhou@ovn.org>2016-07-22 15:25:33 -0700
commit0ec19def8282720b59c0e2520a0633969b322739 (patch)
tree965e2f614c841bd900fc0099f63127b8a63159a3 /tests
parent9aeba3f4105726c6c753b68b73750bdec1a033db (diff)
downloadopenvswitch-0ec19def8282720b59c0e2520a0633969b322739.tar.gz
tests: Add ovsdb lock tests
Add more ovsdb lock tests. Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com> Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/automake.mk1
-rw-r--r--tests/ovsdb-lock.at73
-rw-r--r--tests/ovsdb.at1
3 files changed, 75 insertions, 0 deletions
diff --git a/tests/automake.mk b/tests/automake.mk
index bad68d99b..575ffebf5 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -80,6 +80,7 @@ TESTSUITE_AT = \
tests/ovsdb-server.at \
tests/ovsdb-monitor.at \
tests/ovsdb-idl.at \
+ tests/ovsdb-lock.at \
tests/ovs-vsctl.at \
tests/ovs-monitor-ipsec.at \
tests/ovs-xapi-sync.at \
diff --git a/tests/ovsdb-lock.at b/tests/ovsdb-lock.at
new file mode 100644
index 000000000..7152c5d34
--- /dev/null
+++ b/tests/ovsdb-lock.at
@@ -0,0 +1,73 @@
+AT_BANNER([OVSDB -- lock])
+
+# OVSDB_CHECK_LOCK_SETUP(TITILE, KEYWORDS)
+#
+# Starts an OVSDB server and the default lock transaction, acquire "lock0",
+# using the ovsdb-client tool. Execute additional <LOCK_TRANSACTIONS>,
+# and compare output file catured from ovsdb-client tools to <OUTPUT>.
+
+m4_define([OVSDB_CHECK_LOCK_SETUP],
+ [AT_SETUP([ovsdb lock -- $1])
+ AT_SKIP_IF([test "$IS_WIN32" = "yes"])
+ AT_KEYWORDS([ovsdb lock $2])
+ ordinal_schema > schema
+ AT_CHECK([ovsdb-tool create db schema], [0], [stdout], [ignore])
+ AT_CAPTURE_FILE([ovsdb-server-log])
+ AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --remote=punix:socket --log-file="`pwd`"/ovsdb-server-log db >/dev/null 2>&1], [0], [], [])])
+
+#
+# Two sessions create two locks. Both sessions should be able to get their
+# own lock immediately.
+OVSDB_CHECK_LOCK_SETUP([lock], [positive])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
+ [0], [], [])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock1 >c2-output 2>&1],
+ [0], [], [])
+OVS_APP_EXIT_AND_WAIT([ovsdb-server])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+], [])
+AT_CHECK([cat c2-output], 0, [{"locked":true}
+], [])
+AT_CLEANUP
+
+#
+# Two session wait on the same lock. The first session should be able
+# to get the lock immediately, the second session will get a notification
+# after the first session unlocks.
+OVSDB_CHECK_LOCK_SETUP([unlock], [positive])
+AT_CHECK([ovsdb-client --detach --pidfile lock unix:socket lock0 >c1-output 2>&1],
+ [0], [], [])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c2-output 2>&1],
+ [0], [], [])
+AT_CHECK([ovs-appctl -t ovsdb-client unlock lock0], [0], [], [])
+OVS_APP_EXIT_AND_WAIT([ovsdb-server])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+{}
+])
+AT_CHECK([cat c2-output], 0, [{"locked":false}
+locked
+[["lock0"]]
+], [])
+AT_CLEANUP
+
+#
+# Two session waits on the same lock. The first session should be able
+# to get the lock immediately. The second session tries to steal the lock, then
+# unlocks the lock.
+OVSDB_CHECK_LOCK_SETUP([steal], [positive])
+AT_CHECK([ovsdb-client --detach lock unix:socket lock0 >c1-output 2>&1],
+ [0], [], [])
+AT_CHECK([ovsdb-client --detach --pidfile steal unix:socket lock0 >c2-output 2>&1],
+ [0], [], [])
+AT_CHECK([ovs-appctl -t ovsdb-client unlock lock0], [0], [], [])
+OVS_APP_EXIT_AND_WAIT([ovsdb-server])
+AT_CHECK([cat c1-output], 0, [{"locked":true}
+stolen
+[["lock0"]]
+locked
+[["lock0"]]
+])
+AT_CHECK([cat c2-output], 0, [{"locked":true}
+{}
+], [])
+AT_CLEANUP
diff --git a/tests/ovsdb.at b/tests/ovsdb.at
index b20ab9e4b..fe617a562 100644
--- a/tests/ovsdb.at
+++ b/tests/ovsdb.at
@@ -147,3 +147,4 @@ m4_include([tests/ovsdb-replication.at])
m4_include([tests/ovsdb-server.at])
m4_include([tests/ovsdb-monitor.at])
m4_include([tests/ovsdb-idl.at])
+m4_include([tests/ovsdb-lock.at])