Prepare Open vSwitch 1.1.2 release.
[sliver-openvswitch.git] / tests / test-lockfile.c
index 31e13a7..0feb270 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
 #include "process.h"
 #include "timeval.h"
 #include "util.h"
+#include "vlog.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -100,10 +101,15 @@ do_fork(void)
 static void
 run_lock_blocks_other_process(void)
 {
-    struct lockfile *lockfile;
+    /* Making this static prevents a memory leak warning from valgrind for the
+     * parent process, which cannot easily unlock (and free) 'lockfile' because
+     * it can only do so after the child has exited, and it's the caller of
+     * this function that does the wait() call. */
+    static struct lockfile *lockfile;
 
     assert(lockfile_lock("file", 0, &lockfile) == 0);
     if (do_fork() == CHILD) {
+        lockfile_unlock(lockfile);
         assert(lockfile_lock("file", 0, &lockfile) == EAGAIN);
         exit(11);
     }
@@ -144,6 +150,7 @@ run_lock_timeout_gets_the_lock(void)
     assert(lockfile_lock("file", 0, &lockfile) == 0);
 
     if (do_fork() == CHILD) {
+        lockfile_unlock(lockfile);
         assert(lockfile_lock("file", TIME_UPDATE_INTERVAL * 3,
                              &lockfile) == 0);
         exit(11);
@@ -164,6 +171,7 @@ run_lock_timeout_runs_out(void)
     assert(lockfile_lock("file", 0, &lockfile) == 0);
 
     if (do_fork() == CHILD) {
+        lockfile_unlock(lockfile);
         assert(lockfile_lock("file", TIME_UPDATE_INTERVAL,
                              &lockfile) == ETIMEDOUT);
         exit(11);
@@ -230,10 +238,11 @@ static const struct test tests[] = {
 int
 main(int argc, char *argv[])
 {
+    extern struct vlog_module VLM_lockfile;
     size_t i;
 
     set_program_name(argv[0]);
-    time_init();
+    vlog_set_levels(&VLM_lockfile, VLF_ANY_FACILITY, VLL_ERR);
 
     if (argc != 2) {
         ovs_fatal(0, "exactly one argument required; use \"%s help\" for help",