summaryrefslogtreecommitdiff
path: root/payloads/libpayload/tests/cbfs-x86-test.c
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2013-03-09 10:36:10 +0100
committerStefan Reinauer <stefan.reinauer@coreboot.org>2013-03-22 00:35:32 +0100
commit36b6f367c064e9d5d64bc2246bf7cc85bb7c62d3 (patch)
tree2d47a5f9922ad456e856a67bfb4ed489bc734cc2 /payloads/libpayload/tests/cbfs-x86-test.c
parentb02c873190990698350a7c2a9bce52ce81c0f1b2 (diff)
downloadcoreboot-36b6f367c064e9d5d64bc2246bf7cc85bb7c62d3.tar.xz
libpayload: initial test case + tiny "framework"
This adds a test case for using CBFS images that reside in RAM and a Makefile to run it (and maybe other tests in the future). The test concerns an issue in libcbfs when using x86 style CBFS images in non-canonical locations (eg. when loading CBFS images for processing). Use with "make run" inside the tests directory. Change-Id: I1af3792a1451728ff9594ba7f0410027cdecb59d Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/2623 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'payloads/libpayload/tests/cbfs-x86-test.c')
-rw-r--r--payloads/libpayload/tests/cbfs-x86-test.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/payloads/libpayload/tests/cbfs-x86-test.c b/payloads/libpayload/tests/cbfs-x86-test.c
new file mode 100644
index 0000000000..81029656fc
--- /dev/null
+++ b/payloads/libpayload/tests/cbfs-x86-test.c
@@ -0,0 +1,34 @@
+/* system headers */
+#include <stdlib.h>
+#include <stdio.h>
+
+/* libpayload headers */
+#include "cbfs.h"
+
+int fail(const char* str)
+{
+ fprintf(stderr, "%s", str);
+ exit(1);
+}
+
+int main(int argc, char** argv)
+{
+ FILE *cbfs = fopen("data/cbfs-x86.bin", "rb");
+ if (!cbfs) fail("could not open test file\n");
+ if (fseek(cbfs, 0, SEEK_END) != 0) fail("seek to end failed\n");
+
+ long size = ftell(cbfs);
+ if (size == -1) fail("could not determine file size\n");
+ if (fseek(cbfs, 0, SEEK_SET) != 0) fail("seek to start failed\n");
+
+ void *data = malloc(size);
+ if (!data) fail("could not allocate buffer\n");
+
+ if (fread(data, size, 1, cbfs) != 1) fail("could not read data\n");
+ if (fclose(cbfs)) fail("could not close file\n");
+
+ if (setup_cbfs_from_ram(data, size) != 0) fail("could not setup CBFS in RAM\n");
+ struct cbfs_file *file = cbfs_find("foo");
+ if (file == NULL) fail("could not find file in CBFS\n");
+ exit(0);
+}