1 /* $NetBSD: t_renamerace.c,v 1.13 2011/08/18 21:44:55 riastradh Exp $ */
4 * Modified for rump and atf from a program supplied
5 * by Nicolas Joly in kern/40948
10 #include <sys/utsname.h>
21 #include <rump/rump.h>
22 #include <rump/rump_syscalls.h>
24 #include <fs/tmpfs/tmpfs_args.h>
26 #include "../../h_macros.h"
29 ATF_TC_HEAD(renamerace2, tc)
31 atf_tc_set_md_var(tc, "descr", "rename(2) lock order inversion");
32 atf_tc_set_md_var(tc, "timeout", "6");
35 static volatile int quittingtime = 0;
43 rump_pub_lwproc_newlwp(wrkpid);
45 fd = rump_sys_open("/file", O_CREAT | O_RDWR, 0777);
47 atf_tc_fail_errno("creat");
50 while (!quittingtime) {
51 if (rump_sys_rename("/file", "/dir/file") == -1)
52 atf_tc_fail_errno("rename 1");
53 if (rump_sys_rename("/dir/file", "/file") == -1)
54 atf_tc_fail_errno("rename 2");
65 rump_pub_lwproc_newlwp(wrkpid);
67 while (!quittingtime) {
68 fd = rump_sys_open("/dir/file1", O_RDWR);
76 ATF_TC_BODY(renamerace2, tc)
78 struct tmpfs_args args;
82 * Force SMP regardless of how many host CPUs there are.
83 * Deadlock is highly unlikely to trigger otherwise.
85 setenv("RUMP_NCPU", "2", 1);
88 memset(&args, 0, sizeof(args));
89 args.ta_version = TMPFS_ARGS_VERSION;
90 args.ta_root_mode = 0777;
91 if (rump_sys_mount(MOUNT_TMPFS, "/", 0, &args, sizeof(args)) == -1)
92 atf_tc_fail_errno("could not mount tmpfs");
94 if (rump_sys_mkdir("/dir", 0777) == -1)
95 atf_tc_fail_errno("cannot create directory");
97 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
98 RL(wrkpid = rump_sys_getpid());
99 pthread_create(&pt[0], NULL, r2w1, NULL);
100 pthread_create(&pt[1], NULL, r2w2, NULL);
102 /* usually triggers in <<1s for me */
106 pthread_join(pt[0], NULL);
107 pthread_join(pt[1], NULL);
112 ATF_TP_ADD_TC(tp, renamerace2);
114 return atf_no_error();