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