]> git.saurik.com Git - apple/hfs.git/blame - tests/cases/test-dir-link.c
hfs-366.70.1.tar.gz
[apple/hfs.git] / tests / cases / test-dir-link.c
CommitLineData
558d2836
A
1#include <TargetConditionals.h>
2
3#if !TARGET_OS_EMBEDDED
4
5#include <sys/stat.h>
6#include <pthread.h>
7#include <unistd.h>
8#include <stdio.h>
9#include <spawn.h>
10#include <sys/time.h>
11
12#include "hfs-tests.h"
13#include "test-utils.h"
14#include "systemx.h"
15#include "disk-image.h"
16
17TEST(dir_link)
18
19static disk_image_t *di;
20static char *dir1, *dir2;
21
22static volatile bool stop_thread;
23
24void *thread(__unused void *arg)
25{
26 char *path1, *path2;
27 asprintf(&path1, "%s/dir1/..", dir1);
28 asprintf(&path2, "%s/Dir1/..", dir1);
29
30 struct stat sb;
31 while (!stop_thread) {
32 assert_no_err(stat(path1, &sb));
33 assert_no_err(stat(path2, &sb));
34 }
35
36 free(path1);
37 free(path2);
38
39 return NULL;
40}
41
42int run_dir_link(__unused test_ctx_t *ctx)
43{
44 di = disk_image_get();
45
46 char *tstdir;
47 asprintf(&tstdir, "%s/tmp", di->mount_point);
48
49 assert(!mkdir(tstdir, 0777) || errno == EEXIST);
50
51 asprintf(&dir1, "%s/dir1", tstdir);
52 asprintf(&dir2, "%s/dir2", tstdir);
53
54 systemx("/bin/rm", "-rf", dir1, NULL);
55 systemx("/bin/rm", "-rf", dir2, NULL);
56
57 char *dir1dir1;
58 asprintf(&dir1dir1, "%s/dir1", dir1);
59
60 assert_no_err(mkdir(dir1, 0777));
61 assert_no_err(mkdir(dir1dir1, 0777));
62
63 pthread_t thread_id;
64 pthread_create(&thread_id, NULL, thread, NULL);
65
66 struct stat sb;
67 struct timeval start, now, elapsed;
68
69 gettimeofday(&start, NULL);
70
71 char *path1, *path2;
72 asprintf(&path1, "%s/dir2/..", tstdir);
73 asprintf(&path2, "%s/Dir2/..", tstdir);
74
75 do {
76 assert_no_err(link(dir1dir1, dir2));
77 assert_no_err(stat(path1, &sb));
78 assert_no_err(stat(path2, &sb));
79 assert_no_err(rmdir(dir2));
80
81 gettimeofday(&now, NULL);
82
83 timersub(&now, &start, &elapsed);
84 } while (elapsed.tv_sec < 10);
85
86 stop_thread = true;
87
88 pthread_join(thread_id, NULL);
89
90 assert_no_err(rmdir(dir1dir1));
91 assert_no_err(rmdir(dir1));
92
93 free(dir1);
94 free(dir2);
95 free(dir1dir1);
96 free(path1);
97 free(path2);
98
99 return 0;
100}
101
102#endif // !TARGET_OS_EMBEDDED