2 * libfdt - Flat Device Tree manipulation
3 * Test labels within values
4 * Copyright (C) 2008 David Gibson, IBM Corporation.
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.
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.
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
35 const char *labelname;
39 struct val_label labels1[] = {
45 struct val_label labels2[] = {
53 struct val_label labels3[] = {
61 static void check_prop_labels(void *sohandle, void *fdt, const char *name,
62 const struct val_label* labels, int n)
64 const struct fdt_property *prop;
69 prop = fdt_get_property(fdt, 0, name, &len);
71 FAIL("Couldn't locate property \"%s\"", name);
73 p = dlsym(sohandle, name);
75 FAIL("Couldn't locate label symbol \"%s\"", name);
77 if (p != (const char *)prop)
78 FAIL("Label \"%s\" does not point to correct property", name);
80 for (i = 0; i < n; i++) {
81 int off = labels[i].propoff;
86 p = dlsym(sohandle, labels[i].labelname);
88 FAIL("Couldn't locate label symbol \"%s\"", name);
90 if ((p - prop->data) != off)
91 FAIL("Label \"%s\" points to offset %ld instead of %d"
92 "in property \"%s\"", labels[i].labelname,
93 (long)(p - prop->data), off, name);
97 int main(int argc, char *argv[])
103 test_init(argc, argv);
105 CONFIG("Usage: %s <so file>", argv[0]);
107 sohandle = dlopen(argv[1], RTLD_NOW);
109 FAIL("Couldn't dlopen() %s", argv[1]);
111 fdt = dlsym(sohandle, "dt_blob_start");
113 FAIL("Couldn't locate \"dt_blob_start\" symbol in %s",
116 err = fdt_check_header(fdt);
118 FAIL("%s contains invalid tree: %s", argv[1],
122 check_prop_labels(sohandle, fdt, "prop1", labels1, ARRAY_SIZE(labels1));
123 check_prop_labels(sohandle, fdt, "prop2", labels2, ARRAY_SIZE(labels2));
124 check_prop_labels(sohandle, fdt, "prop3", labels3, ARRAY_SIZE(labels3));