xref: /netbsd-src/external/gpl2/dtc/dist/tests/path_offset_aliases.c (revision 32d1c65c71fbdb65a012e8392a62a757dd6853e9)
1 /*	$NetBSD: path_offset_aliases.c,v 1.1.1.3 2019/12/22 12:34:06 skrll Exp $	*/
2 
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 /*
5  * libfdt - Flat Device Tree manipulation
6  *	Testcase for fdt_path_offset()
7  * Copyright (C) 2006 David Gibson, IBM Corporation.
8  * Copyright 2008 Kumar Gala, Freescale Semiconductor, Inc.
9  */
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdint.h>
14 
15 #include <libfdt.h>
16 
17 #include "tests.h"
18 #include "testdata.h"
19 
20 static void check_alias(void *fdt, const char *full_path, const char *alias_path)
21 {
22 	int offset, offset_a;
23 
24 	offset = fdt_path_offset(fdt, full_path);
25 	offset_a = fdt_path_offset(fdt, alias_path);
26 
27 	if (offset != offset_a)
28 		FAIL("Mismatch between %s path_offset (%d) and %s path_offset alias (%d)",
29 		     full_path, offset, alias_path, offset_a);
30 }
31 
32 int main(int argc, char *argv[])
33 {
34 	void *fdt;
35 
36 	test_init(argc, argv);
37 	fdt = load_blob_arg(argc, argv);
38 
39 	check_alias(fdt, "/subnode@1", "s1");
40 	check_alias(fdt, "/subnode@1/subsubnode", "ss1");
41 	check_alias(fdt, "/subnode@1/subsubnode", "s1/subsubnode");
42 	check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1");
43 	check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "ss1/subsubsubnode");
44 	check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "s1/subsubnode/subsubsubnode");
45 
46 	PASS();
47 }
48