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
parent
1087504bb3
commit
9b0e4fe260
|
@ -348,7 +348,7 @@ libfdt_tests () {
|
||||||
run_test sw_states
|
run_test sw_states
|
||||||
|
|
||||||
# Resizing tests
|
# Resizing tests
|
||||||
for mode in resize realloc; do
|
for mode in resize realloc newalloc; do
|
||||||
run_test sw_tree1 $mode
|
run_test sw_tree1 $mode
|
||||||
tree1_tests sw_tree1.test.dtb
|
tree1_tests sw_tree1.test.dtb
|
||||||
tree1_tests unfinished_tree1.test.dtb
|
tree1_tests unfinished_tree1.test.dtb
|
||||||
|
|
|
@ -35,10 +35,13 @@ static enum {
|
||||||
FIXED = 0,
|
FIXED = 0,
|
||||||
RESIZE,
|
RESIZE,
|
||||||
REALLOC,
|
REALLOC,
|
||||||
|
NEWALLOC,
|
||||||
} alloc_mode;
|
} alloc_mode;
|
||||||
|
|
||||||
static void realloc_fdt(void **fdt, size_t *size, bool created)
|
static void realloc_fdt(void **fdt, size_t *size, bool created)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
switch (alloc_mode) {
|
switch (alloc_mode) {
|
||||||
case FIXED:
|
case FIXED:
|
||||||
if (!(*fdt))
|
if (!(*fdt))
|
||||||
|
@ -52,7 +55,10 @@ static void realloc_fdt(void **fdt, size_t *size, bool created)
|
||||||
*fdt = xmalloc(SPACE);
|
*fdt = xmalloc(SPACE);
|
||||||
} else if (*size < SPACE) {
|
} else if (*size < SPACE) {
|
||||||
*size += 1;
|
*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 {
|
} else {
|
||||||
FAIL("Ran out of space");
|
FAIL("Ran out of space");
|
||||||
}
|
}
|
||||||
|
@ -61,10 +67,30 @@ static void realloc_fdt(void **fdt, size_t *size, bool created)
|
||||||
case REALLOC:
|
case REALLOC:
|
||||||
*size += 1;
|
*size += 1;
|
||||||
*fdt = xrealloc(*fdt, *size);
|
*fdt = xrealloc(*fdt, *size);
|
||||||
if (created)
|
if (created) {
|
||||||
fdt_resize(*fdt, *fdt, *size);
|
err = fdt_resize(*fdt, *fdt, *size);
|
||||||
|
if (err < 0)
|
||||||
|
FAIL("fdt_resize() failed: %s",
|
||||||
|
fdt_strerror(err));
|
||||||
|
}
|
||||||
return;
|
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:
|
default:
|
||||||
CONFIG("Bad allocation mode");
|
CONFIG("Bad allocation mode");
|
||||||
}
|
}
|
||||||
|
@ -101,6 +127,9 @@ int main(int argc, char *argv[])
|
||||||
} else if (streq(argv[1], "realloc")) {
|
} else if (streq(argv[1], "realloc")) {
|
||||||
alloc_mode = REALLOC;
|
alloc_mode = REALLOC;
|
||||||
size = 0;
|
size = 0;
|
||||||
|
} else if (streq(argv[1], "newalloc")) {
|
||||||
|
alloc_mode = NEWALLOC;
|
||||||
|
size = 0;
|
||||||
} else {
|
} else {
|
||||||
char *endp;
|
char *endp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue