sun4m: avoid structure holes spotted by pahole
[qemu/mdroth.git] / tests / test_path.c
blob234ed97088d308eaa947cc970a10f0a33eef07a5
1 /* Test path override code */
2 #include "../config-host.h"
3 #include "../qemu-malloc.c"
4 #include "../cutils.c"
5 #include "../path.c"
6 #include "../trace.c"
7 #ifdef CONFIG_SIMPLE_TRACE
8 #include "../simpletrace.c"
9 #endif
11 #include <stdarg.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
15 void qemu_log(const char *fmt, ...);
17 /* Any log message kills the test. */
18 void qemu_log(const char *fmt, ...)
20 va_list ap;
22 fprintf(stderr, "FATAL: ");
23 va_start(ap, fmt);
24 vfprintf(stderr, fmt, ap);
25 va_end(ap);
26 exit(1);
29 #define NO_CHANGE(_path) \
30 do { \
31 if (strcmp(path(_path), _path) != 0) return __LINE__; \
32 } while(0)
34 #define CHANGE_TO(_path, _newpath) \
35 do { \
36 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
37 } while(0)
39 static void cleanup(void)
41 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE");
42 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2");
43 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3");
44 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4");
45 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5");
46 rmdir("/tmp/qemu-test_path/DIR1/DIR2");
47 rmdir("/tmp/qemu-test_path/DIR1/DIR3");
48 rmdir("/tmp/qemu-test_path/DIR1");
49 rmdir("/tmp/qemu-test_path");
52 static unsigned int do_test(void)
54 if (mkdir("/tmp/qemu-test_path", 0700) != 0)
55 return __LINE__;
57 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
58 return __LINE__;
60 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
61 return __LINE__;
63 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
64 return __LINE__;
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
67 return __LINE__;
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
70 return __LINE__;
72 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
73 return __LINE__;
75 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
76 return __LINE__;
78 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
79 return __LINE__;
81 init_paths("/tmp/qemu-test_path");
83 NO_CHANGE("/tmp");
84 NO_CHANGE("/tmp/");
85 NO_CHANGE("/tmp/qemu-test_path");
86 NO_CHANGE("/tmp/qemu-test_path/");
87 NO_CHANGE("/tmp/qemu-test_path/D");
88 NO_CHANGE("/tmp/qemu-test_path/DI");
89 NO_CHANGE("/tmp/qemu-test_path/DIR");
90 NO_CHANGE("/tmp/qemu-test_path/DIR1");
91 NO_CHANGE("/tmp/qemu-test_path/DIR1/");
93 NO_CHANGE("/D");
94 NO_CHANGE("/DI");
95 NO_CHANGE("/DIR");
96 NO_CHANGE("/DIR2");
97 NO_CHANGE("/DIR1.");
99 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
100 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
102 NO_CHANGE("/DIR1/D");
103 NO_CHANGE("/DIR1/DI");
104 NO_CHANGE("/DIR1/DIR");
105 NO_CHANGE("/DIR1/DIR1");
107 CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
108 CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
110 CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
111 CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
113 NO_CHANGE("/DIR1/DIR2/F");
114 NO_CHANGE("/DIR1/DIR2/FI");
115 NO_CHANGE("/DIR1/DIR2/FIL");
116 NO_CHANGE("/DIR1/DIR2/FIL.");
118 CHANGE_TO("/DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
119 CHANGE_TO("/DIR1/DIR2/FILE2", "/tmp/qemu-test_path/DIR1/DIR2/FILE2");
120 CHANGE_TO("/DIR1/DIR2/FILE3", "/tmp/qemu-test_path/DIR1/DIR2/FILE3");
121 CHANGE_TO("/DIR1/DIR2/FILE4", "/tmp/qemu-test_path/DIR1/DIR2/FILE4");
122 CHANGE_TO("/DIR1/DIR2/FILE5", "/tmp/qemu-test_path/DIR1/DIR2/FILE5");
124 NO_CHANGE("/DIR1/DIR2/FILE6");
125 NO_CHANGE("/DIR1/DIR2/FILE/X");
127 CHANGE_TO("/DIR1/../DIR1", "/tmp/qemu-test_path/DIR1");
128 CHANGE_TO("/DIR1/../DIR1/", "/tmp/qemu-test_path/DIR1");
129 CHANGE_TO("/../DIR1", "/tmp/qemu-test_path/DIR1");
130 CHANGE_TO("/../DIR1/", "/tmp/qemu-test_path/DIR1");
131 CHANGE_TO("/DIR1/DIR2/../DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
132 CHANGE_TO("/DIR1/DIR2/../DIR2/../../DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
133 CHANGE_TO("/DIR1/DIR2/../DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
135 NO_CHANGE("/DIR1/DIR2/../DIR1");
136 NO_CHANGE("/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 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");
146 return 0;
149 int main(int argc, char *argv[])
151 int ret;
153 ret = do_test();
154 cleanup();
155 if (ret) {
156 fprintf(stderr, "test_path: failed on line %i\n", ret);
157 return 1;
159 return 0;