xref: /aosp_15_r20/external/dtc/tests/truncated_property.c (revision cd60bc56d4bea3af4ec04523e4d71c2b272c8aff)
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3  * libfdt - Flat Device Tree manipulation
4  *	Testcase for misbehaviour on a truncated property
5  * Copyright (C) 2006 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 
main(int argc,char * argv[])18 int main(int argc, char *argv[])
19 {
20 	void *fdt = &truncated_property;
21 	const void *prop;
22 	int len;
23 
24 	test_init(argc, argv);
25 
26 	vg_prepare_blob(fdt, fdt_totalsize(fdt));
27 
28 	prop = fdt_getprop(fdt, 0, "truncated", &len);
29 	if (prop)
30 		FAIL("fdt_getprop() succeeded on truncated property");
31 	if (len != -FDT_ERR_BADSTRUCTURE)
32 		FAIL("fdt_getprop() failed with \"%s\" instead of \"%s\"",
33 		     fdt_strerror(len), fdt_strerror(-FDT_ERR_BADSTRUCTURE));
34 
35 	PASS();
36 }
37