David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | int main(int argc, char *argv[]) |
| 33 | { |
David Gibson | 73d6092 | 2006-12-15 15:12:47 +1100 | [diff] [blame] | 34 | void *fdt; |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 35 | int subnode1_offset, subnode2_offset, subsubnode2_offset; |
| 36 | int err; |
| 37 | |
| 38 | test_init(argc, argv); |
David Gibson | 4e6221c | 2006-11-28 17:20:01 +1100 | [diff] [blame] | 39 | fdt = load_blob_arg(argc, argv); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 40 | |
| 41 | subnode1_offset = fdt_path_offset(fdt, "/subnode1"); |
| 42 | if ((err = fdt_offset_error(subnode1_offset))) |
| 43 | FAIL("Couldn't find \"/subnode1\": %s", fdt_strerror(err)); |
| 44 | check_getprop_typed(fdt, subnode1_offset, "prop-int", TEST_VALUE_1); |
| 45 | |
| 46 | subnode2_offset = fdt_path_offset(fdt, "/subnode2"); |
| 47 | if ((err = fdt_offset_error(subnode2_offset))) |
| 48 | FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err)); |
| 49 | check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2); |
| 50 | |
| 51 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode"); |
| 52 | if ((err = fdt_offset_error(subsubnode2_offset))) |
| 53 | FAIL("Couldn't find \"/subnode2/subsubnode\": %s", |
| 54 | fdt_strerror(err)); |
| 55 | check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2); |
| 56 | |
| 57 | err = fdt_nop_node(fdt, subnode1_offset); |
| 58 | if (err) |
| 59 | FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err)); |
| 60 | |
| 61 | subnode1_offset = fdt_path_offset(fdt, "/subnode1"); |
| 62 | if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND) |
| 63 | FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"", |
| 64 | fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND)); |
| 65 | |
| 66 | subnode2_offset = fdt_path_offset(fdt, "/subnode2"); |
| 67 | if ((err = fdt_offset_error(subnode2_offset))) |
| 68 | FAIL("Couldn't find \"/subnode2\": %s", fdt_strerror(err)); |
| 69 | check_getprop_typed(fdt, subnode2_offset, "prop-int", TEST_VALUE_2); |
| 70 | |
| 71 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode"); |
| 72 | if ((err = fdt_offset_error(subsubnode2_offset))) |
| 73 | FAIL("Couldn't find \"/subnode2/subsubnode\": %s", |
| 74 | fdt_strerror(err)); |
| 75 | check_getprop_typed(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2); |
| 76 | |
| 77 | err = fdt_nop_node(fdt, subnode2_offset); |
| 78 | if (err) |
| 79 | FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err)); |
| 80 | |
| 81 | subnode1_offset = fdt_path_offset(fdt, "/subnode1"); |
| 82 | if ((err = fdt_offset_error(subnode1_offset)) != FDT_ERR_NOTFOUND) |
| 83 | FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"", |
| 84 | fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND)); |
| 85 | |
| 86 | subnode2_offset = fdt_path_offset(fdt, "/subnode2"); |
| 87 | if ((err = fdt_offset_error(subnode2_offset)) != FDT_ERR_NOTFOUND) |
| 88 | FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"", |
| 89 | fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND)); |
| 90 | |
| 91 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode2/subsubnode"); |
| 92 | if ((err = fdt_offset_error(subsubnode2_offset)) != FDT_ERR_NOTFOUND) |
| 93 | FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"", |
| 94 | fdt_strerror(err), fdt_strerror(FDT_ERR_NOTFOUND)); |
| 95 | |
| 96 | PASS(); |
| 97 | } |