1 /* $NetBSD: t_renamerace.c,v 1.7 2009/08/03 14:25:24 pooka Exp $ */
4 * Modified for rump and atf from a program supplied
5 * by Nicolas Joly in kern/40948
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");
44 fd
= rump_sys_open("/mp/rename.test1",
45 O_WRONLY
|O_CREAT
|O_TRUNC
, 0666);
46 rump_sys_unlink("/mp/rename.test1");
57 rump_sys_rename("/mp/rename.test1", "/mp/rename.test2");
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
)
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");
80 strcpy(image
, IMAGENAME
);
83 strcpy(cmd
, "newfs -F -s 10000 ");
86 if (system(cmd
) == -1)
87 atf_tc_fail_errno("newfs failed");
89 memset(&args
, 0, sizeof(args
));
90 args
.fspec
= __UNCONST(FAKEBLK
);
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
);
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
)
117 img
= strrchr(image
, '/');
121 printf("removing %s\n", img
+1);
132 ATF_TP_ADD_TC(tp
, renamerace
);