]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-fsync.c
3 #include <hfs/hfs_mount.h>
10 #include <TargetConditionals.h>
11 #include <sys/socket.h>
15 #include "hfs-tests.h"
16 #include "test-utils.h"
17 #include "disk-image.h"
19 TEST(fsync
, .run_as_root
= true)
22 volatile bool stop_thread
;
24 void *sync_thread(__unused
void *arg
)
27 assert_no_err(fsync(fd
));
32 int run_fsync(__unused test_ctx_t
*ctx
)
34 disk_image_t
*di
= NULL
;
37 #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
41 assert(statfs("/tmp", &sfs
) == 0);
42 if (strcmp(sfs
.f_fstypename
, "hfs")) {
44 di
= disk_image_get();
45 tstdir
= di
->mount_point
;
50 #else // !TARGET_OS_IPHONE & !SIM
51 di
= disk_image_get();
52 tstdir
= di
->mount_point
;
56 asprintf(&file
, "%s/fsync.data", tstdir
);
60 fd
= open(file
, O_RDWR
| O_CREAT
, 0666);
62 assert_with_errno(fd
>= 0);
65 pthread_create(&thread
, NULL
, sync_thread
, NULL
);
67 void *buf
= valloc(65536);
69 assert_no_err(fcntl(fd
, F_NOCACHE
, 1));
71 struct timeval start
, now
;
72 gettimeofday(&start
, NULL
);
74 check_io(pwrite(fd
, buf
, 65536, 0), 65536);
76 gettimeofday(&now
, NULL
);
77 } while (now
.tv_sec
< start
.tv_sec
+ 10);
80 pthread_join(thread
, NULL
);
82 assert_no_err(close(fd
));
83 assert_no_err(unlink(file
));
85 assert_with_errno((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) >= 0);
87 struct sockaddr_un addr
= {
92 asprintf(&sock
, "%s/socket", tstdir
);
94 strcpy(addr
.sun_path
, sock
);
96 assert_no_err(bind(fd
, (struct sockaddr
*)&addr
, sizeof(addr
)));
100 asprintf(&fifo
, "%s/fifo", tstdir
);
102 assert_no_err(mkfifo(fifo
, 0666));
106 assert_no_err(unlink(sock
));
107 assert_no_err(unlink(fifo
));