2019-06-20 23:19:41 +02:00
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
2006-12-01 06:59:43 +01:00
|
|
|
/*
|
|
|
|
* libfdt - Flat Device Tree manipulation
|
|
|
|
* Testcase for fdt_setprop()
|
|
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2007-03-23 05:16:54 +01:00
|
|
|
#include <stdint.h>
|
2006-12-01 06:59:43 +01:00
|
|
|
|
|
|
|
#include <libfdt.h>
|
|
|
|
|
|
|
|
#include "tests.h"
|
|
|
|
#include "testdata.h"
|
|
|
|
|
|
|
|
#define SPACE 65536
|
|
|
|
#define NEW_STRING "here is quite a long test string, blah blah blah"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-12-15 05:12:47 +01:00
|
|
|
void *fdt;
|
2006-12-01 06:59:43 +01:00
|
|
|
void *buf;
|
2007-06-13 06:18:10 +02:00
|
|
|
const uint32_t *intp;
|
|
|
|
const char *strp;
|
2006-12-01 06:59:43 +01:00
|
|
|
int err;
|
|
|
|
|
|
|
|
test_init(argc, argv);
|
|
|
|
fdt = load_blob_arg(argc, argv);
|
|
|
|
|
|
|
|
buf = xmalloc(SPACE);
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
err = fdt_open_into(fdt, buf, SPACE);
|
|
|
|
if (err)
|
2006-12-01 06:59:43 +01:00
|
|
|
FAIL("fdt_open_into(): %s", fdt_strerror(err));
|
|
|
|
|
2006-12-15 05:12:47 +01:00
|
|
|
fdt = buf;
|
|
|
|
|
libfdt: Abolish _typed() variants, add _cell() variants
In a number of places through libfdt and its tests, we have *_typed()
macro variants on functions which use gcc's typeof and statement
expression extensions to allow passing literals where the underlying
function takes a buffer and size.
These seemed like a good idea at the time, but in fact they have some
problems. They use typeof and statement expressions, extensions I'd
prefer to avoid for portability. Plus, they have potential gotchas -
although they'll deal with the size of the thing passed, they won't
deal with other representation issues (like endianness) and results
could be very strange if the type of the expression passed isn't what
you think it is.
In fact, the only users of these _typed() macros were when the value
passed is a single cell (32-bit integer). Therefore, this patch
removes all these _typed() macros and replaces them with explicit
_cell() variants which handle a single 32-bit integer, and which also
perform endian convesions as appropriate.
With this in place, it now becomes easy to use standardized big-endian
representation for integer valued properties in the testcases,
regardless of the platform we're running on. We therefore do that,
which has the additional advantage that all the example trees created
during a test run are now byte-for-byte identical regardless of
platform.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2007-11-20 03:35:46 +01:00
|
|
|
intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
|
2006-12-01 06:59:43 +01:00
|
|
|
|
|
|
|
verbose_printf("Old int value was 0x%08x\n", *intp);
|
|
|
|
err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING);
|
|
|
|
if (err)
|
|
|
|
FAIL("Failed to set \"prop-int\" to \"%s\": %s",
|
|
|
|
NEW_STRING, fdt_strerror(err));
|
|
|
|
|
|
|
|
strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING);
|
|
|
|
verbose_printf("New value is \"%s\"\n", strp);
|
2007-09-18 03:44:04 +02:00
|
|
|
|
2006-12-01 06:59:43 +01:00
|
|
|
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
|
|
|
|
TEST_STRING_1);
|
|
|
|
|
|
|
|
verbose_printf("Old string value was \"%s\"\n", strp);
|
2017-02-24 01:12:50 +01:00
|
|
|
err = fdt_setprop_empty(fdt, 0, "prop-str");
|
2006-12-01 06:59:43 +01:00
|
|
|
if (err)
|
|
|
|
FAIL("Failed to empty \"prop-str\": %s",
|
|
|
|
fdt_strerror(err));
|
|
|
|
|
|
|
|
check_getprop(fdt, 0, "prop-str", 0, NULL);
|
|
|
|
|
2012-06-01 06:12:37 +02:00
|
|
|
err = fdt_setprop_u32(fdt, 0, "prop-u32", TEST_VALUE_2);
|
|
|
|
if (err)
|
|
|
|
FAIL("Failed to set \"prop-u32\" to 0x%08x: %s",
|
|
|
|
TEST_VALUE_2, fdt_strerror(err));
|
|
|
|
check_getprop_cell(fdt, 0, "prop-u32", TEST_VALUE_2);
|
|
|
|
|
|
|
|
err = fdt_setprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2);
|
|
|
|
if (err)
|
|
|
|
FAIL("Failed to set \"prop-cell\" to 0x%08x: %s",
|
|
|
|
TEST_VALUE_2, fdt_strerror(err));
|
|
|
|
check_getprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2);
|
|
|
|
|
|
|
|
err = fdt_setprop_u64(fdt, 0, "prop-u64", TEST_VALUE64_1);
|
|
|
|
if (err)
|
|
|
|
FAIL("Failed to set \"prop-u64\" to 0x%016llx: %s",
|
|
|
|
TEST_VALUE64_1, fdt_strerror(err));
|
|
|
|
check_getprop_64(fdt, 0, "prop-u64", TEST_VALUE64_1);
|
|
|
|
|
2006-12-01 06:59:43 +01:00
|
|
|
PASS();
|
|
|
|
}
|