Remove building with NOCRYPTO option
[minix3.git] / tests / fs / vfs / t_rmdirrace.c
blob839dbad73352904407194b4a1df80075bcfa7c0b
1 /* $NetBSD: t_rmdirrace.c,v 1.9 2012/02/16 02:47:56 perseant Exp $ */
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nicolas Joly.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/stat.h>
34 #include <atf-c.h>
35 #include <fcntl.h>
36 #include <pthread.h>
37 #include <stdlib.h>
38 #include <unistd.h>
40 #include <rump/rump_syscalls.h>
41 #include <rump/rump.h>
43 #include "../common/h_fsmacros.h"
45 #define DIRNAME "rmdir.test"
47 static void *func1(void *arg)
50 while (*(int *)arg != 1)
51 rump_sys_mkdir(DIRNAME, 0755);
53 return NULL;
56 static void *func2(void *arg)
59 while (*(int *)arg != 1)
60 rump_sys_rmdir(DIRNAME);
62 return NULL;
65 static void
66 race(const atf_tc_t *tc, const char *path)
68 int res, fd, quit;
69 pthread_t th1, th2;
71 if (FSTYPE_SYSVBFS(tc))
72 atf_tc_skip("directories not supported by file system");
74 fd = rump_sys_open(".", O_RDONLY, 0666);
75 if (fd == -1)
76 atf_tc_fail("open failed");
77 res = rump_sys_chdir(path);
78 if (res == -1)
79 atf_tc_fail("chdir failed");
81 quit = 0;
83 res = pthread_create(&th1, NULL, func1, &quit);
84 if (res != 0)
85 atf_tc_fail("pthread_create1 failed");
86 res = pthread_create(&th2, NULL, func2, &quit);
87 if (res != 0)
88 atf_tc_fail("pthread_create2 failed");
90 sleep(10);
92 quit = 1;
94 res = pthread_join(th2, NULL);
95 if (res != 0)
96 atf_tc_fail("pthread_join2 failed");
97 res = pthread_join(th1, NULL);
98 if (res != 0)
99 atf_tc_fail("pthread_join1 failed");
101 res = rump_sys_fchdir(fd);
102 if (res == -1)
103 atf_tc_fail("fchdir failed");
106 ATF_FSAPPLY(race, "rmdir(2) race");