[PATCH 2/4] tests: Enhance truncated_memrsv to test fdt_open_into()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



We already check that libfdt's r/o functions can deal properly with
malformed blobs, where the memreserve block is not correct.

Add a test for fdt_open_into(), which also queries the memreserve block,
and uses the return value as an offset into a buffer.

Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>
---
 tests/truncated_memrsv.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/truncated_memrsv.c b/tests/truncated_memrsv.c
index d78036c..9defef3 100644
--- a/tests/truncated_memrsv.c
+++ b/tests/truncated_memrsv.c
@@ -18,7 +18,8 @@
 int main(int argc, char *argv[])
 {
 	void *fdt = &truncated_memrsv;
-	int err;
+	char *buf;
+	int err, bufsize;
 	uint64_t addr, size;
 
 	test_init(argc, argv);
@@ -46,5 +47,12 @@ int main(int argc, char *argv[])
 		FAIL("fdt_get_mem_rsv(1) returned %d instead of -FDT_ERR_BADOFFSET",
 		     err);
 
+	bufsize = fdt_totalsize(fdt);
+	buf = xmalloc(bufsize);
+	err = fdt_open_into(fdt, buf, bufsize);
+	if (err != -FDT_ERR_TRUNCATED)
+		FAIL("fdt_open_into() returned %d instead of -FDT_ERR_TRUNCATED",
+		     err);
+
 	PASS();
 }
-- 
2.17.5




[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux