xref: /aosp_15_r20/external/dtc/tests/get_prop_offset.c (revision cd60bc56d4bea3af4ec04523e4d71c2b272c8aff)
1*cd60bc56SAndroid Build Coastguard Worker // SPDX-License-Identifier: LGPL-2.1-or-later
2*cd60bc56SAndroid Build Coastguard Worker /*
3*cd60bc56SAndroid Build Coastguard Worker  * libfdt - Flat Device Tree manipulation
4*cd60bc56SAndroid Build Coastguard Worker  *	Testcase for fdt_getprop_by_offset()
5*cd60bc56SAndroid Build Coastguard Worker  * Copyright (C) 2006 David Gibson, IBM Corporation.
6*cd60bc56SAndroid Build Coastguard Worker  */
7*cd60bc56SAndroid Build Coastguard Worker 
8*cd60bc56SAndroid Build Coastguard Worker #include <stdlib.h>
9*cd60bc56SAndroid Build Coastguard Worker #include <stdio.h>
10*cd60bc56SAndroid Build Coastguard Worker #include <string.h>
11*cd60bc56SAndroid Build Coastguard Worker #include <stdint.h>
12*cd60bc56SAndroid Build Coastguard Worker 
13*cd60bc56SAndroid Build Coastguard Worker #include <libfdt.h>
14*cd60bc56SAndroid Build Coastguard Worker 
15*cd60bc56SAndroid Build Coastguard Worker #include "tests.h"
16*cd60bc56SAndroid Build Coastguard Worker #include "testdata.h"
17*cd60bc56SAndroid Build Coastguard Worker 
main(int argc,char * argv[])18*cd60bc56SAndroid Build Coastguard Worker int main(int argc, char *argv[])
19*cd60bc56SAndroid Build Coastguard Worker {
20*cd60bc56SAndroid Build Coastguard Worker 	bool found_prop_int = false;
21*cd60bc56SAndroid Build Coastguard Worker 	bool found_prop_str = false;
22*cd60bc56SAndroid Build Coastguard Worker 	int poffset;
23*cd60bc56SAndroid Build Coastguard Worker 	void *fdt;
24*cd60bc56SAndroid Build Coastguard Worker 
25*cd60bc56SAndroid Build Coastguard Worker 	test_init(argc, argv);
26*cd60bc56SAndroid Build Coastguard Worker 	fdt = load_blob_arg(argc, argv);
27*cd60bc56SAndroid Build Coastguard Worker 
28*cd60bc56SAndroid Build Coastguard Worker 	fdt_for_each_property_offset(poffset, fdt, 0) {
29*cd60bc56SAndroid Build Coastguard Worker 		if (check_get_prop_offset_cell(fdt, poffset, "prop-int",
30*cd60bc56SAndroid Build Coastguard Worker 					       TEST_VALUE_1))
31*cd60bc56SAndroid Build Coastguard Worker 			found_prop_int = true;
32*cd60bc56SAndroid Build Coastguard Worker 		if (check_get_prop_offset(fdt, poffset, "prop-str",
33*cd60bc56SAndroid Build Coastguard Worker 					  strlen(TEST_STRING_1) + 1,
34*cd60bc56SAndroid Build Coastguard Worker 					  TEST_STRING_1))
35*cd60bc56SAndroid Build Coastguard Worker 			found_prop_str = true;
36*cd60bc56SAndroid Build Coastguard Worker 	}
37*cd60bc56SAndroid Build Coastguard Worker 	if (!found_prop_int)
38*cd60bc56SAndroid Build Coastguard Worker 		FAIL("Property 'prop-int' not found");
39*cd60bc56SAndroid Build Coastguard Worker 	if (!found_prop_str)
40*cd60bc56SAndroid Build Coastguard Worker 		FAIL("Property 'prop-str' not found");
41*cd60bc56SAndroid Build Coastguard Worker 
42*cd60bc56SAndroid Build Coastguard Worker 	PASS();
43*cd60bc56SAndroid Build Coastguard Worker }
44