1 /* $NetBSD: check_full.c,v 1.1.1.1 2019/12/22 12:34:06 skrll Exp $ */ 2 3 // SPDX-License-Identifier: LGPL-2.1-or-later 4 /* 5 * libfdt - Flat Device Tree manipulation 6 * Tests if two given dtbs are structurally equal (including order) 7 * Copyright (C) 2007 David Gibson, IBM Corporation. 8 */ 9 10 #include <stdlib.h> 11 #include <stdio.h> 12 #include <string.h> 13 #include <stdint.h> 14 15 #include <libfdt.h> 16 17 #include "tests.h" 18 #include "testdata.h" 19 20 static int expect_bad; /* = 0 */ 21 22 int main(int argc, char *argv[]) 23 { 24 const char *filename; 25 char *fdt; 26 size_t len; 27 int err; 28 29 test_init(argc, argv); 30 if ((argc != 2) 31 && ((argc != 3) || !streq(argv[1], "-n"))) 32 CONFIG("Usage: %s [-n] <dtb file>", argv[0]); 33 if (argc == 3) 34 expect_bad = 1; 35 36 filename = argv[argc-1]; 37 err = utilfdt_read_err(filename, &fdt, &len); 38 if (err) 39 CONFIG("Couldn't open blob from \"%s\": %s", 40 filename, strerror(err)); 41 42 vg_prepare_blob(fdt, len); 43 44 err = fdt_check_full(fdt, len); 45 46 if (expect_bad && (err == 0)) 47 FAIL("fdt_check_full() succeeded unexpectedly"); 48 else if (!expect_bad && (err != 0)) 49 FAIL("fdt_check_full() failed: %s", fdt_strerror(err)); 50 51 PASS(); 52 } 53