Statistics
| Branch: | Revision:

root / tests / tcg / test_path.c @ c09015dd

History | View | Annotate | Download (4.7 kB)

1
/* Test path override code */
2
#include "../config-host.h"
3
#include "../qemu-malloc.c"
4
#include "../cutils.c"
5
#include "../path.c"
6
#include "../trace.c"
7
#ifdef CONFIG_TRACE_SIMPLE
8
#include "../simpletrace.c"
9
#endif
10

    
11
#include <stdarg.h>
12
#include <sys/stat.h>
13
#include <fcntl.h>
14

    
15
void qemu_log(const char *fmt, ...);
16

    
17
/* Any log message kills the test. */
18
void qemu_log(const char *fmt, ...)
19
{
20
    va_list ap;
21

    
22
    fprintf(stderr, "FATAL: ");
23
    va_start(ap, fmt);
24
    vfprintf(stderr, fmt, ap);
25
    va_end(ap);
26
    exit(1);
27
}
28

    
29
#define NO_CHANGE(_path)                                                \
30
        do {                                                                \
31
            if (strcmp(path(_path), _path) != 0) return __LINE__;        \
32
        } while(0)
33

    
34
#define CHANGE_TO(_path, _newpath)                                        \
35
        do {                                                                \
36
            if (strcmp(path(_path), _newpath) != 0) return __LINE__;        \
37
        } while(0)
38

    
39
static void cleanup(void)
40
{
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");
50
}
51

    
52
static unsigned int do_test(void)
53
{
54
    if (mkdir("/tmp/qemu-test_path", 0700) != 0)
55
        return __LINE__;
56

    
57
    if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
58
        return __LINE__;
59

    
60
    if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
61
        return __LINE__;
62

    
63
    if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
64
        return __LINE__;
65

    
66
    if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
67
        return __LINE__;
68

    
69
    if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE2", 0600)) != 0)
70
        return __LINE__;
71

    
72
    if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE3", 0600)) != 0)
73
        return __LINE__;
74

    
75
    if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE4", 0600)) != 0)
76
        return __LINE__;
77

    
78
    if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE5", 0600)) != 0)
79
        return __LINE__;
80

    
81
    init_paths("/tmp/qemu-test_path");
82

    
83
    NO_CHANGE("/tmp");
84
    NO_CHANGE("/tmp/");
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/");
92

    
93
    NO_CHANGE("/D");
94
    NO_CHANGE("/DI");
95
    NO_CHANGE("/DIR");
96
    NO_CHANGE("/DIR2");
97
    NO_CHANGE("/DIR1.");
98

    
99
    CHANGE_TO("/DIR1", "/tmp/qemu-test_path/DIR1");
100
    CHANGE_TO("/DIR1/", "/tmp/qemu-test_path/DIR1");
101

    
102
    NO_CHANGE("/DIR1/D");
103
    NO_CHANGE("/DIR1/DI");
104
    NO_CHANGE("/DIR1/DIR");
105
    NO_CHANGE("/DIR1/DIR1");
106

    
107
    CHANGE_TO("/DIR1/DIR2", "/tmp/qemu-test_path/DIR1/DIR2");
108
    CHANGE_TO("/DIR1/DIR2/", "/tmp/qemu-test_path/DIR1/DIR2");
109

    
110
    CHANGE_TO("/DIR1/DIR3", "/tmp/qemu-test_path/DIR1/DIR3");
111
    CHANGE_TO("/DIR1/DIR3/", "/tmp/qemu-test_path/DIR1/DIR3");
112

    
113
    NO_CHANGE("/DIR1/DIR2/F");
114
    NO_CHANGE("/DIR1/DIR2/FI");
115
    NO_CHANGE("/DIR1/DIR2/FIL");
116
    NO_CHANGE("/DIR1/DIR2/FIL.");
117

    
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");
123

    
124
    NO_CHANGE("/DIR1/DIR2/FILE6");
125
    NO_CHANGE("/DIR1/DIR2/FILE/X");
126

    
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");
134

    
135
    NO_CHANGE("/DIR1/DIR2/../DIR1");
136
    NO_CHANGE("/DIR1/DIR2/../FILE");
137

    
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");
145

    
146
    return 0;
147
}
148

    
149
int main(int argc, char *argv[])
150
{
151
    int ret;
152

    
153
    ret = do_test();
154
    cleanup();
155
    if (ret) {
156
        fprintf(stderr, "test_path: failed on line %i\n", ret);
157
        return 1;
158
    }
159
    return 0;
160
}