1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for fdt_nop_node()
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
6 */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdint.h>
13
14 #include <libfdt.h>
15
16 #include "tests.h"
17 #include "testdata.h"
18
main(int argc,char * argv[])19 int main(int argc, char *argv[])
20 {
21 void *fdt;
22 int subnode1_offset, subnode2_offset, subsubnode2_offset;
23 int err;
24
25 test_init(argc, argv);
26 fdt = load_blob_arg(argc, argv);
27
28 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
29 if (subnode1_offset < 0)
30 FAIL("Couldn't find \"/subnode1\": %s",
31 fdt_strerror(subnode1_offset));
32 check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
33
34 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
35 if (subnode2_offset < 0)
36 FAIL("Couldn't find \"/subnode2\": %s",
37 fdt_strerror(subnode2_offset));
38 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
39
40 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
41 if (subsubnode2_offset < 0)
42 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
43 fdt_strerror(subsubnode2_offset));
44 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
45
46 err = fdt_nop_node(fdt, subnode1_offset);
47 if (err)
48 FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
49
50 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
51 if (subnode1_offset != -FDT_ERR_NOTFOUND)
52 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
53 fdt_strerror(subnode1_offset),
54 fdt_strerror(-FDT_ERR_NOTFOUND));
55
56 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
57 if (subnode2_offset < 0)
58 FAIL("Couldn't find \"/subnode2\": %s",
59 fdt_strerror(subnode2_offset));
60 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
61
62 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
63 if (subsubnode2_offset < 0)
64 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
65 fdt_strerror(subsubnode2_offset));
66 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
67
68 err = fdt_nop_node(fdt, subnode2_offset);
69 if (err)
70 FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
71
72 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
73 if (subnode1_offset != -FDT_ERR_NOTFOUND)
74 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
75 fdt_strerror(subnode1_offset),
76 fdt_strerror(-FDT_ERR_NOTFOUND));
77
78 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
79 if (subnode2_offset != -FDT_ERR_NOTFOUND)
80 FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
81 fdt_strerror(subnode2_offset),
82 fdt_strerror(-FDT_ERR_NOTFOUND));
83
84 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
85 if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
86 FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
87 fdt_strerror(subsubnode2_offset),
88 fdt_strerror(-FDT_ERR_NOTFOUND));
89
90 PASS();
91 }
92