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> |
David Gibson | 857f54e | 2007-03-23 15:16:54 +1100 | [diff] [blame] | 25 | #include <stdint.h> |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 26 | |
| 27 | #include <fdt.h> |
| 28 | #include <libfdt.h> |
| 29 | |
| 30 | #include "tests.h" |
| 31 | #include "testdata.h" |
| 32 | |
| 33 | int main(int argc, char *argv[]) |
| 34 | { |
David Gibson | 73d6092 | 2006-12-15 15:12:47 +1100 | [diff] [blame] | 35 | void *fdt; |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 36 | int subnode1_offset, subnode2_offset, subsubnode2_offset; |
| 37 | int err; |
| 38 | |
| 39 | test_init(argc, argv); |
David Gibson | 4e6221c | 2006-11-28 17:20:01 +1100 | [diff] [blame] | 40 | fdt = load_blob_arg(argc, argv); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 41 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 42 | subnode1_offset = fdt_path_offset(fdt, "/subnode@1"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 43 | if (subnode1_offset < 0) |
| 44 | FAIL("Couldn't find \"/subnode1\": %s", |
| 45 | fdt_strerror(subnode1_offset)); |
David Gibson | 9521dc5 | 2007-11-20 13:35:46 +1100 | [diff] [blame] | 46 | check_getprop_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 47 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 48 | subnode2_offset = fdt_path_offset(fdt, "/subnode@2"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 49 | if (subnode2_offset < 0) |
| 50 | FAIL("Couldn't find \"/subnode2\": %s", |
| 51 | fdt_strerror(subnode2_offset)); |
David Gibson | 9521dc5 | 2007-11-20 13:35:46 +1100 | [diff] [blame] | 52 | check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 53 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 54 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 55 | if (subsubnode2_offset < 0) |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 56 | FAIL("Couldn't find \"/subnode@2/subsubnode\": %s", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 57 | fdt_strerror(subsubnode2_offset)); |
David Gibson | 9521dc5 | 2007-11-20 13:35:46 +1100 | [diff] [blame] | 58 | check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 59 | |
| 60 | err = fdt_nop_node(fdt, subnode1_offset); |
| 61 | if (err) |
| 62 | FAIL("fdt_nop_node(subnode1): %s", fdt_strerror(err)); |
| 63 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 64 | subnode1_offset = fdt_path_offset(fdt, "/subnode@1"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 65 | if (subnode1_offset != -FDT_ERR_NOTFOUND) |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 66 | FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 67 | fdt_strerror(subnode1_offset), |
| 68 | fdt_strerror(-FDT_ERR_NOTFOUND)); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 69 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 70 | subnode2_offset = fdt_path_offset(fdt, "/subnode@2"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 71 | if (subnode2_offset < 0) |
| 72 | FAIL("Couldn't find \"/subnode2\": %s", |
| 73 | fdt_strerror(subnode2_offset)); |
David Gibson | 9521dc5 | 2007-11-20 13:35:46 +1100 | [diff] [blame] | 74 | check_getprop_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 75 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 76 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 77 | if (subsubnode2_offset < 0) |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 78 | FAIL("Couldn't find \"/subnode@2/subsubnode\": %s", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 79 | fdt_strerror(subsubnode2_offset)); |
David Gibson | 9521dc5 | 2007-11-20 13:35:46 +1100 | [diff] [blame] | 80 | check_getprop_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 81 | |
| 82 | err = fdt_nop_node(fdt, subnode2_offset); |
| 83 | if (err) |
| 84 | FAIL("fdt_nop_node(subnode2): %s", fdt_strerror(err)); |
| 85 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 86 | subnode1_offset = fdt_path_offset(fdt, "/subnode@1"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 87 | if (subnode1_offset != -FDT_ERR_NOTFOUND) |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 88 | FAIL("fdt_path_offset(subnode1) returned \"%s\" instead of \"%s\"", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 89 | fdt_strerror(subnode1_offset), |
| 90 | fdt_strerror(-FDT_ERR_NOTFOUND)); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 91 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 92 | subnode2_offset = fdt_path_offset(fdt, "/subnode@2"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 93 | if (subnode2_offset != -FDT_ERR_NOTFOUND) |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 94 | FAIL("fdt_path_offset(subnode2) returned \"%s\" instead of \"%s\"", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 95 | fdt_strerror(subnode2_offset), |
| 96 | fdt_strerror(-FDT_ERR_NOTFOUND)); |
| 97 | |
David Gibson | d2a9da0 | 2007-09-28 15:51:04 +1000 | [diff] [blame] | 98 | subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode"); |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 99 | if (subsubnode2_offset != -FDT_ERR_NOTFOUND) |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 100 | FAIL("fdt_path_offset(subsubnode2) returned \"%s\" instead of \"%s\"", |
David Gibson | 9a9fdf5 | 2006-12-15 15:12:51 +1100 | [diff] [blame] | 101 | fdt_strerror(subsubnode2_offset), |
| 102 | fdt_strerror(-FDT_ERR_NOTFOUND)); |
David Gibson | 3da0f9a | 2006-11-27 16:21:28 +1100 | [diff] [blame] | 103 | |
| 104 | PASS(); |
| 105 | } |