xref: /netbsd-src/external/gpl2/dtc/dist/tests/get_alias.c (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: get_alias.c,v 1.1.1.2 2017/06/08 15:59:26 skrll Exp $	*/
2 
3 /*
4  * libfdt - Flat Device Tree manipulation
5  *	Testcase for fdt_get_alias()
6  * Copyright (C) 2006 David Gibson, IBM Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdint.h>
27 
28 #include <libfdt.h>
29 
30 #include "tests.h"
31 #include "testdata.h"
32 
33 static void check_alias(void *fdt, const char *path, const char *alias)
34 {
35 	const char *aliaspath;
36 
37 	aliaspath = fdt_get_alias(fdt, alias);
38 
39 	if (path && !aliaspath)
40 		FAIL("fdt_get_alias(%s) failed\n", alias);
41 
42 	if (strcmp(aliaspath, path) != 0)
43 		FAIL("fdt_get_alias(%s) returned %s instead of %s\n",
44 		     alias, aliaspath, path);
45 }
46 
47 int main(int argc, char *argv[])
48 {
49 	void *fdt;
50 
51 	test_init(argc, argv);
52 	fdt = load_blob_arg(argc, argv);
53 
54 	check_alias(fdt, "/subnode@1", "s1");
55 	check_alias(fdt, "/subnode@1/subsubnode", "ss1");
56 	check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1");
57 
58 	PASS();
59 }
60