1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for label relative child references in dtc
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 * Copyright (C) 2020 Ahmad Fatoum, Pengutronix.
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
check_exist(void * fdt,const char * path)18 static void check_exist(void *fdt, const char *path)
19 {
20 int sn = fdt_path_offset(fdt, path);
21 if (sn < 0)
22 FAIL("%s expected but not found: %s", path, fdt_strerror(sn));
23 }
24
check_doesnt_exist(void * fdt,const char * path)25 static void check_doesnt_exist(void *fdt, const char *path)
26 {
27 int sn = fdt_path_offset(fdt, path);
28 if (sn >= 0)
29 FAIL("%s found but not expected %d", path, sn);
30 }
31
main(int argc,char * argv[])32 int main(int argc, char *argv[])
33 {
34 void *fdt;
35
36 test_init(argc, argv);
37 fdt = load_blob_arg(argc, argv);
38
39 check_exist(fdt, "/node/subnode1");
40 check_exist(fdt, "/node/keep-me");
41 check_doesnt_exist(fdt, "/node/remove-me");
42
43 check_doesnt_exist(fdt, "/node2");
44 check_doesnt_exist(fdt, "/node/subnode3");
45
46 check_exist(fdt, "/node/subnode4");
47
48 check_exist(fdt, "/node/subnode1/add-me");
49
50 PASS();
51 }
52