blob: ea3a18f6acb5d8b550e1a3412d713ae765e38675 [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>
David Gibson857f54e2007-03-23 15:16:54 +110025#include <stdint.h>
David Gibson3da0f9a2006-11-27 16:21:28 +110026
27#include <fdt.h>
28#include <libfdt.h>
29
30#include "tests.h"
31#include "testdata.h"
32
33int main(int argc, char *argv[])
34{
David Gibson73d60922006-12-15 15:12:47 +110035 void *fdt;
David Gibson3da0f9a2006-11-27 16:21:28 +110036 int subnode1_offset, subnode2_offset, subsubnode2_offset;
37 int err;
38
39 test_init(argc, argv);
David Gibson4e6221c2006-11-28 17:20:01 +110040 fdt = load_blob_arg(argc, argv);
David Gibson3da0f9a2006-11-27 16:21:28 +110041
David Gibsond2a9da02007-09-28 15:51:04 +100042 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110043 if (subnode1_offset < 0)
44 FAIL("Couldn't find \"/subnode1\": %s",
45 fdt_strerror(subnode1_offset));
David Gibson9521dc52007-11-20 13:35:46 +110046 check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
David Gibson3da0f9a2006-11-27 16:21:28 +110047
David Gibsond2a9da02007-09-28 15:51:04 +100048 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110049 if (subnode2_offset < 0)
50 FAIL("Couldn't find \"/subnode2\": %s",
51 fdt_strerror(subnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110052 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson9a9fdf52006-12-15 15:12:51 +110053
David Gibsond2a9da02007-09-28 15:51:04 +100054 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110055 if (subsubnode2_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100056 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110057 fdt_strerror(subsubnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110058 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson3da0f9a2006-11-27 16:21:28 +110059
60 err = fdt_nop_node(fdt, subnode1_offset);
61 if (err)
62 FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err));
63
David Gibsond2a9da02007-09-28 15:51:04 +100064 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110065 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110066 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110067 fdt_strerror(subnode1_offset),
68 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +110069
David Gibsond2a9da02007-09-28 15:51:04 +100070 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110071 if (subnode2_offset < 0)
72 FAIL("Couldn't find \"/subnode2\": %s",
73 fdt_strerror(subnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110074 check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson9a9fdf52006-12-15 15:12:51 +110075
David Gibsond2a9da02007-09-28 15:51:04 +100076 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110077 if (subsubnode2_offset < 0)
David Gibsond2a9da02007-09-28 15:51:04 +100078 FAIL("Couldn't find \"/subnode@2/subsubnode\": %s",
David Gibson9a9fdf52006-12-15 15:12:51 +110079 fdt_strerror(subsubnode2_offset));
David Gibson9521dc52007-11-20 13:35:46 +110080 check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
David Gibson3da0f9a2006-11-27 16:21:28 +110081
82 err = fdt_nop_node(fdt, subnode2_offset);
83 if (err)
84 FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err));
85
David Gibsond2a9da02007-09-28 15:51:04 +100086 subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110087 if (subnode1_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110088 FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110089 fdt_strerror(subnode1_offset),
90 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +110091
David Gibsond2a9da02007-09-28 15:51:04 +100092 subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
David Gibson9a9fdf52006-12-15 15:12:51 +110093 if (subnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +110094 FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +110095 fdt_strerror(subnode2_offset),
96 fdt_strerror(-FDT_ERR_NOTFOUND));
97
David Gibsond2a9da02007-09-28 15:51:04 +100098 subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110099 if (subsubnode2_offset != -FDT_ERR_NOTFOUND)
David Gibson3da0f9a2006-11-27 16:21:28 +1100100 FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"",
David Gibson9a9fdf52006-12-15 15:12:51 +1100101 fdt_strerror(subsubnode2_offset),
102 fdt_strerror(-FDT_ERR_NOTFOUND));
David Gibson3da0f9a2006-11-27 16:21:28 +1100103
104 PASS();
105}