Patrick Georgi (patrick@georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2623
-gerrit
commit 61f3782d76feb2ffba79066cd8eec38ff1c2ca69 Author: Patrick Georgi patrick@georgi-clan.de Date: Sat Mar 9 10:36:10 2013 +0100
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 --- payloads/libpayload/tests/Makefile | 13 ++++++++++ payloads/libpayload/tests/cbfs-x86-test.c | 34 ++++++++++++++++++++++++++ payloads/libpayload/tests/data/cbfs-x86.bin | Bin 0 -> 200 bytes payloads/libpayload/tests/libpayload-config.h | 30 +++++++++++++++++++++++ 4 files changed, 77 insertions(+)
diff --git a/payloads/libpayload/tests/Makefile b/payloads/libpayload/tests/Makefile new file mode 100644 index 0000000..9728722 --- /dev/null +++ b/payloads/libpayload/tests/Makefile @@ -0,0 +1,13 @@ +CC=gcc -g -m32 +INCLUDES=-I. -I../include -I../include/x86 +TARGETS=cbfs-x86-test + +cbfs-x86-test: cbfs-x86-test.c ../arch/x86/rom_media.c ../libcbfs/ram_media.c ../libcbfs/cbfs.c + $(CC) -o $@ $^ $(INCLUDES) + + +all: $(TARGETS) + +run: all + for i in $(TARGETS); do ./$$i; done + diff --git a/payloads/libpayload/tests/cbfs-x86-test.c b/payloads/libpayload/tests/cbfs-x86-test.c new file mode 100644 index 0000000..8102965 --- /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); +} diff --git a/payloads/libpayload/tests/data/cbfs-x86.bin b/payloads/libpayload/tests/data/cbfs-x86.bin new file mode 100644 index 0000000..b217b50 Binary files /dev/null and b/payloads/libpayload/tests/data/cbfs-x86.bin differ diff --git a/payloads/libpayload/tests/libpayload-config.h b/payloads/libpayload/tests/libpayload-config.h new file mode 100644 index 0000000..6fe99a9 --- /dev/null +++ b/payloads/libpayload/tests/libpayload-config.h @@ -0,0 +1,30 @@ +/* + * Automatically generated C config: don't edit + * libpayload version: 0.2.0 + * Sat Mar 9 10:22:45 2013 + */ +#define AUTOCONF_INCLUDED +#define CONFIG_SPEAKER 1 +#define CONFIG_STORAGE 1 +#define CONFIG_LIBC 1 +#define CONFIG_CBFS 1 +#define CONFIG_VGA_VIDEO_CONSOLE 1 +#define CONFIG_SERIAL_CONSOLE 1 +#define CONFIG_PC_KEYBOARD 1 +#define CONFIG_ARCH_X86 1 +#define CONFIG_STORAGE_ATA 1 +#define CONFIG_ARCH_SPECIFIC_OPTIONS 1 +#define CONFIG_STORAGE_AHCI_ONLY_TESTED 1 +#define CONFIG_X86_SERIAL_CONSOLE 1 +#define CONFIG_PDCURSES 1 +#define CONFIG_NVRAM 1 +#define CONFIG_PC_KEYBOARD_LAYOUT_US 1 +#define CONFIG_STORAGE_AHCI 1 +#define CONFIG_MULTIBOOT 1 +#define CONFIG_SERIAL_IOBASE 0x3f8 +#define CONFIG_CURSES 1 +#define CONFIG_CBMEM_CONSOLE 1 +#define CONFIG_LITTLE_ENDIAN 1 +#define CONFIG_PCI 1 +#define CONFIG_STORAGE_ATAPI 1 +#define CONFIG_VIDEO_CONSOLE 1