~ubuntu-branches/ubuntu/wily/openvswitch/wily

« back to all changes in this revision

Viewing changes to tests/test-lockfile.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-10 11:35:15 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20150810113515-575vj06oq29emxsn
Tags: 2.4.0~git20150810.97bab95-0ubuntu1
* New upstream snapshot from 2.4 branch:
  - d/*: Align any relevant packaging changes with upstream.
* d/*: wrap-and-sort.
* d/openvswitch-{common,vswitch}.install: Correct install location for
  bash completion files.
* d/tests/openflow.py: Explicitly use ovs-testcontroller as provided
  by 2.4.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 */
16
16
 
17
17
#include <config.h>
18
 
 
 
18
#undef NDEBUG
19
19
#include "lockfile.h"
20
 
 
21
20
#include <errno.h>
22
21
#include <stdlib.h>
23
22
#include <sys/stat.h>
24
23
#include <sys/wait.h>
25
24
#include <unistd.h>
26
 
 
 
25
#include "ovstest.h"
27
26
#include "process.h"
28
27
#include "timeval.h"
29
28
#include "util.h"
30
 
#include "vlog.h"
31
 
#include "ovstest.h"
 
29
#include "openvswitch/vlog.h"
32
30
 
33
31
struct test {
34
32
    const char *name;
92
90
    lockfile_unlock(lockfile);
93
91
}
94
92
 
 
93
#ifndef _WIN32
95
94
static enum { PARENT, CHILD }
96
95
do_fork(void)
97
96
{
153
152
    }
154
153
}
155
154
 
156
 
static void
157
 
run_lock_multiple(void)
158
 
{
159
 
    struct lockfile *a, *b, *c, *dummy;
160
 
 
161
 
    CHECK(lockfile_lock("a", &a), 0);
162
 
    CHECK(lockfile_lock("b", &b), 0);
163
 
    CHECK(lockfile_lock("c", &c), 0);
164
 
 
165
 
    lockfile_unlock(a);
166
 
    CHECK(lockfile_lock("a", &a), 0);
167
 
    CHECK(lockfile_lock("a", &dummy), EDEADLK);
168
 
    lockfile_unlock(a);
169
 
 
170
 
    lockfile_unlock(b);
171
 
    CHECK(lockfile_lock("a", &a), 0);
172
 
 
173
 
    lockfile_unlock(c);
174
 
    lockfile_unlock(a);
175
 
}
176
 
 
177
155
/* Checks that locking a dangling symlink works OK.  (It used to hang.) */
178
156
static void
179
157
run_lock_symlink(void)
236
214
 
237
215
    lockfile_unlock(a);
238
216
}
 
217
#endif /* _WIN32 */
 
218
 
 
219
static void
 
220
run_lock_multiple(void)
 
221
{
 
222
    struct lockfile *a, *b, *c, *dummy;
 
223
 
 
224
    CHECK(lockfile_lock("a", &a), 0);
 
225
    CHECK(lockfile_lock("b", &b), 0);
 
226
    CHECK(lockfile_lock("c", &c), 0);
 
227
 
 
228
    lockfile_unlock(a);
 
229
    CHECK(lockfile_lock("a", &a), 0);
 
230
    CHECK(lockfile_lock("a", &dummy), EDEADLK);
 
231
    lockfile_unlock(a);
 
232
 
 
233
    lockfile_unlock(b);
 
234
    CHECK(lockfile_lock("a", &a), 0);
 
235
 
 
236
    lockfile_unlock(c);
 
237
    lockfile_unlock(a);
 
238
}
 
239
 
239
240
 
240
241
static const struct test tests[] = {
241
242
#define TEST(NAME) { #NAME, run_##NAME }
243
244
    TEST(lock_and_unlock_twice),
244
245
    TEST(lock_blocks_same_process),
245
246
    TEST(lock_blocks_same_process_twice),
 
247
#ifndef _WIN32
246
248
    TEST(lock_blocks_other_process),
247
249
    TEST(lock_twice_blocks_other_process),
248
250
    TEST(lock_and_unlock_allows_other_process),
249
 
    TEST(lock_multiple),
250
251
    TEST(lock_symlink),
251
252
    TEST(lock_symlink_to_dir),
 
253
#endif /* _WIN32 */
 
254
    TEST(lock_multiple),
252
255
    TEST(help),
253
256
    { NULL, NULL }
254
257
#undef TEST
289
292
            (tests[i].function)();
290
293
 
291
294
            n_children = 0;
 
295
#ifndef _WIN32
292
296
            while (wait(&status) > 0) {
293
297
                if (WIFEXITED(status) && WEXITSTATUS(status) == 11) {
294
298
                    n_children++;
300
304
            if (errno != ECHILD) {
301
305
                ovs_fatal(errno, "wait");
302
306
            }
 
307
#endif /* _WIN32 */
303
308
 
304
309
            printf("%s: success (%d child%s)\n",
305
310
                   tests[i].name, n_children, n_children != 1 ? "ren" : "");