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