1 /* Test path override code */
3 #include "config-host.h"
8 #ifdef CONFIG_TRACE_SIMPLE
9 #include "../trace/simple.c"
16 void qemu_log(const char *fmt
, ...);
18 /* Any log message kills the test. */
19 void qemu_log(const char *fmt
, ...)
23 fprintf(stderr
, "FATAL: ");
25 vfprintf(stderr
, fmt
, ap
);
30 #define NO_CHANGE(_path) \
32 if (strcmp(path(_path), _path) != 0) return __LINE__; \
35 #define CHANGE_TO(_path, _newpath) \
37 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
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)
58 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
61 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
64 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
67 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
70 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
73 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
76 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
79 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
82 init_paths("/tmp/qemu-test_path");
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/");
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");
150 int main(int argc
, char *argv
[])
157 fprintf(stderr
, "test_path: failed on line %i\n", ret
);