*/
#include <config.h>
-
+#undef NDEBUG
#include "lockfile.h"
-
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
-
+#include "ovstest.h"
#include "process.h"
#include "timeval.h"
#include "util.h"
-#include "vlog.h"
-#include "ovstest.h"
+#include "openvswitch/vlog.h"
struct test {
const char *name;
void (*function)(void);
};
-static const struct test tests[];
+static void run_help(void);
#define CHECK(A, B) check(A, B, #A, #B, __FILE__, __LINE__)
static void
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_help(void)
+run_lock_multiple(void)
{
- size_t i;
+ struct lockfile *a, *b, *c, *dummy;
- printf("usage: %s TESTNAME\n"
- "where TESTNAME is one of the following:\n",
- program_name);
- for (i = 0; tests[i].name; i++) {
- fprintf(stderr, "\t%s\n", tests[i].name);
- }
+ 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),
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
};
+static void
+run_help(void)
+{
+ size_t i;
+
+ printf("usage: %s TESTNAME\n"
+ "where TESTNAME is one of the following:\n",
+ program_name);
+ for (i = 0; tests[i].name; i++) {
+ fprintf(stderr, "\t%s\n", tests[i].name);
+ }
+}
+
static void
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++;
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" : "");