1 /* Test path override code */
2 #include "config-host.h"
3 #include "util/cutils.c"
4 #include "util/hexdump.c"
7 #include "util/qemu-timer-common.c"
12 void qemu_log(const char *fmt
, ...);
14 /* Any log message kills the test. */
15 void qemu_log(const char *fmt
, ...)
19 fprintf(stderr
, "FATAL: ");
21 vfprintf(stderr
, fmt
, ap
);
26 #define NO_CHANGE(_path) \
28 if (strcmp(path(_path), _path) != 0) return __LINE__; \
31 #define CHANGE_TO(_path, _newpath) \
33 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
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)
54 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
57 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
60 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
63 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
72 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
75 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
78 init_paths("/tmp/qemu-test_path");
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/");
96 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
97 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
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");
146 int main(int argc
, char *argv
[])
153 fprintf(stderr
, "test_path: failed on line %i\n", ret
);