Add qemu 2.4.0
[kvmfornfv.git] / qemu / dtc / tests / setprop.c
1 /*
2  * libfdt - Flat Device Tree manipulation
3  *      Testcase for fdt_setprop()
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 #include <stdint.h>
26
27 #include <libfdt.h>
28
29 #include "tests.h"
30 #include "testdata.h"
31
32 #define SPACE           65536
33 #define NEW_STRING      "here is quite a long test string, blah blah blah"
34
35 int main(int argc, char *argv[])
36 {
37         void *fdt;
38         void *buf;
39         const uint32_t *intp;
40         const char *strp;
41         int err;
42
43         test_init(argc, argv);
44         fdt = load_blob_arg(argc, argv);
45
46         buf = xmalloc(SPACE);
47
48         err = fdt_open_into(fdt, buf, SPACE);
49         if (err)
50                 FAIL("fdt_open_into(): %s", fdt_strerror(err));
51
52         fdt = buf;
53
54         intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
55
56         verbose_printf("Old int value was 0x%08x\n", *intp);
57         err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING);
58         if (err)
59                 FAIL("Failed to set \"prop-int\" to \"%s\": %s",
60                      NEW_STRING, fdt_strerror(err));
61
62         strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING);
63         verbose_printf("New value is \"%s\"\n", strp);
64
65         strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
66                              TEST_STRING_1);
67
68         verbose_printf("Old string value was \"%s\"\n", strp);
69         err = fdt_setprop(fdt, 0, "prop-str", NULL, 0);
70         if (err)
71                 FAIL("Failed to empty \"prop-str\": %s",
72                      fdt_strerror(err));
73
74         check_getprop(fdt, 0, "prop-str", 0, NULL);
75
76         err = fdt_setprop_u32(fdt, 0, "prop-u32", TEST_VALUE_2);
77         if (err)
78                 FAIL("Failed to set \"prop-u32\" to 0x%08x: %s",
79                      TEST_VALUE_2, fdt_strerror(err));
80         check_getprop_cell(fdt, 0, "prop-u32", TEST_VALUE_2);
81
82         err = fdt_setprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2);
83         if (err)
84                 FAIL("Failed to set \"prop-cell\" to 0x%08x: %s",
85                      TEST_VALUE_2, fdt_strerror(err));
86         check_getprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2);
87
88         err = fdt_setprop_u64(fdt, 0, "prop-u64", TEST_VALUE64_1);
89         if (err)
90                 FAIL("Failed to set \"prop-u64\" to 0x%016llx: %s",
91                      TEST_VALUE64_1, fdt_strerror(err));
92         check_getprop_64(fdt, 0, "prop-u64", TEST_VALUE64_1);
93         
94         PASS();
95 }