1 /* $NetBSD: notfound.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $ */ 2 3 // SPDX-License-Identifier: LGPL-2.1-or-later 4 /* 5 * libfdt - Flat Device Tree manipulation 6 * Testcase for behaviour on searching for a non-existent node 7 * Copyright (C) 2006 David Gibson, IBM Corporation. 8 */ 9 #include <stdlib.h> 10 #include <stdio.h> 11 #include <string.h> 12 #include <stdint.h> 13 14 #include <libfdt.h> 15 16 #include "tests.h" 17 #include "testdata.h" 18 19 static void check_error(const char *s, int err) 20 { 21 if (err != -FDT_ERR_NOTFOUND) 22 FAIL("%s return error %s instead of -FDT_ERR_NOTFOUND", s, 23 fdt_strerror(err)); 24 } 25 26 int main(int argc, char *argv[]) 27 { 28 void *fdt; 29 int offset; 30 int subnode1_offset; 31 int lenerr; 32 33 test_init(argc, argv); 34 fdt = load_blob_arg(argc, argv); 35 36 fdt_get_property(fdt, 0, "nonexistant-property", &lenerr); 37 check_error("fdt_get_property(\"nonexistant-property\")", lenerr); 38 39 fdt_getprop(fdt, 0, "nonexistant-property", &lenerr); 40 check_error("fdt_getprop(\"nonexistant-property\"", lenerr); 41 42 subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1"); 43 if (subnode1_offset < 0) 44 FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset)); 45 46 fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr); 47 check_error("fdt_getprop(\"prop-str\")", lenerr); 48 49 offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode"); 50 check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset); 51 52 offset = fdt_subnode_offset(fdt, 0, "subsubnode"); 53 check_error("fdt_subnode_offset(\"subsubnode\")", offset); 54 55 offset = fdt_path_offset(fdt, "/nonexistant-subnode"); 56 check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset); 57 58 PASS(); 59 } 60