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