Make get_ticks_per_sec() a static inline
[armpft.git] / tests / test_path.c
blobdef7441c8cb64c76ee78d08a2d8473c4b7fe110e
1 /* Test path override code */
2 #define _GNU_SOURCE
3 #include "../path.c"
4 #include <stdarg.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
8 /* Any log message kills the test. */
9 void gemu_log(const char *fmt, ...)
11 va_list ap;
13 fprintf(stderr, "FATAL: ");
14 va_start(ap, fmt);
15 vfprintf(stderr, fmt, ap);
16 va_end(ap);
17 exit(1);
20 #define NO_CHANGE(_path) \
21 do { \
22 if (strcmp(path(_path), _path) != 0) return __LINE__; \
23 } while(0)
25 #define CHANGE_TO(_path, _newpath) \
26 do { \
27 if (strcmp(path(_path), _newpath) != 0) return __LINE__; \
28 } while(0)
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)
46 return __LINE__;
48 if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
49 return __LINE__;
51 if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
52 return __LINE__;
54 if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
55 return __LINE__;
57 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
58 return __LINE__;
60 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
61 return __LINE__;
63 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
64 return __LINE__;
66 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
67 return __LINE__;
69 if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
70 return __LINE__;
72 init_paths("/tmp/qemu-test_path");
74 NO_CHANGE("/tmp");
75 NO_CHANGE("/tmp/");
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/");
84 NO_CHANGE("/D");
85 NO_CHANGE("/DI");
86 NO_CHANGE("/DIR");
87 NO_CHANGE("/DIR2");
88 NO_CHANGE("/DIR1.");
90 CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
91 CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
93 NO_CHANGE("/DIR1/D");
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");
137 return 0;
140 int main(int argc, char *argv[])
142 int ret;
144 ret = do_test();
145 cleanup();
146 if (ret) {
147 fprintf(stderr, "test_path: failed on line %i\n", ret);
148 return 1;
150 return 0;