~ubuntu-branches/ubuntu/saucy/device-tree-compiler/saucy

« back to all changes in this revision

Viewing changes to tests/path_offset.c

  • Committer: Steve Langasek
  • Date: 2011-02-28 17:57:27 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: steve.langasek@linaro.org-20110228175727-le7jcacnya18tqhz
mergeĀ upstreamĀ 1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libfdt - Flat Device Tree manipulation
 
3
 *      Testcase for fdt_path_offset()
 
4
 * Copyright (C) 2006 David Gibson, IBM Corporation.
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public License
 
8
 * as published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 */
 
20
#include <stdlib.h>
 
21
#include <stdio.h>
 
22
#include <string.h>
 
23
#include <stdint.h>
 
24
 
 
25
#include <fdt.h>
 
26
#include <libfdt.h>
 
27
 
 
28
#include "tests.h"
 
29
#include "testdata.h"
 
30
 
 
31
int check_subnode(void *fdt, int parent, const char *name)
 
32
{
 
33
        int offset;
 
34
        const struct fdt_node_header *nh;
 
35
        uint32_t tag;
 
36
 
 
37
        verbose_printf("Checking subnode \"%s\" of %d...", name, parent);
 
38
        offset = fdt_subnode_offset(fdt, parent, name);
 
39
        verbose_printf("offset %d...", offset);
 
40
        if (offset < 0)
 
41
                FAIL("fdt_subnode_offset(\"%s\"): %s", name, fdt_strerror(offset));
 
42
        nh = fdt_offset_ptr(fdt, offset, sizeof(*nh));
 
43
        verbose_printf("pointer %p\n", nh);
 
44
        if (! nh)
 
45
                FAIL("NULL retrieving subnode \"%s\"", name);
 
46
 
 
47
        tag = fdt32_to_cpu(nh->tag);
 
48
 
 
49
        if (tag != FDT_BEGIN_NODE)
 
50
                FAIL("Incorrect tag 0x%08x on property \"%s\"", tag, name);
 
51
        if (!nodename_eq(nh->name, name))
 
52
                FAIL("Subnode name mismatch \"%s\" instead of \"%s\"",
 
53
                     nh->name, name);
 
54
 
 
55
        return offset;
 
56
}
 
57
 
 
58
int main(int argc, char *argv[])
 
59
{
 
60
        void *fdt;
 
61
        int root_offset;
 
62
        int subnode1_offset, subnode2_offset;
 
63
        int subnode1_offset_p, subnode2_offset_p;
 
64
        int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
 
65
        int subsubnode1_offset_p, subsubnode2_offset_p, subsubnode2_offset2_p;
 
66
 
 
67
        test_init(argc, argv);
 
68
        fdt = load_blob_arg(argc, argv);
 
69
 
 
70
        root_offset = fdt_path_offset(fdt, "/");
 
71
        if (root_offset < 0)
 
72
                FAIL("fdt_path_offset(\"/\") failed: %s",
 
73
                     fdt_strerror(root_offset));
 
74
        else if (root_offset != 0)
 
75
                FAIL("fdt_path_offset(\"/\") returns incorrect offset %d",
 
76
                     root_offset);
 
77
        subnode1_offset = check_subnode(fdt, 0, "subnode@1");
 
78
        subnode2_offset = check_subnode(fdt, 0, "subnode@2");
 
79
 
 
80
        subnode1_offset_p = fdt_path_offset(fdt, "/subnode@1");
 
81
        subnode2_offset_p = fdt_path_offset(fdt, "/subnode@2");
 
82
 
 
83
        if (subnode1_offset != subnode1_offset_p)
 
84
                FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
 
85
                     subnode1_offset, subnode1_offset_p);
 
86
 
 
87
        if (subnode2_offset != subnode2_offset_p)
 
88
                FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
 
89
                     subnode2_offset, subnode2_offset_p);
 
90
 
 
91
        subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
 
92
        subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
 
93
        subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");
 
94
 
 
95
        subsubnode1_offset_p = fdt_path_offset(fdt, "/subnode@1/subsubnode");
 
96
        subsubnode2_offset_p = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
 
97
        subsubnode2_offset2_p = fdt_path_offset(fdt, "/subnode@2/subsubnode");
 
98
 
 
99
        if (subsubnode1_offset != subsubnode1_offset_p)
 
100
                FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
 
101
                     subsubnode1_offset, subsubnode1_offset_p);
 
102
 
 
103
        if (subsubnode2_offset != subsubnode2_offset_p)
 
104
                FAIL("Mismatch between subnode_offset (%d) and path_offset (%d)",
 
105
                     subsubnode2_offset, subsubnode2_offset_p);
 
106
 
 
107
        PASS();
 
108
}