]>
Commit | Line | Data |
---|---|---|
7fb9a24e | 1 | /* Test path override code */ |
f62cb1b6 | 2 | #include "config-host.h" |
6d4adef4 SW |
3 | #include "util/cutils.c" |
4 | #include "util/hexdump.c" | |
5 | #include "util/iov.c" | |
6 | #include "util/path.c" | |
7 | #include "util/qemu-timer-common.c" | |
7fb9a24e FB |
8 | #include <stdarg.h> |
9 | #include <sys/stat.h> | |
10 | #include <fcntl.h> | |
11 | ||
48118b02 PB |
12 | void qemu_log(const char *fmt, ...); |
13 | ||
7fb9a24e | 14 | /* Any log message kills the test. */ |
48118b02 | 15 | void qemu_log(const char *fmt, ...) |
7fb9a24e FB |
16 | { |
17 | va_list ap; | |
18 | ||
19 | fprintf(stderr, "FATAL: "); | |
20 | va_start(ap, fmt); | |
21 | vfprintf(stderr, fmt, ap); | |
22 | va_end(ap); | |
23 | exit(1); | |
24 | } | |
25 | ||
26 | #define NO_CHANGE(_path) \ | |
27 | do { \ | |
28 | if (strcmp(path(_path), _path) != 0) return __LINE__; \ | |
29 | } while(0) | |
30 | ||
31 | #define CHANGE_TO(_path, _newpath) \ | |
32 | do { \ | |
33 | if (strcmp(path(_path), _newpath) != 0) return __LINE__; \ | |
34 | } while(0) | |
35 | ||
36 | static void cleanup(void) | |
37 | { | |
38 | unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
39 | unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2"); | |
40 | unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3"); | |
41 | unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4"); | |
42 | unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5"); | |
43 | rmdir("/tmp/qemu-test_path/DIR1/DIR2"); | |
44 | rmdir("/tmp/qemu-test_path/DIR1/DIR3"); | |
45 | rmdir("/tmp/qemu-test_path/DIR1"); | |
46 | rmdir("/tmp/qemu-test_path"); | |
47 | } | |
48 | ||
49 | static unsigned int do_test(void) | |
50 | { | |
51 | if (mkdir("/tmp/qemu-test_path", 0700) != 0) | |
52 | return __LINE__; | |
53 | ||
54 | if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0) | |
55 | return __LINE__; | |
56 | ||
57 | if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0) | |
58 | return __LINE__; | |
59 | ||
60 | if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0) | |
61 | return __LINE__; | |
62 | ||
63 | if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0) | |
64 | return __LINE__; | |
65 | ||
66 | if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0) | |
67 | return __LINE__; | |
68 | ||
69 | if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0) | |
70 | return __LINE__; | |
71 | ||
72 | if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0) | |
73 | return __LINE__; | |
74 | ||
75 | if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0) | |
76 | return __LINE__; | |
77 | ||
78 | init_paths("/tmp/qemu-test_path"); | |
79 | ||
80 | NO_CHANGE("/tmp"); | |
81 | NO_CHANGE("/tmp/"); | |
82 | NO_CHANGE("/tmp/qemu-test_path"); | |
83 | NO_CHANGE("/tmp/qemu-test_path/"); | |
84 | NO_CHANGE("/tmp/qemu-test_path/D"); | |
85 | NO_CHANGE("/tmp/qemu-test_path/DI"); | |
86 | NO_CHANGE("/tmp/qemu-test_path/DIR"); | |
87 | NO_CHANGE("/tmp/qemu-test_path/DIR1"); | |
88 | NO_CHANGE("/tmp/qemu-test_path/DIR1/"); | |
89 | ||
90 | NO_CHANGE("/D"); | |
91 | NO_CHANGE("/DI"); | |
92 | NO_CHANGE("/DIR"); | |
93 | NO_CHANGE("/DIR2"); | |
94 | NO_CHANGE("/DIR1."); | |
95 | ||
96 | CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1"); | |
97 | CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1"); | |
98 | ||
99 | NO_CHANGE("/DIR1/D"); | |
100 | NO_CHANGE("/DIR1/DI"); | |
101 | NO_CHANGE("/DIR1/DIR"); | |
102 | NO_CHANGE("/DIR1/DIR1"); | |
103 | ||
104 | CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2"); | |
105 | CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2"); | |
106 | ||
107 | CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3"); | |
108 | CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3"); | |
109 | ||
110 | NO_CHANGE("/DIR1/DIR2/F"); | |
111 | NO_CHANGE("/DIR1/DIR2/FI"); | |
112 | NO_CHANGE("/DIR1/DIR2/FIL"); | |
113 | NO_CHANGE("/DIR1/DIR2/FIL."); | |
114 | ||
115 | CHANGE_TO("/DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
116 | CHANGE_TO("/DIR1/DIR2/FILE2", "/tmp/qemu-test_path/DIR1/DIR2/FILE2"); | |
117 | CHANGE_TO("/DIR1/DIR2/FILE3", "/tmp/qemu-test_path/DIR1/DIR2/FILE3"); | |
118 | CHANGE_TO("/DIR1/DIR2/FILE4", "/tmp/qemu-test_path/DIR1/DIR2/FILE4"); | |
119 | CHANGE_TO("/DIR1/DIR2/FILE5", "/tmp/qemu-test_path/DIR1/DIR2/FILE5"); | |
120 | ||
121 | NO_CHANGE("/DIR1/DIR2/FILE6"); | |
122 | NO_CHANGE("/DIR1/DIR2/FILE/X"); | |
123 | ||
124 | CHANGE_TO("/DIR1/../DIR1", "/tmp/qemu-test_path/DIR1"); | |
125 | CHANGE_TO("/DIR1/../DIR1/", "/tmp/qemu-test_path/DIR1"); | |
126 | CHANGE_TO("/../DIR1", "/tmp/qemu-test_path/DIR1"); | |
127 | CHANGE_TO("/../DIR1/", "/tmp/qemu-test_path/DIR1"); | |
128 | CHANGE_TO("/DIR1/DIR2/../DIR2", "/tmp/qemu-test_path/DIR1/DIR2"); | |
129 | CHANGE_TO("/DIR1/DIR2/../DIR2/../../DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
130 | CHANGE_TO("/DIR1/DIR2/../DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
131 | ||
132 | NO_CHANGE("/DIR1/DIR2/../DIR1"); | |
133 | NO_CHANGE("/DIR1/DIR2/../FILE"); | |
134 | ||
135 | CHANGE_TO("/./DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
136 | CHANGE_TO("/././DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
137 | CHANGE_TO("/DIR1/./DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
138 | CHANGE_TO("/DIR1/././DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
139 | CHANGE_TO("/DIR1/DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
140 | CHANGE_TO("/DIR1/DIR2/././FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
141 | CHANGE_TO("/./DIR1/./DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE"); | |
142 | ||
143 | return 0; | |
144 | } | |
145 | ||
146 | int main(int argc, char *argv[]) | |
147 | { | |
148 | int ret; | |
149 | ||
150 | ret = do_test(); | |
151 | cleanup(); | |
152 | if (ret) { | |
153 | fprintf(stderr, "test_path: failed on line %i\n", ret); | |
154 | return 1; | |
155 | } | |
156 | return 0; | |
157 | } |