1 /* Test path override code */
8 /* Any log message kills the test. */
9 void gemu_log(const char *fmt
, ...)
13 fprintf(stderr
, "FATAL: ");
15 vfprintf(stderr
, fmt
, ap
);
20 #define NO_CHANGE(_path) \
22 if (strcmp(path(_path), _path) != 0) return __LINE__; \
25 #define CHANGE_TO(_path, _newpath) \
27 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
30 static void cleanup(void)
32 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE");
33 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2");
34 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3");
35 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4");
36 unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5");
37 rmdir("/tmp/qemu-test_path/DIR1/DIR2");
38 rmdir("/tmp/qemu-test_path/DIR1/DIR3");
39 rmdir("/tmp/qemu-test_path/DIR1");
40 rmdir("/tmp/qemu-test_path");
43 static unsigned int do_test(void)
45 if (mkdir("/tmp/qemu-test_path", 0700) != 0)
48 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
51 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
54 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
57 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
60 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
63 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
72 init_paths("/tmp/qemu-test_path");
76 NO_CHANGE("/tmp/qemu-test_path");
77 NO_CHANGE("/tmp/qemu-test_path/");
78 NO_CHANGE("/tmp/qemu-test_path/D");
79 NO_CHANGE("/tmp/qemu-test_path/DI");
80 NO_CHANGE("/tmp/qemu-test_path/DIR");
81 NO_CHANGE("/tmp/qemu-test_path/DIR1");
82 NO_CHANGE("/tmp/qemu-test_path/DIR1/");
90 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
91 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
94 NO_CHANGE("/DIR1/DI");
95 NO_CHANGE("/DIR1/DIR");
96 NO_CHANGE("/DIR1/DIR1");
98 CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
99 CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
101 CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
102 CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
104 NO_CHANGE("/DIR1/DIR2/F");
105 NO_CHANGE("/DIR1/DIR2/FI");
106 NO_CHANGE("/DIR1/DIR2/FIL");
107 NO_CHANGE("/DIR1/DIR2/FIL.");
109 CHANGE_TO("/DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
110 CHANGE_TO("/DIR1/DIR2/FILE2", "/tmp/qemu-test_path/DIR1/DIR2/FILE2");
111 CHANGE_TO("/DIR1/DIR2/FILE3", "/tmp/qemu-test_path/DIR1/DIR2/FILE3");
112 CHANGE_TO("/DIR1/DIR2/FILE4", "/tmp/qemu-test_path/DIR1/DIR2/FILE4");
113 CHANGE_TO("/DIR1/DIR2/FILE5", "/tmp/qemu-test_path/DIR1/DIR2/FILE5");
115 NO_CHANGE("/DIR1/DIR2/FILE6");
116 NO_CHANGE("/DIR1/DIR2/FILE/X");
118 CHANGE_TO("/DIR1/../DIR1", "/tmp/qemu-test_path/DIR1");
119 CHANGE_TO("/DIR1/../DIR1/", "/tmp/qemu-test_path/DIR1");
120 CHANGE_TO("/../DIR1", "/tmp/qemu-test_path/DIR1");
121 CHANGE_TO("/../DIR1/", "/tmp/qemu-test_path/DIR1");
122 CHANGE_TO("/DIR1/DIR2/../DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
123 CHANGE_TO("/DIR1/DIR2/../DIR2/../../DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
124 CHANGE_TO("/DIR1/DIR2/../DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
126 NO_CHANGE("/DIR1/DIR2/../DIR1");
127 NO_CHANGE("/DIR1/DIR2/../FILE");
129 CHANGE_TO("/./DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
130 CHANGE_TO("/././DIR1/DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
131 CHANGE_TO("/DIR1/./DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
132 CHANGE_TO("/DIR1/././DIR2/FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
133 CHANGE_TO("/DIR1/DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
134 CHANGE_TO("/DIR1/DIR2/././FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
135 CHANGE_TO("/./DIR1/./DIR2/./FILE", "/tmp/qemu-test_path/DIR1/DIR2/FILE");
140 int main(int argc
, char *argv
[])
147 fprintf(stderr
, "test_path: failed on line %i\n", ret
);