hw/omap1.c: Add fallthrough markers and breaks
[qemu/pbrook.git] / tests / tcg / test_path.c
bloba064eea8fb989e351046710d2d64883d8205c1c4
1 /* Test path override code */
2 #define _GNU_SOURCE
3 #include "config-host.h"
4 #include "iov.c"
5 #include "cutils.c"
6 #include "path.c"
7 #include "trace.c"
8 #ifdef CONFIG_TRACE_SIMPLE
9 #include "../trace/simple.c"
10 #endif
12 #include <stdarg.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
16 void qemu_log(const char *fmt, ...);
18 /* Any log message kills the test. */
19 void qemu_log(const char *fmt, ...)
21 va_list ap;
23 fprintf(stderr, "FATAL: ");
24 va_start(ap, fmt);
25 vfprintf(stderr, fmt, ap);
26 va_end(ap);
27 exit(1);
30 #define NO_CHANGE(_path) \
31 do { \
32 if (strcmp(path(_path), _path) != 0) return __LINE__; \
33 } while(0)
35 #define CHANGE_TO(_path, _newpath) \
36 do { \
37 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
38 } while(0)
40 static void cleanup(void)
42 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE");
43 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2");
44 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3");
45 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4");
46 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5");
47 rmdir("/tmp/qemu-test_path/DIR1/DIR2");
48 rmdir("/tmp/qemu-test_path/DIR1/DIR3");
49 rmdir("/tmp/qemu-test_path/DIR1");
50 rmdir("/tmp/qemu-test_path");
53 static unsigned int do_test(void)
55 if (mkdir("/tmp/qemu-test_path", 0700) != 0)
56 return __LINE__;
58 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
59 return __LINE__;
61 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
62 return __LINE__;
64 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
65 return __LINE__;
67 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
68 return __LINE__;
70 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
71 return __LINE__;
73 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
74 return __LINE__;
76 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
77 return __LINE__;
79 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
80 return __LINE__;
82 init_paths("/tmp/qemu-test_path");
84 NO_CHANGE("/tmp");
85 NO_CHANGE("/tmp/");
86 NO_CHANGE("/tmp/qemu-test_path");
87 NO_CHANGE("/tmp/qemu-test_path/");
88 NO_CHANGE("/tmp/qemu-test_path/D");
89 NO_CHANGE("/tmp/qemu-test_path/DI");
90 NO_CHANGE("/tmp/qemu-test_path/DIR");
91 NO_CHANGE("/tmp/qemu-test_path/DIR1");
92 NO_CHANGE("/tmp/qemu-test_path/DIR1/");
94 NO_CHANGE("/D");
95 NO_CHANGE("/DI");
96 NO_CHANGE("/DIR");
97 NO_CHANGE("/DIR2");
98 NO_CHANGE("/DIR1.");
100 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
101 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
103 NO_CHANGE("/DIR1/D");
104 NO_CHANGE("/DIR1/DI");
105 NO_CHANGE("/DIR1/DIR");
106 NO_CHANGE("/DIR1/DIR1");
108 CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
109 CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
111 CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
112 CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
114 NO_CHANGE("/DIR1/DIR2/F");
115 NO_CHANGE("/DIR1/DIR2/FI");
116 NO_CHANGE("/DIR1/DIR2/FIL");
117 NO_CHANGE("/DIR1/DIR2/FIL.");
119 CHANGE_TO("/DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
120 CHANGE_TO("/DIR1/DIR2/FILE2", "/tmp/qemu-test_path/DIR1/DIR2/FILE2");
121 CHANGE_TO("/DIR1/DIR2/FILE3", "/tmp/qemu-test_path/DIR1/DIR2/FILE3");
122 CHANGE_TO("/DIR1/DIR2/FILE4", "/tmp/qemu-test_path/DIR1/DIR2/FILE4");
123 CHANGE_TO("/DIR1/DIR2/FILE5", "/tmp/qemu-test_path/DIR1/DIR2/FILE5");
125 NO_CHANGE("/DIR1/DIR2/FILE6");
126 NO_CHANGE("/DIR1/DIR2/FILE/X");
128 CHANGE_TO("/DIR1/../DIR1", "/tmp/qemu-test_path/DIR1");
129 CHANGE_TO("/DIR1/../DIR1/", "/tmp/qemu-test_path/DIR1");
130 CHANGE_TO("/../DIR1", "/tmp/qemu-test_path/DIR1");
131 CHANGE_TO("/../DIR1/", "/tmp/qemu-test_path/DIR1");
132 CHANGE_TO("/DIR1/DIR2/../DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
133 CHANGE_TO("/DIR1/DIR2/../DIR2/../../DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
134 CHANGE_TO("/DIR1/DIR2/../DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
136 NO_CHANGE("/DIR1/DIR2/../DIR1");
137 NO_CHANGE("/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 CHANGE_TO("/DIR1/././DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
143 CHANGE_TO("/DIR1/DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
144 CHANGE_TO("/DIR1/DIR2/././FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
145 CHANGE_TO("/./DIR1/./DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
147 return 0;
150 int main(int argc, char *argv[])
152 int ret;
154 ret = do_test();
155 cleanup();
156 if (ret) {
157 fprintf(stderr, "test_path: failed on line %i\n", ret);
158 return 1;
160 return 0;