David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 1 | /* |
| 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 Gibson | 857f54e | 2007-03-23 15:16:54 +1100 | [diff] [blame] | 23 | #include <stdint.h> |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 24 | |
| 25 | #include <fdt.h> |
| 26 | #include <libfdt.h> |
| 27 | |
| 28 | #include "tests.h" |
| 29 | #include "testdata.h" |
| 30 | |
David Gibson | 01a2d8a | 2008-08-04 15:30:13 +1000 | [diff] [blame] | 31 | static void check_error(const char *s, int err) |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 32 | { |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 33 | if (err != -FDT_ERR_NOTFOUND) |
| 34 | FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s, |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 35 | fdt_strerror(err)); |
| 36 | } |
| 37 | |
| 38 | int main(int argc, char *argv[]) |
| 39 | { |
David Gibson | a6c76f9 | 2007-06-13 14:18:10 +1000 | [diff] [blame] | 40 | const struct fdt_property *prop; |
David Gibson | 73d6092 | 2006-12-15 15:12:47 +1100 | [diff] [blame] | 41 | void *fdt; |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 42 | int offset; |
| 43 | int subnode1_offset; |
David Gibson | a6c76f9 | 2007-06-13 14:18:10 +1000 | [diff] [blame] | 44 | const void *val; |
David Gibson | a7ee95d | 2006-12-15 15:12:49 +1100 | [diff] [blame] | 45 | int lenerr; |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 46 | |
| 47 | test_init(argc, argv); |
David Gibson | 4e6221c | 2006-11-28 17:20:01 +1100 | [diff] [blame] | 48 | fdt = load_blob_arg(argc, argv); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 49 | |
David Gibson | a7ee95d | 2006-12-15 15:12:49 +1100 | [diff] [blame] | 50 | prop = fdt_get_property(fdt, 0, "nonexistant-property", &lenerr); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 51 | check_error("fdt_get_property(\"nonexistant-property\")", lenerr); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 52 | |
David Gibson | a7ee95d | 2006-12-15 15:12:49 +1100 | [diff] [blame] | 53 | val = fdt_getprop(fdt, 0, "nonexistant-property", &lenerr); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 54 | check_error("fdt_getprop(\"nonexistant-property\"", lenerr); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 55 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 56 | subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 57 | if (subnode1_offset < 0) |
| 58 | FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset)); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 59 | |
David Gibson | a7ee95d | 2006-12-15 15:12:49 +1100 | [diff] [blame] | 60 | val = fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 61 | check_error("fdt_getprop(\"prop-str\")", lenerr); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 62 | |
| 63 | offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 64 | check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 65 | |
| 66 | offset = fdt_subnode_offset(fdt, 0, "subsubnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 67 | check_error("fdt_subnode_offset(\"subsubnode\")", offset); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 68 | |
| 69 | offset = fdt_path_offset(fdt, "/nonexistant-subnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 70 | check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset); |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 71 | |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 72 | PASS(); |
| 73 | } |