AT_BANNER([lockfile unit tests])
+# CHECK_LOCKFILE([test-name], [number-children], [error-message]
+# [skip-test-windows])
m4_define([CHECK_LOCKFILE],
[AT_SETUP([m4_translit([$1], [_], [ ])])
+ m4_if([$4], [yes], [AT_SKIP_IF([test "$IS_WIN32" = "yes"])])
AT_KEYWORDS([lockfile])
AT_CHECK([ovstest test-lockfile $1], [0], [$1: success (m4_if(
[$2], [1], [$2 child], [$2 children]))
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
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])
lockfile_unlock(lockfile);
}
+#ifndef _WIN32
static enum { PARENT, CHILD }
do_fork(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)
lockfile_unlock(a);
}
+#endif /* _WIN32 */
+
+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);
+}
+
static const struct test tests[] = {
#define TEST(NAME) { #NAME, run_##NAME }
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 /* _WIN32 */
+ TEST(lock_multiple),
TEST(help),
{ NULL, NULL }
#undef TEST
(tests[i].function)();
n_children = 0;
+#ifndef _WIN32
while (wait(&status) > 0) {
if (WIFEXITED(status) && WEXITSTATUS(status) == 11) {
n_children++;
if (errno != ECHILD) {
ovs_fatal(errno, "wait");
}
+#endif /* _WIN32 */
printf("%s: success (%d child%s)\n",
tests[i].name, n_children, n_children != 1 ? "ren" : "");