|
1 #ifndef _TESTS_H |
|
2 #define _TESTS_H |
|
3 /* |
|
4 * libfdt - Flat Device Tree manipulation |
|
5 * Testcase definitions |
|
6 * Copyright (C) 2006 David Gibson, IBM Corporation. |
|
7 * |
|
8 * This library is free software; you can redistribute it and/or |
|
9 * modify it under the terms of the GNU Lesser General Public License |
|
10 * as published by the Free Software Foundation; either version 2.1 of |
|
11 * the License, or (at your option) any later version. |
|
12 * |
|
13 * This library is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * Lesser General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU Lesser General Public |
|
19 * License along with this library; if not, write to the Free Software |
|
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 */ |
|
22 |
|
23 #define DEBUG |
|
24 |
|
25 /* Test return codes */ |
|
26 #define RC_PASS 0 |
|
27 #define RC_CONFIG 1 |
|
28 #define RC_FAIL 2 |
|
29 #define RC_BUG 99 |
|
30 |
|
31 extern int verbose_test; |
|
32 extern char *test_name; |
|
33 void test_init(int argc, char *argv[]); |
|
34 |
|
35 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) |
|
36 #define PALIGN(p, a) ((void *)ALIGN((unsigned long)(p), (a))) |
|
37 |
|
38 #define streq(s1, s2) (strcmp((s1),(s2)) == 0) |
|
39 |
|
40 /* Each test case must define this function */ |
|
41 void cleanup(void); |
|
42 |
|
43 #define verbose_printf(...) \ |
|
44 if (verbose_test) { \ |
|
45 printf(__VA_ARGS__); \ |
|
46 fflush(stdout); \ |
|
47 } |
|
48 #define ERR "ERR: " |
|
49 #define ERROR(fmt, args...) fprintf(stderr, ERR fmt, ## args) |
|
50 |
|
51 |
|
52 #define PASS() \ |
|
53 do { \ |
|
54 cleanup(); \ |
|
55 printf("PASS\n"); \ |
|
56 exit(RC_PASS); \ |
|
57 } while (0) |
|
58 |
|
59 #define PASS_INCONCLUSIVE() \ |
|
60 do { \ |
|
61 cleanup(); \ |
|
62 printf("PASS (inconclusive)\n"); \ |
|
63 exit(RC_PASS); \ |
|
64 } while (0) |
|
65 |
|
66 #define IRRELEVANT() \ |
|
67 do { \ |
|
68 cleanup(); \ |
|
69 printf("PASS (irrelevant)\n"); \ |
|
70 exit(RC_PASS); \ |
|
71 } while (0) |
|
72 |
|
73 /* Look out, gcc extension below... */ |
|
74 #define FAIL(fmt, ...) \ |
|
75 do { \ |
|
76 cleanup(); \ |
|
77 printf("FAIL\t" fmt "\n", ##__VA_ARGS__); \ |
|
78 exit(RC_FAIL); \ |
|
79 } while (0) |
|
80 |
|
81 #define CONFIG(fmt, ...) \ |
|
82 do { \ |
|
83 cleanup(); \ |
|
84 printf("Bad configuration: " fmt "\n", ##__VA_ARGS__); \ |
|
85 exit(RC_CONFIG); \ |
|
86 } while (0) |
|
87 |
|
88 #define TEST_BUG(fmt, ...) \ |
|
89 do { \ |
|
90 cleanup(); \ |
|
91 printf("BUG in testsuite: " fmt "\n", ##__VA_ARGS__); \ |
|
92 exit(RC_BUG); \ |
|
93 } while (0) |
|
94 |
|
95 static inline void *xmalloc(size_t size) |
|
96 { |
|
97 void *p = malloc(size); |
|
98 if (! p) |
|
99 FAIL("malloc() failure"); |
|
100 return p; |
|
101 } |
|
102 |
|
103 static inline void *xrealloc(void *p, size_t size) |
|
104 { |
|
105 p = realloc(p, size); |
|
106 if (! p) |
|
107 FAIL("realloc() failure"); |
|
108 return p; |
|
109 } |
|
110 |
|
111 void check_mem_rsv(void *fdt, int n, uint64_t addr, uint64_t size); |
|
112 |
|
113 void check_property(void *fdt, int nodeoffset, const char *name, |
|
114 int len, const void *val); |
|
115 #define check_property_cell(fdt, nodeoffset, name, val) \ |
|
116 ({ \ |
|
117 uint32_t x = cpu_to_fdt32(val); \ |
|
118 check_property(fdt, nodeoffset, name, sizeof(x), &x); \ |
|
119 }) |
|
120 |
|
121 |
|
122 const void *check_getprop(void *fdt, int nodeoffset, const char *name, |
|
123 int len, const void *val); |
|
124 #define check_getprop_cell(fdt, nodeoffset, name, val) \ |
|
125 ({ \ |
|
126 uint32_t x = cpu_to_fdt32(val); \ |
|
127 check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \ |
|
128 }) |
|
129 #define check_getprop_string(fdt, nodeoffset, name, s) \ |
|
130 check_getprop((fdt), (nodeoffset), (name), strlen(s)+1, (s)) |
|
131 int nodename_eq(const char *s1, const char *s2); |
|
132 void *load_blob(const char *filename); |
|
133 void *load_blob_arg(int argc, char *argv[]); |
|
134 void save_blob(const char *filename, void *blob); |
|
135 void *open_blob_rw(void *blob); |
|
136 |
|
137 #endif /* _TESTS_H */ |