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

« back to all changes in this revision

Viewing changes to tests/node_offset_by_compatible.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_node_offset_by_compatible()
 
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
#include <stdarg.h>
 
25
 
 
26
#include <fdt.h>
 
27
#include <libfdt.h>
 
28
 
 
29
#include "tests.h"
 
30
#include "testdata.h"
 
31
 
 
32
void check_search(void *fdt, const char *compat, ...)
 
33
{
 
34
        va_list ap;
 
35
        int offset = -1, target;
 
36
 
 
37
        va_start(ap, compat);
 
38
        do {
 
39
                target = va_arg(ap, int);
 
40
                verbose_printf("Searching (target = %d): %d ->",
 
41
                               target, offset);
 
42
                offset = fdt_node_offset_by_compatible(fdt, offset, compat);
 
43
                verbose_printf("%d\n", offset);
 
44
 
 
45
                if (offset != target)
 
46
                        FAIL("fdt_node_offset_by_compatible(%s) returns %d "
 
47
                             "instead of %d", compat, offset, target);
 
48
        } while (target >= 0);
 
49
 
 
50
        va_end(ap);
 
51
}
 
52
 
 
53
int main(int argc, char *argv[])
 
54
{
 
55
        void *fdt;
 
56
        int subnode1_offset, subnode2_offset;
 
57
        int subsubnode1_offset, subsubnode2_offset;
 
58
 
 
59
        test_init(argc, argv);
 
60
        fdt = load_blob_arg(argc, argv);
 
61
 
 
62
        subnode1_offset = fdt_path_offset(fdt, "/subnode@1");
 
63
        subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
 
64
        subsubnode1_offset = fdt_path_offset(fdt, "/subnode@1/subsubnode");
 
65
        subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");
 
66
 
 
67
        if ((subnode1_offset < 0) || (subnode2_offset < 0)
 
68
            || (subsubnode1_offset < 0) || (subsubnode2_offset < 0))
 
69
                FAIL("Can't find required nodes");
 
70
 
 
71
        check_search(fdt, "test_tree1", 0, -FDT_ERR_NOTFOUND);
 
72
        check_search(fdt, "subnode1", subnode1_offset, -FDT_ERR_NOTFOUND);
 
73
        check_search(fdt, "subsubnode1", subsubnode1_offset, -FDT_ERR_NOTFOUND);
 
74
        check_search(fdt, "subsubnode2", subsubnode2_offset, -FDT_ERR_NOTFOUND);
 
75
        /* Eek.. HACK to make this work whatever the order in the
 
76
         * example tree */
 
77
        if (subsubnode1_offset < subsubnode2_offset)
 
78
                check_search(fdt, "subsubnode", subsubnode1_offset,
 
79
                             subsubnode2_offset, -FDT_ERR_NOTFOUND);
 
80
        else
 
81
                check_search(fdt, "subsubnode", subsubnode2_offset,
 
82
                             subsubnode1_offset, -FDT_ERR_NOTFOUND);
 
83
        check_search(fdt, "nothing-like-this", -FDT_ERR_NOTFOUND);
 
84
 
 
85
        PASS();
 
86
}