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