blob: 4d55b886ba7a472e38bc02e369856a88a9a09559 [file] [log] [blame]
David Gibson3da0f9a2006-11-27 16:21:28 +11001/*
2 * libfdt - Flat Device Tree manipulation
3 * Testcase for behaviour on searching for a non-existent 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#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
David Gibson857f54e2007-03-23 15:16:54 +110023#include <stdint.h>
David Gibson3da0f9a2006-11-27 16:21:28 +110024
25#include <fdt.h>
26#include <libfdt.h>
27
28#include "tests.h"
29#include "testdata.h"
30
David Gibson01a2d8a2008-08-04 15:30:13 +100031static void check_error(const char *s, int err)
David Gibson3da0f9a2006-11-27 16:21:28 +110032{
David Gibson9a9fdf52006-12-15 15:12:51 +110033 if (err != -FDT_ERR_NOTFOUND)
34 FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s,
David Gibson3da0f9a2006-11-27 16:21:28 +110035 fdt_strerror(err));
36}
37
38int main(int argc, char *argv[])
39{
David Gibson73d60922006-12-15 15:12:47 +110040 void *fdt;
David Gibson3da0f9a2006-11-27 16:21:28 +110041 int offset;
42 int subnode1_offset;
David Gibsona7ee95d2006-12-15 15:12:49 +110043 int lenerr;
David Gibson3da0f9a2006-11-27 16:21:28 +110044
45 test_init(argc, argv);
David Gibson4e6221c2006-11-28 17:20:01 +110046 fdt = load_blob_arg(argc, argv);
David Gibson3da0f9a2006-11-27 16:21:28 +110047
David Gibson83df28b2011-09-12 11:18:43 +100048 fdt_get_property(fdt, 0, "nonexistant-property", &lenerr);
David Gibson9a9fdf52006-12-15 15:12:51 +110049 check_error("fdt_get_property(\"nonexistant-property\")", lenerr);
David Gibson3da0f9a2006-11-27 16:21:28 +110050
David Gibson83df28b2011-09-12 11:18:43 +100051 fdt_getprop(fdt, 0, "nonexistant-property", &lenerr);
David Gibson9a9fdf52006-12-15 15:12:51 +110052 check_error("fdt_getprop(\"nonexistant-property\"", lenerr);
David Gibson3da0f9a2006-11-27 16:21:28 +110053
David Gibsond2a9da02007-09-28 15:51:04 +100054 subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1");
David Gibson9a9fdf52006-12-15 15:12:51 +110055 if (subnode1_offset < 0)
56 FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset));
David Gibson3da0f9a2006-11-27 16:21:28 +110057
David Gibson83df28b2011-09-12 11:18:43 +100058 fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr);
David Gibson9a9fdf52006-12-15 15:12:51 +110059 check_error("fdt_getprop(\"prop-str\")", lenerr);
David Gibson3da0f9a2006-11-27 16:21:28 +110060
61 offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110062 check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset);
David Gibson3da0f9a2006-11-27 16:21:28 +110063
64 offset = fdt_subnode_offset(fdt, 0, "subsubnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110065 check_error("fdt_subnode_offset(\"subsubnode\")", offset);
David Gibson3da0f9a2006-11-27 16:21:28 +110066
67 offset = fdt_path_offset(fdt, "/nonexistant-subnode");
David Gibson9a9fdf52006-12-15 15:12:51 +110068 check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset);
David Gibson63dc9c72007-09-18 11:44:04 +100069
David Gibson3da0f9a2006-11-27 16:21:28 +110070 PASS();
71}