]>
Commit | Line | Data |
---|---|---|
1 | #include <TargetConditionals.h> | |
2 | ||
3 | #if !TARGET_OS_EMBEDDED | |
4 | ||
5 | #include <unistd.h> | |
6 | #include <pthread.h> | |
7 | ||
8 | #include "hfs-tests.h" | |
9 | #include "test-utils.h" | |
10 | #include "disk-image.h" | |
11 | #include "systemx.h" | |
12 | ||
13 | TEST(journal_toggle) | |
14 | ||
15 | #define DMG "/tmp/journal-toggle.sparseimage" | |
16 | ||
17 | static disk_image_t *di; | |
18 | static volatile bool run = true; | |
19 | ||
20 | void *thread1func(__unused void *arg) | |
21 | { | |
22 | char *file; | |
23 | ||
24 | asprintf(&file, "%s/file", di->mount_point); | |
25 | ||
26 | while (run) { | |
27 | assert(!systemx("/usr/bin/touch", file, NULL)); | |
28 | assert(!systemx("/bin/rm", file, NULL)); | |
29 | } | |
30 | ||
31 | pthread_exit(NULL); | |
32 | } | |
33 | ||
34 | void *thread2func(__unused void *arg) | |
35 | { | |
36 | while (run) { | |
37 | assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "disableJournal", di->mount_point, NULL)); | |
38 | assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "enableJournal", di->mount_point, NULL)); | |
39 | } | |
40 | ||
41 | pthread_exit(NULL); | |
42 | } | |
43 | ||
44 | int run_journal_toggle(__unused test_ctx_t *ctx) | |
45 | { | |
46 | di = disk_image_create(DMG, &(disk_image_opts_t){ | |
47 | .size = 32 * 1024 * 1024 | |
48 | }); | |
49 | ||
50 | pthread_t thread1, thread2; | |
51 | assert(!pthread_create(&thread1, NULL, thread1func, NULL)); | |
52 | assert(!pthread_create(&thread2, NULL, thread2func, NULL)); | |
53 | ||
54 | sleep(10); | |
55 | ||
56 | run = false; | |
57 | ||
58 | void *ret1, *ret2; | |
59 | assert(!pthread_join(thread1, &ret1)); | |
60 | assert(!pthread_join(thread2, &ret2)); | |
61 | ||
62 | return 0; | |
63 | } | |
64 | ||
65 | #endif // !TARGET_OS_EMBEDDED |