Home | History | Annotate | Line # | Download | only in vfs
t_rmdirrace.c revision 1.5
      1  1.5  njoly /*	$NetBSD: t_rmdirrace.c,v 1.5 2010/07/12 21:05:20 njoly Exp $	*/
      2  1.1  njoly 
      3  1.1  njoly /*-
      4  1.1  njoly  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  1.1  njoly  * All rights reserved.
      6  1.1  njoly  *
      7  1.1  njoly  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  njoly  * by Nicolas Joly.
      9  1.1  njoly  *
     10  1.1  njoly  * Redistribution and use in source and binary forms, with or without
     11  1.1  njoly  * modification, are permitted provided that the following conditions
     12  1.1  njoly  * are met:
     13  1.1  njoly  * 1. Redistributions of source code must retain the above copyright
     14  1.1  njoly  *    notice, this list of conditions and the following disclaimer.
     15  1.1  njoly  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  njoly  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  njoly  *    documentation and/or other materials provided with the distribution.
     18  1.1  njoly  *
     19  1.1  njoly  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  njoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  njoly  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  njoly  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  njoly  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  njoly  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  njoly  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  njoly  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  njoly  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  njoly  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  njoly  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  njoly  */
     31  1.1  njoly 
     32  1.1  njoly #include <sys/stat.h>
     33  1.1  njoly 
     34  1.1  njoly #include <atf-c.h>
     35  1.1  njoly #include <fcntl.h>
     36  1.1  njoly #include <pthread.h>
     37  1.1  njoly #include <unistd.h>
     38  1.1  njoly 
     39  1.1  njoly #include <rump/rump_syscalls.h>
     40  1.1  njoly #include <rump/rump.h>
     41  1.1  njoly 
     42  1.1  njoly #include "../common/h_fsmacros.h"
     43  1.1  njoly 
     44  1.1  njoly #define DIRNAME "rmdir.test"
     45  1.1  njoly 
     46  1.1  njoly static void *func1(void *arg)
     47  1.1  njoly {
     48  1.1  njoly 
     49  1.1  njoly 	while (*(int *)arg != 1)
     50  1.1  njoly 		rump_sys_mkdir(DIRNAME, 0755);
     51  1.1  njoly 
     52  1.1  njoly 	return NULL;
     53  1.1  njoly }
     54  1.1  njoly 
     55  1.1  njoly static void *func2(void *arg)
     56  1.1  njoly {
     57  1.1  njoly 
     58  1.1  njoly 	while (*(int *)arg != 1)
     59  1.1  njoly 		rump_sys_rmdir(DIRNAME);
     60  1.1  njoly 
     61  1.1  njoly 	return NULL;
     62  1.1  njoly }
     63  1.1  njoly 
     64  1.1  njoly static void
     65  1.5  njoly race(const atf_tc_t *tc, const char *path)
     66  1.1  njoly {
     67  1.5  njoly 	const char *type;
     68  1.1  njoly 	int res, fd, quit;
     69  1.1  njoly 	pthread_t th1, th2;
     70  1.1  njoly 
     71  1.5  njoly 	type = atf_tc_get_md_var(tc, "X-fs.type");
     72  1.5  njoly 
     73  1.4  njoly 	if (FSTYPE_LFS(type))
     74  1.3  njoly 		atf_tc_expect_signal(-1, "PR kern/43582");
     75  1.4  njoly 	if (FSTYPE_SYSVBFS(type))
     76  1.3  njoly 		atf_tc_skip("%s does not support rmdir(2)", type);
     77  1.3  njoly 
     78  1.1  njoly 	fd = rump_sys_open(".", O_RDONLY, 0666);
     79  1.1  njoly 	if (fd == -1)
     80  1.1  njoly 		atf_tc_fail("open failed");
     81  1.1  njoly 	res = rump_sys_chdir(path);
     82  1.1  njoly 	if (res == -1)
     83  1.1  njoly 		atf_tc_fail("chdir failed");
     84  1.1  njoly 
     85  1.1  njoly 	quit = 0;
     86  1.1  njoly 
     87  1.1  njoly 	res = pthread_create(&th1, NULL, func1, &quit);
     88  1.1  njoly 	if (res != 0)
     89  1.1  njoly 		atf_tc_fail("pthread_create1 failed");
     90  1.1  njoly 	res = pthread_create(&th2, NULL, func2, &quit);
     91  1.1  njoly 	if (res != 0)
     92  1.1  njoly 		atf_tc_fail("pthread_create2 failed");
     93  1.1  njoly 
     94  1.1  njoly 	sleep(10);
     95  1.1  njoly 
     96  1.1  njoly 	quit = 1;
     97  1.1  njoly 
     98  1.1  njoly 	res = pthread_join(th2, NULL);
     99  1.1  njoly 	if (res != 0)
    100  1.1  njoly 		atf_tc_fail("pthread_join2 failed");
    101  1.1  njoly 	res = pthread_join(th1, NULL);
    102  1.1  njoly 	if (res != 0)
    103  1.1  njoly 		atf_tc_fail("pthread_join1 failed");
    104  1.1  njoly 
    105  1.1  njoly 	res = rump_sys_fchdir(fd);
    106  1.1  njoly 	if (res == -1)
    107  1.1  njoly 		atf_tc_fail("fchdir failed");
    108  1.3  njoly 
    109  1.3  njoly 	/*
    110  1.3  njoly 	 * Rarely the LFS test does not crash.  atf currently has no way of
    111  1.3  njoly 	 * saying "just chill even if the test doesn't fail", so this
    112  1.3  njoly 	 * takes care of it.
    113  1.3  njoly 	 */
    114  1.4  njoly 	if (FSTYPE_LFS(type))
    115  1.3  njoly 		abort();
    116  1.1  njoly }
    117  1.1  njoly 
    118  1.1  njoly ATF_FSAPPLY(race, "rmdir(2) race");
    119