block: use the block job list in qmp_query_block_jobs()
[qemu/ar7.git] / tests / tcg / test_path.c
blob1c29bce263f345f1ad65a8d01a12d46bf59ce092
1 /* Test path override code */
2 #include "config-host.h"
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"
8 #include <stdarg.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
12 void qemu_log(const char *fmt, ...);
14 /* Any log message kills the test. */
15 void qemu_log(const char *fmt, ...)
17 va_list ap;
19 fprintf(stderr, "FATAL: ");
20 va_start(ap, fmt);
21 vfprintf(stderr, fmt, ap);
22 va_end(ap);
23 exit(1);
26 #define NO_CHANGE(_path) \
27 do { \
28 if (strcmp(path(_path), _path) != 0) return __LINE__; \
29 } while(0)
31 #define CHANGE_TO(_path, _newpath) \
32 do { \
33 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
34 } while(0)
36 static void cleanup(void)
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");
49 static unsigned int do_test(void)
51 if (mkdir("/tmp/qemu-test_path", 0700) != 0)
52 return __LINE__;
54 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
55 return __LINE__;
57 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
58 return __LINE__;
60 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
61 return __LINE__;
63 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
64 return __LINE__;
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
67 return __LINE__;
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
70 return __LINE__;
72 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
73 return __LINE__;
75 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
76 return __LINE__;
78 init_paths("/tmp/qemu-test_path");
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/");
90 NO_CHANGE("/D");
91 NO_CHANGE("/DI");
92 NO_CHANGE("/DIR");
93 NO_CHANGE("/DIR2");
94 NO_CHANGE("/DIR1.");
96 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
97 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
99 NO_CHANGE("/DIR1/D");
100 NO_CHANGE("/DIR1/DI");
101 NO_CHANGE("/DIR1/DIR");
102 NO_CHANGE("/DIR1/DIR1");
104 CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
105 CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
107 CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
108 CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
110 NO_CHANGE("/DIR1/DIR2/F");
111 NO_CHANGE("/DIR1/DIR2/FI");
112 NO_CHANGE("/DIR1/DIR2/FIL");
113 NO_CHANGE("/DIR1/DIR2/FIL.");
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");
121 NO_CHANGE("/DIR1/DIR2/FILE6");
122 NO_CHANGE("/DIR1/DIR2/FILE/X");
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");
132 NO_CHANGE("/DIR1/DIR2/../DIR1");
133 NO_CHANGE("/DIR1/DIR2/../FILE");
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");
143 return 0;
146 int main(int argc, char *argv[])
148 int ret;
150 ret = do_test();
151 cleanup();
152 if (ret) {
153 fprintf(stderr, "test_path: failed on line %i\n", ret);
154 return 1;
156 return 0;