Home | History | Annotate | Line # | Download | only in tests
      1  1.1.1.2     skrll /*	$NetBSD: node_offset_by_phandle.c,v 1.1.1.3 2019/12/22 12:34:07 skrll Exp $	*/
      2  1.1.1.2     skrll 
      3  1.1.1.3     skrll // SPDX-License-Identifier: LGPL-2.1-or-later
      4      1.1  macallan /*
      5      1.1  macallan  * libfdt - Flat Device Tree manipulation
      6      1.1  macallan  *	Testcase for fdt_node_offset_by_phandle()
      7      1.1  macallan  * Copyright (C) 2006 David Gibson, IBM Corporation.
      8      1.1  macallan  */
      9      1.1  macallan #include <stdlib.h>
     10      1.1  macallan #include <stdio.h>
     11      1.1  macallan #include <string.h>
     12      1.1  macallan #include <stdint.h>
     13      1.1  macallan #include <stdarg.h>
     14      1.1  macallan 
     15      1.1  macallan #include <libfdt.h>
     16      1.1  macallan 
     17      1.1  macallan #include "tests.h"
     18      1.1  macallan #include "testdata.h"
     19      1.1  macallan 
     20      1.1  macallan static void check_search(void *fdt, uint32_t phandle, int target)
     21      1.1  macallan {
     22      1.1  macallan 	int offset;
     23      1.1  macallan 
     24      1.1  macallan 	offset = fdt_node_offset_by_phandle(fdt, phandle);
     25      1.1  macallan 
     26      1.1  macallan 	if (offset != target)
     27      1.1  macallan 		FAIL("fdt_node_offset_by_phandle(0x%x) returns %d "
     28      1.1  macallan 		     "instead of %d", phandle, offset, target);
     29      1.1  macallan }
     30      1.1  macallan 
     31      1.1  macallan int main(int argc, char *argv[])
     32      1.1  macallan {
     33      1.1  macallan 	void *fdt;
     34      1.1  macallan 	int subnode2_offset, subsubnode2_offset;
     35      1.1  macallan 
     36      1.1  macallan 	test_init(argc, argv);
     37      1.1  macallan 	fdt = load_blob_arg(argc, argv);
     38      1.1  macallan 
     39      1.1  macallan 	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
     40      1.1  macallan 	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
     41      1.1  macallan 
     42      1.1  macallan 	if ((subnode2_offset < 0) || (subsubnode2_offset < 0))
     43      1.1  macallan 		FAIL("Can't find required nodes");
     44      1.1  macallan 
     45      1.1  macallan 	check_search(fdt, PHANDLE_1, subnode2_offset);
     46      1.1  macallan 	check_search(fdt, PHANDLE_2, subsubnode2_offset);
     47      1.1  macallan 	check_search(fdt, ~PHANDLE_1, -FDT_ERR_NOTFOUND);
     48      1.1  macallan 	check_search(fdt, 0, -FDT_ERR_BADPHANDLE);
     49      1.1  macallan 	check_search(fdt, -1, -FDT_ERR_BADPHANDLE);
     50      1.1  macallan 
     51      1.1  macallan 	PASS();
     52      1.1  macallan }
     53