blob: f674ec6f637e56c21c32757193755257571c50ee [file] [log] [blame]
David Gibson3da0f9a2006-11-27 16:21:28 +11001/*
2 * libfdt - Flat Device Tree manipulation
3 * Testcase for fdt_setprop_inplace()
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
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <ctype.h>
25
26#include <fdt.h>
27#include <libfdt.h>
28
29#include "tests.h"
30#include "testdata.h"
31
32int main(int argc, char *argv[])
33{
David Gibson73d60922006-12-15 15:12:47 +110034 void *fdt;
David Gibson3da0f9a2006-11-27 16:21:28 +110035 uint32_t *intp;
36 char *strp, *xstr;
37 int xlen, i;
38 int err;
39
40 test_init(argc, argv);
David Gibson4e6221c2006-11-28 17:20:01 +110041 fdt = load_blob_arg(argc, argv);
David Gibson3da0f9a2006-11-27 16:21:28 +110042
43 intp = check_getprop_typed(fdt, 0, "prop-int", TEST_VALUE_1);
44
45 verbose_printf("Old int value was 0x%08x\n", *intp);
46 err = fdt_setprop_inplace_typed(fdt, 0, "prop-int", ~TEST_VALUE_1);
47 if (err)
48 FAIL("Failed to set \"prop-int\" to 0x08%x: %s",
49 ~TEST_VALUE_1, fdt_strerror(err));
50 intp = check_getprop_typed(fdt, 0, "prop-int", ~TEST_VALUE_1);
51 verbose_printf("New int value is 0x%08x\n", *intp);
52
53 strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
54 TEST_STRING_1);
55
56 verbose_printf("Old string value was \"%s\"\n", strp);
57 xstr = strdup(strp);
58 xlen = strlen(xstr);
59 for (i = 0; i < xlen; i++)
60 xstr[i] = toupper(xstr[i]);
61 err = fdt_setprop_inplace(fdt, 0, "prop-str", xstr, xlen+1);
62 if (err)
63 FAIL("Failed to set \"prop-str\" to \"%s\": %s",
64 xstr, fdt_strerror(err));
65
66 strp = check_getprop(fdt, 0, "prop-str", xlen+1, xstr);
67 verbose_printf("New string value is \"%s\"\n", strp);
68
69 PASS();
70}