blob: 81efe621115b1c322e3ccf4dc37f1cfb9d29e9ef [file] [log] [blame]
Rob Herringc4ffc052019-06-20 15:19:41 -06001// SPDX-License-Identifier: LGPL-2.1-or-later
David Gibson32b6bd32007-10-17 11:23:57 +10002/*
3 * libfdt - Flat Device Tree manipulation
4 * Testcase for fdt_node_check_compatible()
5 * Copyright (C) 2006 David Gibson, IBM Corporation.
David Gibson32b6bd32007-10-17 11:23:57 +10006 */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11#include <stdint.h>
12
David Gibson32b6bd32007-10-17 11:23:57 +100013#include <libfdt.h>
14
15#include "tests.h"
16#include "testdata.h"
17
David Gibson01a2d8a2008-08-04 15:30:13 +100018static void check_compatible(const void *fdt, const char *path,
19 const char *compat)
David Gibson32b6bd32007-10-17 11:23:57 +100020{
21 int offset, err;
22
23 offset = fdt_path_offset(fdt, path);
24 if (offset < 0)
25 FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(offset));
26
27 err = fdt_node_check_compatible(fdt, offset, compat);
28 if (err < 0)
29 FAIL("fdt_node_check_compatible(%s): %s", path,
30 fdt_strerror(err));
31 if (err != 0)
32 FAIL("%s is not compatible with \"%s\"", path, compat);
33}
34
David Gibsoncc392f02017-10-29 22:56:54 +010035static void check_not_compatible(const void *fdt, const char *path,
36 const char *compat)
37{
38 int offset, err;
39
40 offset = fdt_path_offset(fdt, path);
41 if (offset < 0)
42 FAIL("fdt_path_offset(%s): %s", path, fdt_strerror(offset));
43
44 err = fdt_node_check_compatible(fdt, offset, compat);
45 if (err < 0)
46 FAIL("fdt_node_check_compatible(%s): %s", path,
47 fdt_strerror(err));
48 if (err == 0)
49 FAIL("%s is incorrectly compatible with \"%s\"", path, compat);
50}
51
David Gibson32b6bd32007-10-17 11:23:57 +100052int main(int argc, char *argv[])
53{
54 void *fdt;
55
56 test_init(argc, argv);
57 fdt = load_blob_arg(argc, argv);
58
59 check_compatible(fdt, "/", "test_tree1");
60 check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode1");
61 check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode");
David Gibsoncc392f02017-10-29 22:56:54 +010062 check_not_compatible(fdt, "/subnode@1/subsubnode", "subsubnode2");
David Gibson32b6bd32007-10-17 11:23:57 +100063 check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode2");
64 check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode");
David Gibsoncc392f02017-10-29 22:56:54 +010065 check_not_compatible(fdt, "/subnode@2/subsubnode", "subsubnode1");
David Gibson32b6bd32007-10-17 11:23:57 +100066
67 PASS();
68}