1 /* Test path override code */
2 #include "../config-host.h"
3 #include "../qemu-malloc.c"
7 #ifdef CONFIG_SIMPLE_TRACE
8 #include "../simpletrace.c"
15 void qemu_log(const char *fmt
, ...);
17 /* Any log message kills the test. */
18 void qemu_log(const char *fmt
, ...)
22 fprintf(stderr
, "FATAL: ");
24 vfprintf(stderr
, fmt
, ap
);
29 #define NO_CHANGE(_path) \
31 if (strcmp(path(_path), _path) != 0) return __LINE__; \
34 #define CHANGE_TO(_path, _newpath) \
36 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
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)
57 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
60 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
63 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
72 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
75 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
78 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
81 init_paths("/tmp/qemu-test_path");
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/");
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");
149 int main(int argc
, char *argv
[])
156 fprintf(stderr
, "test_path: failed on line %i\n", ret
);