Expand PMF_FN_* macros.
[netbsd-mini2440.git] / tests / fs / ffs / t_renamerace.c
blob513e47ec6eb87005aedb82749959c01ff0047875
1 /* $NetBSD: t_renamerace.c,v 1.7 2009/08/03 14:25:24 pooka Exp $ */
3 /*
4 * Modified for rump and atf from a program supplied
5 * by Nicolas Joly in kern/40948
6 */
8 #include <sys/types.h>
9 #include <sys/mount.h>
11 #include <atf-c.h>
12 #include <errno.h>
13 #include <fcntl.h>
14 #include <pthread.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <string.h>
20 #include <rump/rump.h>
21 #include <rump/rump_syscalls.h>
23 #include <ufs/ufs/ufsmount.h>
25 #include "../../h_macros.h"
27 ATF_TC_WITH_CLEANUP(renamerace);
28 ATF_TC_HEAD(renamerace, tc)
30 atf_tc_set_md_var(tc, "descr", "rename(2) race against files "
31 "unlinked mid-operation, kern/40948");
32 /* XXX: test hangs in qemu for unknown reasons */
33 atf_tc_set_md_var(tc, "timeout", "20");
36 volatile int quit;
38 static void *
39 w1(void *arg)
41 int fd;
43 while (!quit) {
44 fd = rump_sys_open("/mp/rename.test1",
45 O_WRONLY|O_CREAT|O_TRUNC, 0666);
46 rump_sys_unlink("/mp/rename.test1");
47 rump_sys_close(fd);
49 return NULL;
52 static void *
53 w2(void *arg)
56 while (!quit)
57 rump_sys_rename("/mp/rename.test1", "/mp/rename.test2");
59 return NULL;
62 /* XXX: how to do cleanup if we use mkdtemp? */
63 #define IMAGENAME "/tmp/ffsatf.img"
64 static char image[MAXPATHLEN];
66 #define FAKEBLK "/dev/sp00ka"
68 ATF_TC_BODY(renamerace, tc)
70 struct ufs_args args;
71 char cmd[256];
72 pthread_t pt1, pt2;
74 #if 0
75 strcpy(image, TMPPATH);
76 if (mkdtemp(image) == NULL)
77 atf_tc_fail_errno("can't create tmpdir %s", TMPPATH);
78 strcat(image, "/ffsatf.img");
79 #else
80 strcpy(image, IMAGENAME);
81 #endif
83 strcpy(cmd, "newfs -F -s 10000 ");
84 strcat(cmd, image);
86 if (system(cmd) == -1)
87 atf_tc_fail_errno("newfs failed");
89 memset(&args, 0, sizeof(args));
90 args.fspec = __UNCONST(FAKEBLK);
92 rump_init();
93 if (rump_sys_mkdir("/mp", 0777) == -1)
94 atf_tc_fail_errno("cannot create mountpoint");
95 rump_etfs_register(FAKEBLK, image, RUMP_ETFS_BLK);
96 if (rump_sys_mount(MOUNT_FFS, "/mp", MNT_LOG, &args, sizeof(args))==-1)
97 atf_tc_fail_errno("rump_sys_mount failed");
99 pthread_create(&pt1, NULL, w1, NULL);
100 pthread_create(&pt2, NULL, w2, NULL);
102 sleep(10);
104 quit = 1;
105 pthread_join(pt1, NULL);
106 pthread_join(pt2, NULL);
108 if (rump_sys_unmount("/mp", 0) == -1)
109 atf_tc_fail_errno("unmount failed");
112 ATF_TC_CLEANUP(renamerace, tc)
114 #if 0
115 char *img;
117 img = strrchr(image, '/');
118 if (!img)
119 return;
121 printf("removing %s\n", img+1);
122 unlink(img+1);
123 *img = '\0';
124 rmdir(img);
125 #else
126 unlink(IMAGENAME);
127 #endif
130 ATF_TP_ADD_TCS(tp)
132 ATF_TP_ADD_TC(tp, renamerace);
133 return 0; /* ??? */