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 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 38 39 #define streq(s1, s2) (strcmp((s1),(s2)) == 0) 40 41 /* Each test case must define this function */ 42 void cleanup(void); 43 44 #define verbose_printf(...) \ 45 if (verbose_test) { \ 46 printf(__VA_ARGS__); \ 47 fflush(stdout); \ 48 } 49 #define ERR "ERR: " 50 #define ERROR(fmt, args...) fprintf(stderr, ERR fmt, ## args) 51 52 53 #define PASS() \ 54 do { \ 55 cleanup(); \ 56 printf("PASS\n"); \ 57 exit(RC_PASS); \ 58 } while (0) 59 60 #define PASS_INCONCLUSIVE() \ 61 do { \ 62 cleanup(); \ 63 printf("PASS (inconclusive)\n"); \ 64 exit(RC_PASS); \ 65 } while (0) 66 67 #define IRRELEVANT() \ 68 do { \ 69 cleanup(); \ 70 printf("PASS (irrelevant)\n"); \ 71 exit(RC_PASS); \ 72 } while (0) 73 74 /* Look out, gcc extension below... */ 75 #define FAIL(fmt, ...) \ 76 do { \ 77 cleanup(); \ 78 printf("FAIL\t" fmt "\n", ##__VA_ARGS__); \ 79 exit(RC_FAIL); \ 80 } while (0) 81 82 #define CONFIG(fmt, ...) \ 83 do { \ 84 cleanup(); \ 85 printf("Bad configuration: " fmt "\n", ##__VA_ARGS__); \ 86 exit(RC_CONFIG); \ 87 } while (0) 88 89 #define TEST_BUG(fmt, ...) \ 90 do { \ 91 cleanup(); \ 92 printf("BUG in testsuite: " fmt "\n", ##__VA_ARGS__); \ 93 exit(RC_BUG); \ 94 } while (0) 95 96 void check_mem_rsv(void *fdt, int n, uint64_t addr, uint64_t size); 97 98 void check_property(void *fdt, int nodeoffset, const char *name, 99 int len, const void *val); 100 #define check_property_cell(fdt, nodeoffset, name, val) \ 101 ({ \ 102 fdt32_t x = cpu_to_fdt32(val); \ 103 check_property(fdt, nodeoffset, name, sizeof(x), &x); \ 104 }) 105 106 107 const void *check_getprop(void *fdt, int nodeoffset, const char *name, 108 int len, const void *val); 109 #define check_getprop_cell(fdt, nodeoffset, name, val) \ 110 ({ \ 111 fdt32_t x = cpu_to_fdt32(val); \ 112 check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \ 113 }) 114 #define check_getprop_64(fdt, nodeoffset, name, val) \ 115 ({ \ 116 fdt64_t x = cpu_to_fdt64(val); \ 117 check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \ 118 }) 119 #define check_getprop_string(fdt, nodeoffset, name, s) \ 120 check_getprop((fdt), (nodeoffset), (name), strlen(s)+1, (s)) 121 int nodename_eq(const char *s1, const char *s2); 122 void *load_blob(const char *filename); 123 void *load_blob_arg(int argc, char *argv[]); 124 void save_blob(const char *filename, void *blob); 125 void *open_blob_rw(void *blob); 126 127 #include "util.h" 128 129 #endif /* _TESTS_H */ 130