blob: 30a1cf3009614931ac48e6d79e1b59145345cb48 [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>
David Gibson857f54e2007-03-23 15:16:54 +110025#include <stdint.h>
David Gibson3da0f9a2006-11-27 16:21:28 +110026
27#include <fdt.h>
28#include <libfdt.h>
29
30#include "tests.h"
31#include "testdata.h"
32
33int main(int argc, char *argv[])
34{
David Gibson73d60922006-12-15 15:12:47 +110035 void *fdt;
David Gibsona6c76f92007-06-13 14:18:10 +100036 const uint32_t *intp;
David Gibsoncbf14102012-06-01 14:12:37 +100037 const uint64_t *int64p;
David Gibsona6c76f92007-06-13 14:18:10 +100038 const char *strp;
39 char *xstr;
David Gibson3da0f9a2006-11-27 16:21:28 +110040 int xlen, i;
41 int err;
42
43 test_init(argc, argv);
David Gibson4e6221c2006-11-28 17:20:01 +110044 fdt = load_blob_arg(argc, argv);
David Gibson3da0f9a2006-11-27 16:21:28 +110045
David Gibson9521dc52007-11-20 13:35:46 +110046 intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
David Gibson3da0f9a2006-11-27 16:21:28 +110047
48 verbose_printf("Old int value was 0x%08x\n", *intp);
David Gibson9521dc52007-11-20 13:35:46 +110049 err = fdt_setprop_inplace_cell(fdt, 0, "prop-int", ~TEST_VALUE_1);
David Gibson3da0f9a2006-11-27 16:21:28 +110050 if (err)
51 FAIL("Failed to set \"prop-int\" to 0x08%x: %s",
52 ~TEST_VALUE_1, fdt_strerror(err));
David Gibson9521dc52007-11-20 13:35:46 +110053 intp = check_getprop_cell(fdt, 0, "prop-int", ~TEST_VALUE_1);
David Gibson3da0f9a2006-11-27 16:21:28 +110054 verbose_printf("New int value is 0x%08x\n", *intp);
David Gibson63dc9c72007-09-18 11:44:04 +100055
David Gibson3da0f9a2006-11-27 16:21:28 +110056 strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
57 TEST_STRING_1);
58
David Gibsoncbf14102012-06-01 14:12:37 +100059
60 int64p = check_getprop_64(fdt, 0, "prop-int64", TEST_VALUE64_1);
61
62 verbose_printf("Old int64 value was 0x%016llx\n", *int64p);
63 err = fdt_setprop_inplace_u64(fdt, 0, "prop-int64", ~TEST_VALUE64_1);
64 if (err)
65 FAIL("Failed to set \"prop-int64\" to 0x016%llx: %s",
66 ~TEST_VALUE64_1, fdt_strerror(err));
67 int64p = check_getprop_64(fdt, 0, "prop-int64", ~TEST_VALUE64_1);
68 verbose_printf("New int64 value is 0x%016llx\n", *int64p);
69
70 strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
71 TEST_STRING_1);
72
David Gibson3da0f9a2006-11-27 16:21:28 +110073 verbose_printf("Old string value was \"%s\"\n", strp);
74 xstr = strdup(strp);
75 xlen = strlen(xstr);
76 for (i = 0; i < xlen; i++)
77 xstr[i] = toupper(xstr[i]);
78 err = fdt_setprop_inplace(fdt, 0, "prop-str", xstr, xlen+1);
79 if (err)
80 FAIL("Failed to set \"prop-str\" to \"%s\": %s",
81 xstr, fdt_strerror(err));
82
83 strp = check_getprop(fdt, 0, "prop-str", xlen+1, xstr);
David Gibson63dc9c72007-09-18 11:44:04 +100084 verbose_printf("New string value is \"%s\"\n", strp);
David Gibson3da0f9a2006-11-27 16:21:28 +110085
86 PASS();
87}