blob: d09d9dfe7128a41713b9704fd4220d2671775824 [file] [log] [blame]
David Gibson3da0f9a2006-11-27 16:21:28 +11001/*
2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_nop_node()
4 * Copyright (C) 2006 David Gibson, IBM Corporation.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <ctype.h>
25
26#include <fdt.h>
27#include <libfdt.h>
28
29#include "tests.h"
30#include "testdata.h"
31
32int main(int argc, char *argv[])
33{
David Gibson73d60922006-12-15 15:12:47 +110034 void *fdt;
David Gibson3da0f9a2006-11-27 16:21:28 +110035 int subnode1_offset, subnode2_offset, subsubnode2_offset;
36 int err;
37
38 test_init(argc, argv);
David Gibson4e6221c2006-11-28 17:20:01 +110039 fdt = load_blob_arg(argc, argv);
David Gibson3da0f9a2006-11-27 16:21:28 +110040
41 subnode1_offset = fdt_path_offset(fdt, "/subnode1");
David Gibson9a9fdf52006-12-15 15:12:51 +110042 if (subnode1_offset < 0)
43 FAIL("Couldn't find \"/subnode1\": %s",
44 fdt_strerror(subnode1_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110045 check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
46
47 subnode2_offset = fdt_path_offset(fdt, "/subnode2");
David Gibson9a9fdf52006-12-15 15:12:51 +110048 if (subnode2_offset < 0)
49 FAIL("Couldn't find \"/subnode2\": %s",
50 fdt_strerror(subnode2_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110051 check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson9a9fdf52006-12-15 15:12:51 +110052
David Gibson3da0f9a2006-11-27 16:21:28 +110053 subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110054 if (subsubnode2_offset < 0)
David Gibson3da0f9a2006-11-27 16:21:28 +110055 FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110056 fdt_strerror(subsubnode2_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110057 check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
58
59 err = fdt_nop_node(fdt, subnode1_offset);
60 if (err)
61 FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
62
63 subnode1_offset = fdt_path_offset(fdt, "/subnode1");
David Gibson9a9fdf52006-12-15 15:12:51 +110064 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110065 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110066 fdt_strerror(subnode1_offset),
67 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +110068
69 subnode2_offset = fdt_path_offset(fdt, "/subnode2");
David Gibson9a9fdf52006-12-15 15:12:51 +110070 if (subnode2_offset < 0)
71 FAIL("Couldn't find \"/subnode2\": %s",
72 fdt_strerror(subnode2_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110073 check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson9a9fdf52006-12-15 15:12:51 +110074
David Gibson3da0f9a2006-11-27 16:21:28 +110075 subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110076 if (subsubnode2_offset < 0)
David Gibson3da0f9a2006-11-27 16:21:28 +110077 FAIL("Couldn't find \"/subnode2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110078 fdt_strerror(subsubnode2_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110079 check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
80
81 err = fdt_nop_node(fdt, subnode2_offset);
82 if (err)
83 FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
84
85 subnode1_offset = fdt_path_offset(fdt, "/subnode1");
David Gibson9a9fdf52006-12-15 15:12:51 +110086 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110087 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110088 fdt_strerror(subnode1_offset),
89 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +110090
91 subnode2_offset = fdt_path_offset(fdt, "/subnode2");
David Gibson9a9fdf52006-12-15 15:12:51 +110092 if (subnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110093 FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110094 fdt_strerror(subnode2_offset),
95 fdt_strerror(-FDT_ERR_NOTFOUND));
96
David Gibson3da0f9a2006-11-27 16:21:28 +110097 subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110098 if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110099 FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +1100100 fdt_strerror(subsubnode2_offset),
101 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +1100102
103 PASS();
104}