Browse Source

tests: Improve fdt_resize() tests

We primarily test fdt_resize() in the sw_tree1 testcase, but it has
some deficiencies:

  - It didn't check for errors actually originating in fdt_resize(),
    just for errors before and after

  - It only tested cases where the resized buffer was at the same
    address as the original one, whereas fdt_resize() is also supposed
    to work if the new buffer is entirely separate, or partly
    overlapping

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
main
David Gibson 6 years ago
parent
commit
9b0e4fe260
  1. 2
      tests/run_tests.sh
  2. 35
      tests/sw_tree1.c

2
tests/run_tests.sh

@ -348,7 +348,7 @@ libfdt_tests () { @@ -348,7 +348,7 @@ libfdt_tests () {
run_test sw_states

# Resizing tests
for mode in resize realloc; do
for mode in resize realloc newalloc; do
run_test sw_tree1 $mode
tree1_tests sw_tree1.test.dtb
tree1_tests unfinished_tree1.test.dtb

35
tests/sw_tree1.c

@ -35,10 +35,13 @@ static enum { @@ -35,10 +35,13 @@ static enum {
FIXED = 0,
RESIZE,
REALLOC,
NEWALLOC,
} alloc_mode;

static void realloc_fdt(void **fdt, size_t *size, bool created)
{
int err;

switch (alloc_mode) {
case FIXED:
if (!(*fdt))
@ -52,7 +55,10 @@ static void realloc_fdt(void **fdt, size_t *size, bool created) @@ -52,7 +55,10 @@ static void realloc_fdt(void **fdt, size_t *size, bool created)
*fdt = xmalloc(SPACE);
} else if (*size < SPACE) {
*size += 1;
fdt_resize(*fdt, *fdt, *size);
err = fdt_resize(*fdt, *fdt, *size);
if (err < 0)
FAIL("fdt_resize() failed: %s",
fdt_strerror(err));
} else {
FAIL("Ran out of space");
}
@ -61,9 +67,29 @@ static void realloc_fdt(void **fdt, size_t *size, bool created) @@ -61,9 +67,29 @@ static void realloc_fdt(void **fdt, size_t *size, bool created)
case REALLOC:
*size += 1;
*fdt = xrealloc(*fdt, *size);
if (created)
fdt_resize(*fdt, *fdt, *size);
if (created) {
err = fdt_resize(*fdt, *fdt, *size);
if (err < 0)
FAIL("fdt_resize() failed: %s",
fdt_strerror(err));
}
return;

case NEWALLOC: {
void *buf;

*size += 1;
buf = xmalloc(*size);
if (created) {
err = fdt_resize(*fdt, buf, *size);
if (err < 0)
FAIL("fdt_resize() failed: %s",
fdt_strerror(err));
}
free(*fdt);
*fdt = buf;
return;
}

default:
CONFIG("Bad allocation mode");
@ -101,6 +127,9 @@ int main(int argc, char *argv[]) @@ -101,6 +127,9 @@ int main(int argc, char *argv[])
} else if (streq(argv[1], "realloc")) {
alloc_mode = REALLOC;
size = 0;
} else if (streq(argv[1], "newalloc")) {
alloc_mode = NEWALLOC;
size = 0;
} else {
char *endp;


Loading…
Cancel
Save