xref: /aosp_15_r20/external/dtc/tests/notfound.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 behaviour on searching for a non-existent node
5*cd60bc56SAndroid Build Coastguard Worker  * Copyright (C) 2006 David Gibson, IBM Corporation.
6*cd60bc56SAndroid Build Coastguard Worker  */
7*cd60bc56SAndroid Build Coastguard Worker #include <stdlib.h>
8*cd60bc56SAndroid Build Coastguard Worker #include <stdio.h>
9*cd60bc56SAndroid Build Coastguard Worker #include <string.h>
10*cd60bc56SAndroid Build Coastguard Worker #include <stdint.h>
11*cd60bc56SAndroid Build Coastguard Worker 
12*cd60bc56SAndroid Build Coastguard Worker #include <libfdt.h>
13*cd60bc56SAndroid Build Coastguard Worker 
14*cd60bc56SAndroid Build Coastguard Worker #include "tests.h"
15*cd60bc56SAndroid Build Coastguard Worker #include "testdata.h"
16*cd60bc56SAndroid Build Coastguard Worker 
check_error(const char * s,int err)17*cd60bc56SAndroid Build Coastguard Worker static void check_error(const char *s, int err)
18*cd60bc56SAndroid Build Coastguard Worker {
19*cd60bc56SAndroid Build Coastguard Worker 	if (err != -FDT_ERR_NOTFOUND)
20*cd60bc56SAndroid Build Coastguard Worker 		FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s,
21*cd60bc56SAndroid Build Coastguard Worker 		     fdt_strerror(err));
22*cd60bc56SAndroid Build Coastguard Worker }
23*cd60bc56SAndroid Build Coastguard Worker 
main(int argc,char * argv[])24*cd60bc56SAndroid Build Coastguard Worker int main(int argc, char *argv[])
25*cd60bc56SAndroid Build Coastguard Worker {
26*cd60bc56SAndroid Build Coastguard Worker 	void *fdt;
27*cd60bc56SAndroid Build Coastguard Worker 	int offset;
28*cd60bc56SAndroid Build Coastguard Worker 	int subnode1_offset;
29*cd60bc56SAndroid Build Coastguard Worker 	int lenerr;
30*cd60bc56SAndroid Build Coastguard Worker 
31*cd60bc56SAndroid Build Coastguard Worker 	test_init(argc, argv);
32*cd60bc56SAndroid Build Coastguard Worker 	fdt = load_blob_arg(argc, argv);
33*cd60bc56SAndroid Build Coastguard Worker 
34*cd60bc56SAndroid Build Coastguard Worker 	fdt_get_property(fdt, 0, "nonexistant-property", &lenerr);
35*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_get_property(\"nonexistant-property\")", lenerr);
36*cd60bc56SAndroid Build Coastguard Worker 
37*cd60bc56SAndroid Build Coastguard Worker 	fdt_getprop(fdt, 0, "nonexistant-property", &lenerr);
38*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_getprop(\"nonexistant-property\"", lenerr);
39*cd60bc56SAndroid Build Coastguard Worker 
40*cd60bc56SAndroid Build Coastguard Worker 	subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1");
41*cd60bc56SAndroid Build Coastguard Worker 	if (subnode1_offset < 0)
42*cd60bc56SAndroid Build Coastguard Worker 		FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset));
43*cd60bc56SAndroid Build Coastguard Worker 
44*cd60bc56SAndroid Build Coastguard Worker 	fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr);
45*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_getprop(\"prop-str\")", lenerr);
46*cd60bc56SAndroid Build Coastguard Worker 
47*cd60bc56SAndroid Build Coastguard Worker 	offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode");
48*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset);
49*cd60bc56SAndroid Build Coastguard Worker 
50*cd60bc56SAndroid Build Coastguard Worker 	offset = fdt_subnode_offset(fdt, 0, "subsubnode");
51*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_subnode_offset(\"subsubnode\")", offset);
52*cd60bc56SAndroid Build Coastguard Worker 
53*cd60bc56SAndroid Build Coastguard Worker 	offset = fdt_path_offset(fdt, "/nonexistant-subnode");
54*cd60bc56SAndroid Build Coastguard Worker 	check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset);
55*cd60bc56SAndroid Build Coastguard Worker 
56*cd60bc56SAndroid Build Coastguard Worker 	PASS();
57*cd60bc56SAndroid Build Coastguard Worker }
58