2 * Testcase for dtc expression support
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
37 #define TE(expr) { #expr, (expr) }
47 TE(3*2+1), TE(3*(2+1)),
48 TE(1+2*3), TE((1+2)*3),
49 TE(1 < 2), TE(2 < 1), TE(1 < 1),
50 TE(1 <= 2), TE(2 <= 1), TE(1 <= 1),
51 TE(1 > 2), TE(2 > 1), TE(1 > 1),
52 TE(1 >= 2), TE(2 >= 1), TE(1 >= 1),
53 TE(1 == 1), TE(1 == 2),
54 TE(1 != 1), TE(1 != 2),
55 TE(0xabcdabcd & 0xffff0000),
56 TE(0xdead4110 ^ 0xf0f0f0f0),
57 TE(0xabcd0000 | 0x0000abcd),
60 TE(0 && 0), TE(17 && 0), TE(0 && 17), TE(17 && 17),
61 TE(0 || 0), TE(17 || 0), TE(0 || 17), TE(17 || 17),
62 TE(!0), TE(!1), TE(!17), TE(!!0), TE(!!17),
63 TE(0 ? 17 : 39), TE(1 ? 17 : 39), TE(17 ? 0xdeadbeef : 0xabcd1234),
64 TE(11 * 257 * 1321517ULL),
65 TE(123456790 - 4/2 + 17%4),
68 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
70 int main(int argc, char *argv[])
77 test_init(argc, argv);
79 if ((argc == 3) && (strcmp(argv[1], "-g") == 0)) {
80 FILE *f = fopen(argv[2], "w");
83 FAIL("Couldn't open \"%s\" for output: %s\n",
84 argv[2], strerror(errno));
86 fprintf(f, "/dts-v1/;\n");
88 fprintf(f, "\texpressions = <\n");
89 for (i = 0; i < ARRAY_SIZE(expr_table); i++)
90 fprintf(f, "\t\t(%s)\n", expr_table[i].expr);
95 fdt = load_blob_arg(argc, argv);
97 res = fdt_getprop(fdt, 0, "expressions", &reslen);
100 FAIL("Error retreiving expression results: %s\n",
101 fdt_strerror(reslen));
103 if (reslen != (ARRAY_SIZE(expr_table) * sizeof(uint32_t)))
104 FAIL("Unexpected length of results %d instead of %zd\n",
105 reslen, ARRAY_SIZE(expr_table) * sizeof(uint32_t));
107 for (i = 0; i < ARRAY_SIZE(expr_table); i++)
108 if (fdt32_to_cpu(res[i]) != expr_table[i].result)
109 FAIL("Incorrect result for expression \"%s\","
110 " 0x%x instead of 0x%x\n",
111 expr_table[i].expr, fdt32_to_cpu(res[i]),
112 expr_table[i].result);