Some of the tests in test-lockfile.c uses fork to test a
child's ability to acquire lock. We do not fork in Windows.
We also do not support symlinks on Windows.  So, comment out
those tests.

The error messages output is different in Windows and Linux. So
adjust the tests accordingly.

Signed-off-by: Gurucharan Shetty <gshe...@nicira.com>
---
 lib/lockfile.c        |    1 -
 tests/lockfile.at     |   30 ++++++++++++++++-------
 tests/test-lockfile.c |   64 ++++++++++++++++++++++++++++++++-----------------
 3 files changed, 63 insertions(+), 32 deletions(-)

diff --git a/lib/lockfile.c b/lib/lockfile.c
index d157bc6..5d1db6a 100644
--- a/lib/lockfile.c
+++ b/lib/lockfile.c
@@ -276,7 +276,6 @@ lockfile_try_lock(const char *name, pid_t *pidp, struct 
lockfile **lockfilep)
     retval = LockFileEx(lock_handle, LOCKFILE_EXCLUSIVE_LOCK
                         | LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &overl);
     if (!retval) {
-        VLOG_WARN("Failed to lock file : %s", ovs_lasterror_to_string());
         return EEXIST;
     }
 
diff --git a/tests/lockfile.at b/tests/lockfile.at
index 2e2a74b..82f4ddd 100644
--- a/tests/lockfile.at
+++ b/tests/lockfile.at
@@ -1,12 +1,19 @@
 AT_BANNER([lockfile unit tests])
 
+# CHECK_LOCKFILE([test-name], [number-children], [linux-error-message]
+#                [skip-test-windows], [windows-error-message])
 m4_define([CHECK_LOCKFILE],
   [AT_SETUP([m4_translit([$1], [_], [ ])])
+   AT_SKIP_IF([test "$4" = "yes" && test "$IS_WIN32" = "yes"])
    AT_KEYWORDS([lockfile])
    AT_CHECK([ovstest test-lockfile $1], [0], [$1: success (m4_if(
      [$2], [1], [$2 child], [$2 children]))
 ], [stderr])
-   AT_CHECK([sed 's/pid [[0-9]]*/pid <pid>/' stderr], [0], [$3])
+   if test "$IS_WIN32" = "no"; then
+     AT_CHECK([sed 's/pid [[0-9]]*/pid <pid>/' stderr], [0], [$3])
+   else
+     AT_CHECK([sed 's/pid [[0-9]]*/pid <pid>/' stderr], [0], [$5])
+   fi
    AT_CLEANUP])
 
 CHECK_LOCKFILE([lock_and_unlock], [0])
@@ -14,29 +21,34 @@ CHECK_LOCKFILE([lock_and_unlock], [0])
 CHECK_LOCKFILE([lock_and_unlock_twice], [0])
 
 CHECK_LOCKFILE([lock_blocks_same_process], [0],
-  [lockfile|WARN|.file.~lock~: cannot lock file because this process has 
already locked it
-])
+[lockfile|WARN|.file.~lock~: cannot lock file because this process has already 
locked it
+], [no], [lockfile|WARN|.file.~lock~: failed to lock file: File exists
+],
+)
 
 CHECK_LOCKFILE([lock_blocks_same_process_twice], [0],
-  [lockfile|WARN|.file.~lock~: cannot lock file because this process has 
already locked it
+[lockfile|WARN|.file.~lock~: cannot lock file because this process has already 
locked it
 lockfile|WARN|.file.~lock~: cannot lock file because this process has already 
locked it
+], [no], [lockfile|WARN|.file.~lock~: failed to lock file: File exists
+lockfile|WARN|.file.~lock~: failed to lock file: File exists
 ])
 
 CHECK_LOCKFILE([lock_blocks_other_process], [1],
   [lockfile|WARN|.file.~lock~: child does not inherit lock
 lockfile|WARN|.file.~lock~: cannot lock file because it is already locked by 
pid <pid>
-])
+], [yes])
 
 CHECK_LOCKFILE([lock_twice_blocks_other_process], [1],
   [lockfile|WARN|.file.~lock~: cannot lock file because this process has 
already locked it
 lockfile|WARN|.file.~lock~: child does not inherit lock
 lockfile|WARN|.file.~lock~: cannot lock file because it is already locked by 
pid <pid>
-])
+], [yes])
 
-CHECK_LOCKFILE([lock_and_unlock_allows_other_process], [1])
+CHECK_LOCKFILE([lock_and_unlock_allows_other_process], [1], [], [yes])
 
 CHECK_LOCKFILE([lock_multiple], [0],
   [lockfile|WARN|.a.~lock~: cannot lock file because this process has already 
locked it
+], [no], [lockfile|WARN|.a.~lock~: failed to lock file: File exists
 ])
 
 CHECK_LOCKFILE([lock_symlink], [0],
@@ -44,8 +56,8 @@ CHECK_LOCKFILE([lock_symlink], [0],
 lockfile|WARN|.b.~lock~: cannot lock file because this process has already 
locked it
 lockfile|WARN|.b.~lock~: cannot lock file because this process has already 
locked it
 lockfile|WARN|.a.~lock~: cannot lock file because this process has already 
locked it
-])
+], [yes])
 
 CHECK_LOCKFILE([lock_symlink_to_dir], [0],
   [lockfile|WARN|dir/.b.~lock~: cannot lock file because this process has 
already locked it
-])
+], [yes])
diff --git a/tests/test-lockfile.c b/tests/test-lockfile.c
index 0bf3fe6..016b0d1 100644
--- a/tests/test-lockfile.c
+++ b/tests/test-lockfile.c
@@ -77,7 +77,11 @@ run_lock_blocks_same_process(void)
     struct lockfile *lockfile;
 
     CHECK(lockfile_lock("file", &lockfile), 0);
+#ifndef _WIN32
     CHECK(lockfile_lock("file", &lockfile), EDEADLK);
+#else
+    CHECK(lockfile_lock("file", &lockfile), EEXIST);
+#endif
     lockfile_unlock(lockfile);
 }
 
@@ -87,11 +91,17 @@ run_lock_blocks_same_process_twice(void)
     struct lockfile *lockfile;
 
     CHECK(lockfile_lock("file", &lockfile), 0);
+#ifndef _WIN32
     CHECK(lockfile_lock("file", &lockfile), EDEADLK);
     CHECK(lockfile_lock("file", &lockfile), EDEADLK);
+#else
+    CHECK(lockfile_lock("file", &lockfile), EEXIST);
+    CHECK(lockfile_lock("file", &lockfile), EEXIST);
+#endif
     lockfile_unlock(lockfile);
 }
 
+#ifndef _WIN32
 static enum { PARENT, CHILD }
 do_fork(void)
 {
@@ -153,27 +163,6 @@ run_lock_and_unlock_allows_other_process(void)
     }
 }
 
-static void
-run_lock_multiple(void)
-{
-    struct lockfile *a, *b, *c, *dummy;
-
-    CHECK(lockfile_lock("a", &a), 0);
-    CHECK(lockfile_lock("b", &b), 0);
-    CHECK(lockfile_lock("c", &c), 0);
-
-    lockfile_unlock(a);
-    CHECK(lockfile_lock("a", &a), 0);
-    CHECK(lockfile_lock("a", &dummy), EDEADLK);
-    lockfile_unlock(a);
-
-    lockfile_unlock(b);
-    CHECK(lockfile_lock("a", &a), 0);
-
-    lockfile_unlock(c);
-    lockfile_unlock(a);
-}
-
 /* Checks that locking a dangling symlink works OK.  (It used to hang.) */
 static void
 run_lock_symlink(void)
@@ -236,6 +225,33 @@ run_lock_symlink_to_dir(void)
 
     lockfile_unlock(a);
 }
+#endif
+
+static void
+run_lock_multiple(void)
+{
+    struct lockfile *a, *b, *c, *dummy;
+
+    CHECK(lockfile_lock("a", &a), 0);
+    CHECK(lockfile_lock("b", &b), 0);
+    CHECK(lockfile_lock("c", &c), 0);
+
+    lockfile_unlock(a);
+    CHECK(lockfile_lock("a", &a), 0);
+#ifndef _WIN32
+    CHECK(lockfile_lock("a", &dummy), EDEADLK);
+#else
+    CHECK(lockfile_lock("a", &dummy), EEXIST);
+#endif
+    lockfile_unlock(a);
+
+    lockfile_unlock(b);
+    CHECK(lockfile_lock("a", &a), 0);
+
+    lockfile_unlock(c);
+    lockfile_unlock(a);
+}
+
 
 static const struct test tests[] = {
 #define TEST(NAME) { #NAME, run_##NAME }
@@ -243,12 +259,14 @@ static const struct test tests[] = {
     TEST(lock_and_unlock_twice),
     TEST(lock_blocks_same_process),
     TEST(lock_blocks_same_process_twice),
+#ifndef _WIN32
     TEST(lock_blocks_other_process),
     TEST(lock_twice_blocks_other_process),
     TEST(lock_and_unlock_allows_other_process),
-    TEST(lock_multiple),
     TEST(lock_symlink),
     TEST(lock_symlink_to_dir),
+#endif
+    TEST(lock_multiple),
     TEST(help),
     { NULL, NULL }
 #undef TEST
@@ -289,6 +307,7 @@ test_lockfile_main(int argc, char *argv[])
             (tests[i].function)();
 
             n_children = 0;
+#ifndef _WIN32
             while (wait(&status) > 0) {
                 if (WIFEXITED(status) && WEXITSTATUS(status) == 11) {
                     n_children++;
@@ -300,6 +319,7 @@ test_lockfile_main(int argc, char *argv[])
             if (errno != ECHILD) {
                 ovs_fatal(errno, "wait");
             }
+#endif
 
             printf("%s: success (%d child%s)\n",
                    tests[i].name, n_children, n_children != 1 ? "ren" : "");
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to