Name of user not set #1003143 has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/lib/fmap/fmap_config.h A tests/include/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 563 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/1
diff --git a/tests/include/lib/fmap/fmap_config.h b/tests/include/lib/fmap/fmap_config.h new file mode 100644 index 0000000..c735330 --- /dev/null +++ b/tests/include/lib/fmap/fmap_config.h @@ -0,0 +1,87 @@ +#ifndef FMAPTOOL_GENERATED_HEADER_H_ +#define FMAPTOOL_GENERATED_HEADER_H_ + +/* + * This file was generated using fmaptool from util/cbfstools using + * src/mainboard/google/octopus/chromeos.fmd + * FMAP_OFFSET was changed to zero for testing purposes. + */ +#define FMAP_OFFSET 0x204000 +#define FMAP_SIZE 0x620 + +#define FMAP_SECTION_FLASH_START 0 +#define FMAP_SECTION_FLASH_SIZE 0x1000000 +#define FMAP_SECTION_WP_RO_START 0 +#define FMAP_SECTION_WP_RO_SIZE 0x400000 +#define FMAP_SECTION_SI_DESC_START 0 +#define FMAP_SECTION_SI_DESC_SIZE 0x1000 +#define FMAP_SECTION_IFWI_START 0x1000 +#define FMAP_SECTION_IFWI_SIZE 0x1ff000 +#define FMAP_SECTION_RO_VPD_START 0x200000 +#define FMAP_SECTION_RO_VPD_SIZE 0x4000 +#define FMAP_SECTION_RO_SECTION_START 0x204000 +#define FMAP_SECTION_RO_SECTION_SIZE 0x1fc000 +#define FMAP_SECTION_FMAP_START 0x204000 +#define FMAP_SECTION_FMAP_SIZE 0x800 +#define FMAP_SECTION_RO_FRID_START 0x204800 +#define FMAP_SECTION_RO_FRID_SIZE 0x40 +#define FMAP_SECTION_RO_FRID_PAD_START 0x204840 +#define FMAP_SECTION_RO_FRID_PAD_SIZE 0x7c0 +#define FMAP_SECTION_COREBOOT_START 0x205000 +#define FMAP_SECTION_COREBOOT_SIZE 0x1f8000 +#define FMAP_SECTION_GBB_START 0x3fd000 +#define FMAP_SECTION_GBB_SIZE 0x3000 +#define FMAP_SECTION_MISC_RW_START 0x400000 +#define FMAP_SECTION_MISC_RW_SIZE 0x30000 +#define FMAP_SECTION_RW_PRESERVE_START 0x400000 +#define FMAP_SECTION_RW_PRESERVE_SIZE 0x21000 +#define FMAP_SECTION_UNIFIED_MRC_CACHE_START 0x400000 +#define FMAP_SECTION_UNIFIED_MRC_CACHE_SIZE 0x21000 +#define FMAP_SECTION_RECOVERY_MRC_CACHE_START 0x400000 +#define FMAP_SECTION_RECOVERY_MRC_CACHE_SIZE 0x10000 +#define FMAP_SECTION_RW_MRC_CACHE_START 0x410000 +#define FMAP_SECTION_RW_MRC_CACHE_SIZE 0x10000 +#define FMAP_SECTION_RW_VAR_MRC_CACHE_START 0x420000 +#define FMAP_SECTION_RW_VAR_MRC_CACHE_SIZE 0x1000 +#define FMAP_SECTION_RW_ELOG_START 0x421000 +#define FMAP_SECTION_RW_ELOG_SIZE 0x3000 +#define FMAP_SECTION_RW_SHARED_START 0x424000 +#define FMAP_SECTION_RW_SHARED_SIZE 0x4000 +#define FMAP_SECTION_SHARED_DATA_START 0x424000 +#define FMAP_SECTION_SHARED_DATA_SIZE 0x2000 +#define FMAP_SECTION_VBLOCK_DEV_START 0x426000 +#define FMAP_SECTION_VBLOCK_DEV_SIZE 0x2000 +#define FMAP_SECTION_RW_VPD_START 0x428000 +#define FMAP_SECTION_RW_VPD_SIZE 0x2000 +#define FMAP_SECTION_RW_NVRAM_START 0x42a000 +#define FMAP_SECTION_RW_NVRAM_SIZE 0x5000 +#define FMAP_SECTION_FPF_STATUS_START 0x42f000 +#define FMAP_SECTION_FPF_STATUS_SIZE 0x1000 +#define FMAP_SECTION_RW_SECTION_A_START 0x430000 +#define FMAP_SECTION_RW_SECTION_A_SIZE 0x480000 +#define FMAP_SECTION_VBLOCK_A_START 0x430000 +#define FMAP_SECTION_VBLOCK_A_SIZE 0x10000 +#define FMAP_SECTION_FW_MAIN_A_START 0x440000 +#define FMAP_SECTION_FW_MAIN_A_SIZE 0x46ffc0 +#define FMAP_SECTION_RW_FWID_A_START 0x8affc0 +#define FMAP_SECTION_RW_FWID_A_SIZE 0x40 +#define FMAP_SECTION_RW_SECTION_B_START 0x8b0000 +#define FMAP_SECTION_RW_SECTION_B_SIZE 0x480000 +#define FMAP_SECTION_VBLOCK_B_START 0x8b0000 +#define FMAP_SECTION_VBLOCK_B_SIZE 0x10000 +#define FMAP_SECTION_FW_MAIN_B_START 0x8c0000 +#define FMAP_SECTION_FW_MAIN_B_SIZE 0x46ffc0 +#define FMAP_SECTION_RW_FWID_B_START 0xd2ffc0 +#define FMAP_SECTION_RW_FWID_B_SIZE 0x40 +#define FMAP_SECTION_SMMSTORE_START 0xd30000 +#define FMAP_SECTION_SMMSTORE_SIZE 0x40000 +#define FMAP_SECTION_RW_LEGACY_START 0xd70000 +#define FMAP_SECTION_RW_LEGACY_SIZE 0x1c0000 +#define FMAP_SECTION_BIOS_UNUSABLE_START 0xf30000 +#define FMAP_SECTION_BIOS_UNUSABLE_SIZE 0x4f000 +#define FMAP_SECTION_DEVICE_EXTENSION_START 0xf7f000 +#define FMAP_SECTION_DEVICE_EXTENSION_SIZE 0x80000 +//#define FMAP_SECTION_UNUSED_HOLE_START 0xfff000 +#define FMAP_SECTION_UNUSED_HOLE_SIZE 0x1000 + +#endif diff --git a/tests/include/lib/fmap/fmap_data.h b/tests/include/lib/fmap/fmap_data.h new file mode 100644 index 0000000..343feef --- /dev/null +++ b/tests/include/lib/fmap/fmap_data.h @@ -0,0 +1,148 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_ +#define TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_ + +/* + * This file was converted using `xxd -i` from binary output of + * fmaptool from util/cbfstools. Data is based on output generated by + * mentioned tool using src/mainboard/google/octopus/chromeos.fmd file. + */ + +unsigned char tests_fmap_bin[] = { +0x5f, 0x5f, 0x46, 0x4d, 0x41, 0x50, 0x5f, 0x5f, 0x01, 0x01, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x46, 0x4c, +0x41, 0x53, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x40, 0x00, 0x57, 0x50, 0x5f, 0x52, 0x4f, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x53, 0x49, +0x5f, 0x44, 0x45, 0x53, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0xf0, 0x1f, 0x00, 0x49, 0x46, 0x57, 0x49, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x40, 0x00, 0x00, 0x52, 0x4f, +0x5f, 0x56, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x40, 0x20, 0x00, +0x00, 0xc0, 0x1f, 0x00, 0x52, 0x4f, 0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, +0x4f, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x46, 0x4d, +0x41, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x20, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x4f, 0x5f, 0x46, 0x52, 0x49, 0x44, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x40, 0x48, 0x20, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x52, 0x4f, +0x5f, 0x46, 0x52, 0x49, 0x44, 0x5f, 0x50, 0x41, 0x44, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x20, 0x00, +0x00, 0x80, 0x1f, 0x00, 0x43, 0x4f, 0x52, 0x45, 0x42, 0x4f, 0x4f, 0x54, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0xd0, 0x3f, 0x00, 0x00, 0x30, 0x00, 0x00, 0x47, 0x42, +0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, +0x00, 0x00, 0x03, 0x00, 0x4d, 0x49, 0x53, 0x43, 0x5f, 0x52, 0x57, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x02, 0x00, 0x52, 0x57, +0x5f, 0x50, 0x52, 0x45, 0x53, 0x45, 0x52, 0x56, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, +0x00, 0x10, 0x02, 0x00, 0x55, 0x4e, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5f, +0x4d, 0x52, 0x43, 0x5f, 0x43, 0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x52, 0x45, +0x43, 0x4f, 0x56, 0x45, 0x52, 0x59, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, +0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, +0x00, 0x00, 0x01, 0x00, 0x52, 0x57, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, +0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x10, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x56, 0x41, 0x52, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, 0x41, 0x43, +0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x42, 0x00, +0x00, 0x30, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x45, 0x4c, 0x4f, 0x47, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x00, 0x00, 0x40, 0x42, 0x00, 0x00, 0x40, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x48, 0x41, 0x52, 0x45, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x42, 0x00, +0x00, 0x20, 0x00, 0x00, 0x53, 0x48, 0x41, 0x52, 0x45, 0x44, 0x5f, 0x44, +0x41, 0x54, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x60, 0x42, 0x00, 0x00, 0x20, 0x00, 0x00, 0x56, 0x42, +0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x44, 0x45, 0x56, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x42, 0x00, +0x00, 0x20, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x56, 0x50, 0x44, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x00, 0x00, 0xa0, 0x42, 0x00, 0x00, 0x50, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x4e, 0x56, 0x52, 0x41, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xf0, 0x42, 0x00, +0x00, 0x10, 0x00, 0x00, 0x46, 0x50, 0x46, 0x5f, 0x53, 0x54, 0x41, 0x54, +0x55, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x48, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x41, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, +0x00, 0x00, 0x01, 0x00, 0x56, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x41, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0xc0, 0xff, 0x46, 0x00, 0x46, 0x57, +0x5f, 0x4d, 0x41, 0x49, 0x4e, 0x5f, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x8a, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x46, 0x57, 0x49, 0x44, 0x5f, +0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x48, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x42, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, +0x00, 0x00, 0x01, 0x00, 0x56, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x42, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0xc0, 0xff, 0x46, 0x00, 0x46, 0x57, +0x5f, 0x4d, 0x41, 0x49, 0x4e, 0x5f, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xd2, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x46, 0x57, 0x49, 0x44, 0x5f, +0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x04, 0x00, 0x53, 0x4d, +0x4d, 0x53, 0x54, 0x4f, 0x52, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xd7, 0x00, +0x00, 0x00, 0x1c, 0x00, 0x52, 0x57, 0x5f, 0x4c, 0x45, 0x47, 0x41, 0x43, +0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x00, 0xf0, 0x04, 0x00, 0x42, 0x49, +0x4f, 0x53, 0x5f, 0x55, 0x4e, 0x55, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf7, 0x00, +0x00, 0x00, 0x08, 0x00, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x45, +0x58, 0x54, 0x45, 0x4e, 0x53, 0x49, 0x4f, 0x4e, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x10, 0x00, 0x00, 0x55, 0x4e, +0x55, 0x53, 0x45, 0x44, 0x5f, 0x48, 0x4f, 0x4c, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +unsigned int tests_fmap_bin_len = 1568; + + +#endif /* TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_ */ diff --git a/tests/lib/Makefile.inc b/tests/lib/Makefile.inc index 5783f18..6948588 100644 --- a/tests/lib/Makefile.inc +++ b/tests/lib/Makefile.inc @@ -9,6 +9,7 @@ tests-y += cbmem_console-romstage-test tests-y += cbmem_console-ramstage-test tests-y += list-test +tests-y += fmap-test
string-test-srcs += tests/lib/string-test.c string-test-srcs += src/lib/string.c @@ -44,3 +45,10 @@ list-test-srcs += tests/lib/list-test.c list-test-srcs += src/lib/list.c
+fmap-test-srcs += tests/lib/fmap-test.c +fmap-test-srcs += src/lib/fmap.c +fmap-test-srcs += tests/stubs/console.c +fmap-test-srcs += src/lib/boot_device.c +fmap-test-srcs += src/commonlib/region.c +fmap-test-cflags += -I tests/include/lib/fmap +fmap-test-cflags += -I 3rdparty/vboot/firmware/include diff --git a/tests/lib/fmap-test.c b/tests/lib/fmap-test.c new file mode 100644 index 0000000..2b7605d --- /dev/null +++ b/tests/lib/fmap-test.c @@ -0,0 +1,320 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <stdlib.h> +#include <string.h> + +#include <fmap.h> +#include <commonlib/region.h> + +#include <tests/test.h> + +#include <lib/fmap/fmap_data.h> +#include <lib/fmap/fmap_config.h> + +static struct region_device *rdev_root = NULL; +static char *flash_buffer = NULL; +static size_t flash_buffer_size = 0; + +static void *local_mmap(const struct region_device *rdev, size_t offset, size_t size) +{ + if (offset >= FMAP_SECTION_FLASH_START + && offset < FMAP_SECTION_FLASH_START + FMAP_SECTION_FLASH_SIZE) + return flash_buffer + offset; + + return NULL; +} + +static int local_unmap(const struct region_device *rdev, void *mapping) +{ + return 0; +} + +static ssize_t local_readat(const struct region_device *rdev, void *buffer, + size_t offset, size_t size) +{ + if (size + offset >= flash_buffer_size) + return -1; + + size = MIN(size, flash_buffer_size - offset); + + memcpy(buffer, flash_buffer + offset, size); + + return size; +} + +static ssize_t local_writeat(const struct region_device *rdev, const void *buffer, + size_t offset, size_t size) +{ + if (size + offset >= flash_buffer_size) + return -1; + + size = MIN(size, flash_buffer_size - offset); + + memcpy(flash_buffer + offset, buffer, size); + + return size; +} + +static ssize_t local_eraseat(const struct region_device *rdev, + size_t offset, size_t size) +{ + if (size + offset >= flash_buffer_size) + return -1; + + size = MIN(size, flash_buffer_size - offset); + + memset(flash_buffer + offset, 0, size); + + return size; +} + +static int setup_fmap_region_device(void **state) +{ + // Setup callbacks + struct region_device_ops *rdev_ops = malloc(sizeof(*rdev_ops)); + rdev_ops->mmap = local_mmap; + rdev_ops->munmap = local_unmap; + rdev_ops->readat = local_readat; + rdev_ops->writeat = local_writeat; + rdev_ops->eraseat = local_eraseat; + + // Prepare root region device + struct region_device rdev_new_root = REGION_DEV_INIT(rdev_ops, + FMAP_SECTION_FLASH_START, FMAP_SECTION_FLASH_SIZE); + rdev_root = malloc(sizeof(rdev_new_root)); + memcpy(rdev_root, &rdev_new_root, sizeof(rdev_new_root)); + + // Prepare fmap region device + struct region_device rdev_fmap = REGION_DEV_INIT(rdev_ops, + FMAP_SECTION_FMAP_START, FMAP_SECTION_FMAP_SIZE); + rdev_fmap.root = rdev_root; + + // Pass fmap region device to tests as state + *state = malloc(sizeof(rdev_fmap)); + memcpy(*state, &rdev_fmap, sizeof(rdev_fmap)); + + // Prepare flash buffer with dummy data and FMAP + flash_buffer = malloc(FMAP_SECTION_FLASH_SIZE); + flash_buffer_size = FMAP_SECTION_FLASH_SIZE; + memset(flash_buffer, 0, FMAP_SECTION_FLASH_SIZE); + for (int i = 0; i < FMAP_SECTION_FMAP_START; ++i) + flash_buffer[i] = 'a' + i % ('z' - 'a'); + memcpy(flash_buffer + FMAP_SECTION_FMAP_START, tests_fmap_bin, FMAP_SIZE); + for (int i = FMAP_SECTION_FMAP_START + FMAP_SECTION_FMAP_SIZE; + i < FMAP_SECTION_FLASH_SIZE; ++i) + flash_buffer[i] = 'a' + i % ('z' - 'a'); + + return 0; +} + +static int teardown_fmap_region_device(void **state) +{ + struct region_device *rdev_fmap = *state; + + free((void *)rdev_fmap->ops); + free(rdev_fmap); + + free(rdev_root); + rdev_root = NULL; + + free(flash_buffer); + flash_buffer = NULL; + flash_buffer_size = 0; + + return 0; +} + +void boot_device_init(void) +{ + // Setup in unit test setup function +} + +const struct region_device *boot_device_ro(void) +{ + return rdev_root; +} + +const struct region_device *boot_device_rw(void) +{ + return rdev_root; +} + +static void test_fmap_locate_area_as_rdev(void **state) +{ + struct region_device *rdev = *state; + + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", rdev)); + + // Check if locating area second time works + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", rdev)); + + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RECOVERY_MRC_CACHE", rdev)); + + // Expect error when looking for non-existent area + assert_int_equal(-1, fmap_locate_area_as_rdev("NONEXISTENT_AREA", rdev)); + + assert_int_equal(-1, fmap_locate_area_as_rdev("", rdev)); + + // Expect error when passing invalid references + assert_int_equal(-1, fmap_locate_area_as_rdev(NULL, rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev("RW_SECTION_A", NULL)); +} + + +static void test_fmap_locate_area_as_rdev_rw(void **state) +{ + struct region_device *rdev = *state; + + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", rdev)); + + // Check if locating area second time works + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", rdev)); + + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", rdev)); + + // Expect error when looking for non-existent area + assert_int_equal(-1, fmap_locate_area_as_rdev_rw("NONEXISTENT_AREA", rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev_rw("", rdev)); + + // Expect error when passing invalid references + assert_int_equal(-1, fmap_locate_area_as_rdev_rw(NULL, rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", NULL)); +} + +static void test_fmap_locate_area(void **state) +{ + (void)state; + struct region ar; + + assert_int_not_equal(-1, fmap_locate_area("COREBOOT", &ar)); + + // Check if locating area second time works + assert_int_not_equal(-1, fmap_locate_area("COREBOOT", &ar)); + + assert_int_not_equal(-1, fmap_locate_area("GBB", &ar)); + + // Expect error when looking for non-existent area + assert_int_equal(-1, fmap_locate_area("NONEXISTENT_AREA", &ar)); + assert_int_equal(-1, fmap_locate_area("", &ar)); + + // Expect error when passing invalid references + assert_int_equal(-1, fmap_locate_area(NULL, &ar)); + assert_int_equal(-1, fmap_locate_area("SHARED_DATA", NULL)); +} + +static void test_fmap_find_region_name(void **state) +{ + (void)state; + struct region ar; + char found_area_name[FMAP_STRLEN] = ""; + const char *area_name = "RW_PRESERVE"; + + // Find area by name + assert_int_not_equal(-1, fmap_locate_area(area_name, &ar)); + + // Find name by previously find area + assert_int_not_equal(-1, fmap_find_region_name(&ar, found_area_name)); + assert_string_equal(area_name, found_area_name); + + // Expect error when passing invalid buffer + assert_int_equal(-1, fmap_find_region_name(&ar, NULL)); + + // Try to find non-existent area + ar.offset = 2142037; + ar.size = 636; + assert_int_equal(-1, fmap_find_region_name(&ar, found_area_name)); + + // Expect error when passing invalid region pointer + assert_int_equal(-1, fmap_find_region_name(NULL, found_area_name)); +} + +static void test_fmap_read_area(void **state) +{ + (void)state; + struct region ar; + char *buffer = malloc(FMAP_SECTION_RW_SECTION_A_SIZE); + + fmap_locate_area("RW_SECTION_A", &ar); + assert_int_equal(FMAP_SECTION_RW_SECTION_A_SIZE, + fmap_read_area("RW_SECTION_A", buffer, FMAP_SECTION_RW_SECTION_A_SIZE)); + assert_memory_equal(flash_buffer + FMAP_SECTION_RW_SECTION_A_START, buffer, + FMAP_SECTION_RW_SECTION_A_SIZE); + + assert_int_equal(-1, + fmap_read_area("NONEXISTENT_SECTION", + buffer, + FMAP_SECTION_RW_SECTION_A_SIZE)); + + assert_int_equal(-1, fmap_read_area(NULL, buffer, FMAP_SECTION_RW_SECTION_A_SIZE)); + assert_int_equal(-1, + fmap_read_area("RW_SECTION_A", NULL, FMAP_SECTION_RW_SECTION_A_SIZE)); + + free(buffer); +} + +static void test_fmap_overwrite_area(void **state) +{ + (void)state; + struct region ar; + char *buffer1 = malloc(FMAP_SECTION_FW_MAIN_A_SIZE); + char *buffer2 = malloc(FMAP_SECTION_FW_MAIN_A_SIZE); + char *new_data = malloc(FMAP_SECTION_FW_MAIN_A_SIZE); + + fmap_locate_area("FW_MAIN_A", &ar); + assert_int_equal(FMAP_SECTION_FW_MAIN_A_SIZE, + fmap_read_area("FW_MAIN_A", buffer1, FMAP_SECTION_FW_MAIN_A_SIZE)); + + memset(new_data, 0x42, FMAP_SECTION_FW_MAIN_A_SIZE); + assert_int_equal(FMAP_SECTION_FW_MAIN_A_SIZE, + fmap_overwrite_area("FW_MAIN_A", + new_data, + FMAP_SECTION_FW_MAIN_A_SIZE)); + + assert_int_equal(FMAP_SECTION_FW_MAIN_A_SIZE, + fmap_read_area("FW_MAIN_A", buffer2, FMAP_SECTION_FW_MAIN_A_SIZE)); + + assert_memory_not_equal(buffer1, buffer2, FMAP_SECTION_FW_MAIN_A_SIZE); + assert_memory_equal(buffer2, new_data, FMAP_SECTION_FW_MAIN_A_SIZE); + + assert_int_equal(-1, + fmap_overwrite_area("NONEXISTENT_SECTION", + new_data, + FMAP_SECTION_FW_MAIN_A_SIZE)); + + assert_int_equal(-1, + fmap_overwrite_area(NULL, new_data, FMAP_SECTION_FW_MAIN_A_SIZE)); + + assert_int_equal(-1, + fmap_overwrite_area("FW_MAIN_A", NULL, FMAP_SECTION_FW_MAIN_A_SIZE)); + + + free(buffer1); + free(buffer2); + free(new_data); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev, + setup_fmap_region_device, + teardown_fmap_region_device), + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw, + setup_fmap_region_device, + teardown_fmap_region_device), + cmocka_unit_test_setup_teardown(test_fmap_locate_area, + setup_fmap_region_device, + teardown_fmap_region_device), + cmocka_unit_test_setup_teardown(test_fmap_find_region_name, + setup_fmap_region_device, + teardown_fmap_region_device), + cmocka_unit_test_setup_teardown(test_fmap_read_area, + setup_fmap_region_device, + teardown_fmap_region_device), + cmocka_unit_test_setup_teardown(test_fmap_overwrite_area, + setup_fmap_region_device, + teardown_fmap_region_device), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +}
Paul Fagerburg has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 1:
Strange that the tests with invalid parameters are causing a stack fault instead of returning an error; I wonder if the build is not pulling in the ancestor CL?
Name of user not set #1003143 has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 1:
Patch Set 1:
Strange that the tests with invalid parameters are causing a stack fault instead of returning an error; I wonder if the build is not pulling in the ancestor CL?
Build is correct. In ancestor commit I missed few functions that could crash the program. Once again tests prove their usefulness. :)
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Paul Fagerburg, Julius Werner, Jan Dabros,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/48557
to look at the new patch set (#2).
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/lib/fmap/fmap_config.h A tests/include/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 563 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/2
Paul Fagerburg has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 2: Code-Review+2
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 2:
(11 comments)
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... File tests/include/lib/fmap/fmap_config.h:
PS2: Always put a license line, even on generated files, just to be safe.
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 7: * FMAP_OFFSET was changed to zero for testing purposes. Doesn't look like it's zero below?
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 84: //#define FMAP_SECTION_UNUSED_HOLE_START 0xfff000 ??
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... File tests/include/lib/fmap/fmap_data.h:
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 3: #ifndef TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_ I don't think you should use tests/include/lib for this, because then all the headers in there clash paths with coreboot's normal include/lib/ (okay, I guess coreboot technically doesn't have an include/lib/ at the moment, but the name is still too generic). You should always use subdirectories that clearly indicate they're test headers and not normal parts of coreboot, like include/tests/ or include/stubs/ (I see this was already done for <lib/edid-test.h>... since that has the 'test' in the name it's not quite as bad, but I still think it should be moved to another subdirectory for consistency). (You can of course put it under include/tests/lib/ or something like that if you want to encode that it tests some of coreboot's lib/ code as well.)
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 145: 1568 nit: just use sizeof()?
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@18 PS2, Line 18: static void *local_mmap(const struct region_device *rdev, size_t offset, size_t size) I think you could just use a mem_region_device instead of all of this?
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@38 PS2, Line 38: size = MIN(size, flash_buffer_size - offset); Doesn't the check above make this unnecessary?
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@84 PS2, Line 84: rdev_root = malloc(sizeof(rdev_new_root)); I think you can just write
rdev_root = (struct region_device)REGION_DEV_INIT(...);
instead of the copying? If not, you can also just assign the members manually, there's no rule that you *have* to use REGION_DEV_INIT() if it makes the code for confusing than open-coding it.
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@146 PS2, Line 146: assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", rdev)); Please test for actual offsets, not just != -1.
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@161 PS2, Line 161: } Test the returned rdev, too? Make sure you cannot rdev_writeat() the RO version?
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@261 PS2, Line 261: FMAP_SECTION_FW_MAIN_A_SIZE Maybe make it smaller so you can also test that the remaining part of the region gets zeroed on overwrite?
Name of user not set #1003143 has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 2:
(11 comments)
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... File tests/include/lib/fmap/fmap_config.h:
PS2:
Always put a license line, even on generated files, just to be safe.
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 7: * FMAP_OFFSET was changed to zero for testing purposes.
Doesn't look like it's zero below?
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 84: //#define FMAP_SECTION_UNUSED_HOLE_START 0xfff000
??
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... File tests/include/lib/fmap/fmap_data.h:
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 3: #ifndef TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_
I don't think you should use tests/include/lib for this, because then all the headers in there clash […]
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/include/lib/fmap/fmap... PS2, Line 145: 1568
nit: just use sizeof()?
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@18 PS2, Line 18: static void *local_mmap(const struct region_device *rdev, size_t offset, size_t size)
I think you could just use a mem_region_device instead of all of this?
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@38 PS2, Line 38: size = MIN(size, flash_buffer_size - offset);
Doesn't the check above make this unnecessary?
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@84 PS2, Line 84: rdev_root = malloc(sizeof(rdev_new_root));
I think you can just write […]
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@146 PS2, Line 146: assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", rdev));
Please test for actual offsets, not just != -1.
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@161 PS2, Line 161: }
Test the returned rdev, too? Make sure you cannot rdev_writeat() the RO version?
Done
https://review.coreboot.org/c/coreboot/+/48557/2/tests/lib/fmap-test.c@261 PS2, Line 261: FMAP_SECTION_FW_MAIN_A_SIZE
Maybe make it smaller so you can also test that the remaining part of the region gets zeroed on over […]
Done
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Paul Fagerburg, Julius Werner, Jan Dabros,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/48557
to look at the new patch set (#3).
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/tests/lib/fmap/fmap_config.h A tests/include/tests/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 547 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/3
Paul Fagerburg has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 3:
(3 comments)
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@118 PS3, Line 118: /* assert_int_equal(-1, fmap_locate_area_as_rdev("RW_SECTION_A", NULL)); : * : * It is not allowed to pass NULL as region_device pointer. : */ Please remove the commented-out code. If needed, keep a comment that you're not testing a NULL pointer because it's not allowed, but don't have a complete line of code commented out.
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@153 PS3, Line 153: /* assert_int_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", NULL)); Same comment here - remove unused code instead of commenting it out.
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@232 PS3, Line 232: /* assert_int_equal(-1, fmap_read_area("RW_SECTION_A", NULL, section_size)); Remove unused code instead of commenting out
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Paul Fagerburg, Julius Werner, Jan Dabros,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/48557
to look at the new patch set (#4).
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/tests/lib/fmap/fmap_config.h A tests/include/tests/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 543 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/4
jacz@semihalf.com has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 4:
(3 comments)
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@118 PS3, Line 118: /* assert_int_equal(-1, fmap_locate_area_as_rdev("RW_SECTION_A", NULL)); : * : * It is not allowed to pass NULL as region_device pointer. : */
Please remove the commented-out code. […]
Done
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@153 PS3, Line 153: /* assert_int_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", NULL));
Same comment here - remove unused code instead of commenting it out.
Done
https://review.coreboot.org/c/coreboot/+/48557/3/tests/lib/fmap-test.c@232 PS3, Line 232: /* assert_int_equal(-1, fmap_read_area("RW_SECTION_A", NULL, section_size));
Remove unused code instead of commenting out
Done
Paul Fagerburg has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 4: Code-Review+1
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 4:
(10 comments)
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@94 PS4, Line 94: mem_rdev_fmap_ro.rdev.root = &mem_rdev_ro.rdev; What are you trying to do here? This isn't legal. MEM_REGION_DEV_RO_INIT already constructs a fully valid (root) rdev, don't muck around in the internals afterwards. The rdev API maintains some tricky internal invariants, you're only supposed to interact through it with the official accessors.
If you want a device that is chained off mem_rdev_ro instead, you can just do
struct region_device rdev; rdev_chain(&rdev, &mem_rdev_ro, FMAP_SECTION_FMAP_START, FMAP_SECTION_FMAP_SIZE);
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@97 PS4, Line 97: rdev ...and then here you immediately overwrite it here again... no, this is not how this API was designed. 'rdev' is an OUT-parameter to fmap_locate_area_as_rdev(). You don't need to initialize it at all, just allocate it on the stack. The function will fill it in for you. The way this is meant to be called is just
struct region_device rdev; fmap_locate_area_as_rdev("RO_VPD", &rdev);
You don't need to make any connection from mem_rdev_ro to your rdev yourself, the whole point is that the FMAP API is supposed to do that for you.
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@98 PS4, Line 98: assert_int_equal(FMAP_SECTION_RO_VPD_START, rdev->region.offset); Please use the region_device_offset() and region_device_sz() accessors instead of accessing rdev members directly.
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@118 PS4, Line 118: /* Function fmap_locate_area_as_rdev is not tested with NULL See comment style I mentioned in the other patch (or on https://doc.coreboot.org/coding_style.html#commenting).
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@154 PS4, Line 154: */ How about actually writing to it here, and then maybe looking it up as an RO rdev again to confirm your newly written data is visible?
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@164 PS4, Line 164: assert_int_equal(FMAP_SECTION_COREBOOT_START, ar.offset); For regions we also have accessors (region_offset()/region_sz()).
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@204 PS4, Line 204: ar.offset = 2142037; Would be good to test both an out-of-bounds area (like you're doing here) and an incorrect in-bounds area. Maybe also areas where either the start or the end offset is correct, but the size isn't.
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@221 PS4, Line 221: fmap_locate_area("RW_SECTION_A", &ar); Why is this call here? It does nothing and has nothing to do with the rest of the test. fmap_read_area() already does a lookup for the name you give it internally.
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@251 PS4, Line 251: fmap_locate_area(section_name, &ar); same as above
https://review.coreboot.org/c/coreboot/+/48557/4/tests/lib/fmap-test.c@261 PS4, Line 261: war typo
Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Paul Fagerburg, Julius Werner, Jan Dabros,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/48557
to look at the new patch set (#5).
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/tests/lib/fmap/fmap_config.h A tests/include/tests/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 567 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/5
Attention is currently required from: Julius Werner. jacz@semihalf.com has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 5:
(10 comments)
File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/comment/fcadff6e_f1bafb6c PS4, Line 94: mem_rdev_fmap_ro.rdev.root = &mem_rdev_ro.rdev;
What are you trying to do here? This isn't legal. […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/1be11c1c_31c3a0bf PS4, Line 97: rdev
...and then here you immediately overwrite it here again... […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/db18d33c_c3ee34a6 PS4, Line 98: assert_int_equal(FMAP_SECTION_RO_VPD_START, rdev->region.offset);
Please use the region_device_offset() and region_device_sz() accessors instead of accessing rdev mem […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/f888734e_38588355 PS4, Line 118: /* Function fmap_locate_area_as_rdev is not tested with NULL
See comment style I mentioned in the other patch (or on https://doc.coreboot.org/coding_style. […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/bd2ebc5e_110e6a25 PS4, Line 154: */
How about actually writing to it here, and then maybe looking it up as an RO rdev again to confirm y […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/93b833ff_b0c6fe7c PS4, Line 164: assert_int_equal(FMAP_SECTION_COREBOOT_START, ar.offset);
For regions we also have accessors (region_offset()/region_sz()).
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/0e9d0763_bc883294 PS4, Line 204: ar.offset = 2142037;
Would be good to test both an out-of-bounds area (like you're doing here) and an incorrect in-bounds […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/5bd75ce9_29d1f2e2 PS4, Line 221: fmap_locate_area("RW_SECTION_A", &ar);
Why is this call here? It does nothing and has nothing to do with the rest of the test. […]
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/195f0589_f7eafd47 PS4, Line 251: fmap_locate_area(section_name, &ar);
same as above
Done
https://review.coreboot.org/c/coreboot/+/48557/comment/6fbd5bfd_819bc6a2 PS4, Line 261: war
typo
Done
Attention is currently required from: Julius Werner. Hello build bot (Jenkins), Patrick Georgi, Martin Roth, Paul Fagerburg, Julius Werner, Jan Dabros,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/48557
to look at the new patch set (#6).
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 --- A tests/include/tests/lib/fmap/fmap_config.h A tests/include/tests/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 567 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/48557/6
Attention is currently required from: Julius Werner. jacz@semihalf.com has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 6:
(2 comments)
File tests/lib/fmap-test.c:
https://review.coreboot.org/c/coreboot/+/48557/comment/0cccca82_7d8cc84f PS4, Line 94: mem_rdev_fmap_ro.rdev.root = &mem_rdev_ro.rdev;
Done
Sure, You are right. This code is not necessary. This is leftover after I refactored boot_device_ro/rw from my implementation to mem_region_device.
https://review.coreboot.org/c/coreboot/+/48557/comment/e91ff098_745253cd PS4, Line 204: ar.offset = 2142037;
Done
Good idea. I added more cases testing areas outside flash region, overlapping with other sections or with incorrect offset or size.
Attention is currently required from: jacz@semihalf.com. Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 6: Code-Review+2
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
tests: Add lib/fmap-test test case
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I885ea05d509d3b1330de7a18531f310d290c6965 Reviewed-on: https://review.coreboot.org/c/coreboot/+/48557 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- A tests/include/tests/lib/fmap/fmap_config.h A tests/include/tests/lib/fmap/fmap_data.h M tests/lib/Makefile.inc A tests/lib/fmap-test.c 4 files changed, 567 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/tests/include/tests/lib/fmap/fmap_config.h b/tests/include/tests/lib/fmap/fmap_config.h new file mode 100644 index 0000000..0a2809b --- /dev/null +++ b/tests/include/tests/lib/fmap/fmap_config.h @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef FMAPTOOL_GENERATED_HEADER_H_ +#define FMAPTOOL_GENERATED_HEADER_H_ + +/* + * This file was generated using fmaptool from util/cbfstools using + * src/mainboard/google/octopus/chromeos.fmd + */ +#define FMAP_OFFSET 0x204000 +#define FMAP_SIZE 0x620 + +#define FMAP_SECTION_FLASH_START 0 +#define FMAP_SECTION_FLASH_SIZE 0x1000000 +#define FMAP_SECTION_WP_RO_START 0 +#define FMAP_SECTION_WP_RO_SIZE 0x400000 +#define FMAP_SECTION_SI_DESC_START 0 +#define FMAP_SECTION_SI_DESC_SIZE 0x1000 +#define FMAP_SECTION_IFWI_START 0x1000 +#define FMAP_SECTION_IFWI_SIZE 0x1ff000 +#define FMAP_SECTION_RO_VPD_START 0x200000 +#define FMAP_SECTION_RO_VPD_SIZE 0x4000 +#define FMAP_SECTION_RO_SECTION_START 0x204000 +#define FMAP_SECTION_RO_SECTION_SIZE 0x1fc000 +#define FMAP_SECTION_FMAP_START 0x204000 +#define FMAP_SECTION_FMAP_SIZE 0x800 +#define FMAP_SECTION_RO_FRID_START 0x204800 +#define FMAP_SECTION_RO_FRID_SIZE 0x40 +#define FMAP_SECTION_RO_FRID_PAD_START 0x204840 +#define FMAP_SECTION_RO_FRID_PAD_SIZE 0x7c0 +#define FMAP_SECTION_COREBOOT_START 0x205000 +#define FMAP_SECTION_COREBOOT_SIZE 0x1f8000 +#define FMAP_SECTION_GBB_START 0x3fd000 +#define FMAP_SECTION_GBB_SIZE 0x3000 +#define FMAP_SECTION_MISC_RW_START 0x400000 +#define FMAP_SECTION_MISC_RW_SIZE 0x30000 +#define FMAP_SECTION_RW_PRESERVE_START 0x400000 +#define FMAP_SECTION_RW_PRESERVE_SIZE 0x21000 +#define FMAP_SECTION_UNIFIED_MRC_CACHE_START 0x400000 +#define FMAP_SECTION_UNIFIED_MRC_CACHE_SIZE 0x21000 +#define FMAP_SECTION_RECOVERY_MRC_CACHE_START 0x400000 +#define FMAP_SECTION_RECOVERY_MRC_CACHE_SIZE 0x10000 +#define FMAP_SECTION_RW_MRC_CACHE_START 0x410000 +#define FMAP_SECTION_RW_MRC_CACHE_SIZE 0x10000 +#define FMAP_SECTION_RW_VAR_MRC_CACHE_START 0x420000 +#define FMAP_SECTION_RW_VAR_MRC_CACHE_SIZE 0x1000 +#define FMAP_SECTION_RW_ELOG_START 0x421000 +#define FMAP_SECTION_RW_ELOG_SIZE 0x3000 +#define FMAP_SECTION_RW_SHARED_START 0x424000 +#define FMAP_SECTION_RW_SHARED_SIZE 0x4000 +#define FMAP_SECTION_SHARED_DATA_START 0x424000 +#define FMAP_SECTION_SHARED_DATA_SIZE 0x2000 +#define FMAP_SECTION_VBLOCK_DEV_START 0x426000 +#define FMAP_SECTION_VBLOCK_DEV_SIZE 0x2000 +#define FMAP_SECTION_RW_VPD_START 0x428000 +#define FMAP_SECTION_RW_VPD_SIZE 0x2000 +#define FMAP_SECTION_RW_NVRAM_START 0x42a000 +#define FMAP_SECTION_RW_NVRAM_SIZE 0x5000 +#define FMAP_SECTION_FPF_STATUS_START 0x42f000 +#define FMAP_SECTION_FPF_STATUS_SIZE 0x1000 +#define FMAP_SECTION_RW_SECTION_A_START 0x430000 +#define FMAP_SECTION_RW_SECTION_A_SIZE 0x480000 +#define FMAP_SECTION_VBLOCK_A_START 0x430000 +#define FMAP_SECTION_VBLOCK_A_SIZE 0x10000 +#define FMAP_SECTION_FW_MAIN_A_START 0x440000 +#define FMAP_SECTION_FW_MAIN_A_SIZE 0x46ffc0 +#define FMAP_SECTION_RW_FWID_A_START 0x8affc0 +#define FMAP_SECTION_RW_FWID_A_SIZE 0x40 +#define FMAP_SECTION_RW_SECTION_B_START 0x8b0000 +#define FMAP_SECTION_RW_SECTION_B_SIZE 0x480000 +#define FMAP_SECTION_VBLOCK_B_START 0x8b0000 +#define FMAP_SECTION_VBLOCK_B_SIZE 0x10000 +#define FMAP_SECTION_FW_MAIN_B_START 0x8c0000 +#define FMAP_SECTION_FW_MAIN_B_SIZE 0x46ffc0 +#define FMAP_SECTION_RW_FWID_B_START 0xd2ffc0 +#define FMAP_SECTION_RW_FWID_B_SIZE 0x40 +#define FMAP_SECTION_SMMSTORE_START 0xd30000 +#define FMAP_SECTION_SMMSTORE_SIZE 0x40000 +#define FMAP_SECTION_RW_LEGACY_START 0xd70000 +#define FMAP_SECTION_RW_LEGACY_SIZE 0x1c0000 +#define FMAP_SECTION_BIOS_UNUSABLE_START 0xf30000 +#define FMAP_SECTION_BIOS_UNUSABLE_SIZE 0x4f000 +#define FMAP_SECTION_DEVICE_EXTENSION_START 0xf7f000 +#define FMAP_SECTION_DEVICE_EXTENSION_SIZE 0x80000 +#define FMAP_SECTION_UNUSED_HOLE_START 0xfff000 +#define FMAP_SECTION_UNUSED_HOLE_SIZE 0x1000 + +#endif diff --git a/tests/include/tests/lib/fmap/fmap_data.h b/tests/include/tests/lib/fmap/fmap_data.h new file mode 100644 index 0000000..eaeabd3 --- /dev/null +++ b/tests/include/tests/lib/fmap/fmap_data.h @@ -0,0 +1,148 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef TESTS_FMAP_DATA_H_ +#define TESTS_FMAP_DATA_H_ + +/* + * This file was converted using `xxd -i` from binary output of + * fmaptool from util/cbfstools. Data is based on output generated by + * mentioned tool using src/mainboard/google/octopus/chromeos.fmd file. + */ + +unsigned char tests_fmap_bin[] = { +0x5f, 0x5f, 0x46, 0x4d, 0x41, 0x50, 0x5f, 0x5f, 0x01, 0x01, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x46, 0x4c, +0x41, 0x53, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x40, 0x00, 0x57, 0x50, 0x5f, 0x52, 0x4f, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x53, 0x49, +0x5f, 0x44, 0x45, 0x53, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, +0x00, 0xf0, 0x1f, 0x00, 0x49, 0x46, 0x57, 0x49, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x40, 0x00, 0x00, 0x52, 0x4f, +0x5f, 0x56, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x40, 0x20, 0x00, +0x00, 0xc0, 0x1f, 0x00, 0x52, 0x4f, 0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, +0x4f, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x40, 0x20, 0x00, 0x00, 0x08, 0x00, 0x00, 0x46, 0x4d, +0x41, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x20, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x4f, 0x5f, 0x46, 0x52, 0x49, 0x44, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x40, 0x48, 0x20, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x52, 0x4f, +0x5f, 0x46, 0x52, 0x49, 0x44, 0x5f, 0x50, 0x41, 0x44, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x20, 0x00, +0x00, 0x80, 0x1f, 0x00, 0x43, 0x4f, 0x52, 0x45, 0x42, 0x4f, 0x4f, 0x54, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0xd0, 0x3f, 0x00, 0x00, 0x30, 0x00, 0x00, 0x47, 0x42, +0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, +0x00, 0x00, 0x03, 0x00, 0x4d, 0x49, 0x53, 0x43, 0x5f, 0x52, 0x57, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x02, 0x00, 0x52, 0x57, +0x5f, 0x50, 0x52, 0x45, 0x53, 0x45, 0x52, 0x56, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, +0x00, 0x10, 0x02, 0x00, 0x55, 0x4e, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5f, +0x4d, 0x52, 0x43, 0x5f, 0x43, 0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x52, 0x45, +0x43, 0x4f, 0x56, 0x45, 0x52, 0x59, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, +0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, +0x00, 0x00, 0x01, 0x00, 0x52, 0x57, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, +0x41, 0x43, 0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x10, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x56, 0x41, 0x52, 0x5f, 0x4d, 0x52, 0x43, 0x5f, 0x43, 0x41, 0x43, +0x48, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x42, 0x00, +0x00, 0x30, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x45, 0x4c, 0x4f, 0x47, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x00, 0x00, 0x40, 0x42, 0x00, 0x00, 0x40, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x48, 0x41, 0x52, 0x45, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x42, 0x00, +0x00, 0x20, 0x00, 0x00, 0x53, 0x48, 0x41, 0x52, 0x45, 0x44, 0x5f, 0x44, +0x41, 0x54, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x60, 0x42, 0x00, 0x00, 0x20, 0x00, 0x00, 0x56, 0x42, +0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x44, 0x45, 0x56, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x42, 0x00, +0x00, 0x20, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x56, 0x50, 0x44, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x00, 0x00, 0xa0, 0x42, 0x00, 0x00, 0x50, 0x00, 0x00, 0x52, 0x57, +0x5f, 0x4e, 0x56, 0x52, 0x41, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xf0, 0x42, 0x00, +0x00, 0x10, 0x00, 0x00, 0x46, 0x50, 0x46, 0x5f, 0x53, 0x54, 0x41, 0x54, +0x55, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x48, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x41, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00, +0x00, 0x00, 0x01, 0x00, 0x56, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x41, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0xc0, 0xff, 0x46, 0x00, 0x46, 0x57, +0x5f, 0x4d, 0x41, 0x49, 0x4e, 0x5f, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x8a, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x46, 0x57, 0x49, 0x44, 0x5f, +0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x48, 0x00, 0x52, 0x57, +0x5f, 0x53, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x42, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x00, +0x00, 0x00, 0x01, 0x00, 0x56, 0x42, 0x4c, 0x4f, 0x43, 0x4b, 0x5f, 0x42, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0xc0, 0xff, 0x46, 0x00, 0x46, 0x57, +0x5f, 0x4d, 0x41, 0x49, 0x4e, 0x5f, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xd2, 0x00, +0x40, 0x00, 0x00, 0x00, 0x52, 0x57, 0x5f, 0x46, 0x57, 0x49, 0x44, 0x5f, +0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xd3, 0x00, 0x00, 0x00, 0x04, 0x00, 0x53, 0x4d, +0x4d, 0x53, 0x54, 0x4f, 0x52, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xd7, 0x00, +0x00, 0x00, 0x1c, 0x00, 0x52, 0x57, 0x5f, 0x4c, 0x45, 0x47, 0x41, 0x43, +0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x00, 0xf0, 0x04, 0x00, 0x42, 0x49, +0x4f, 0x53, 0x5f, 0x55, 0x4e, 0x55, 0x53, 0x41, 0x42, 0x4c, 0x45, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf7, 0x00, +0x00, 0x00, 0x08, 0x00, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x45, +0x58, 0x54, 0x45, 0x4e, 0x53, 0x49, 0x4f, 0x4e, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x10, 0x00, 0x00, 0x55, 0x4e, +0x55, 0x53, 0x45, 0x44, 0x5f, 0x48, 0x4f, 0x4c, 0x45, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +unsigned int tests_fmap_bin_len = sizeof(tests_fmap_bin); + + +#endif /* TESTS_INCLUDE_LIB_FMAP_FMAP_DATA_H_ */ diff --git a/tests/lib/Makefile.inc b/tests/lib/Makefile.inc index 5783f18..dba27ec 100644 --- a/tests/lib/Makefile.inc +++ b/tests/lib/Makefile.inc @@ -9,6 +9,7 @@ tests-y += cbmem_console-romstage-test tests-y += cbmem_console-ramstage-test tests-y += list-test +tests-y += fmap-test
string-test-srcs += tests/lib/string-test.c string-test-srcs += src/lib/string.c @@ -44,3 +45,10 @@ list-test-srcs += tests/lib/list-test.c list-test-srcs += src/lib/list.c
+fmap-test-srcs += tests/lib/fmap-test.c +fmap-test-srcs += src/lib/fmap.c +fmap-test-srcs += tests/stubs/console.c +fmap-test-srcs += src/lib/boot_device.c +fmap-test-srcs += src/commonlib/region.c +fmap-test-cflags += -I tests/include/tests/lib/fmap +fmap-test-cflags += -I 3rdparty/vboot/firmware/include diff --git a/tests/lib/fmap-test.c b/tests/lib/fmap-test.c new file mode 100644 index 0000000..372bb85 --- /dev/null +++ b/tests/lib/fmap-test.c @@ -0,0 +1,323 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <stdlib.h> +#include <string.h> + +#include <tests/test.h> + +#include <fmap.h> +#include <commonlib/region.h> + +#include <tests/lib/fmap/fmap_data.h> +#include <tests/lib/fmap/fmap_config.h> + +static struct mem_region_device mem_rdev_rw; +static struct mem_region_device mem_rdev_ro; +static char *flash_buffer = NULL; +static size_t flash_buffer_size = 0; + +static void prepare_flash_buffer(void) +{ + /* Prepare flash buffer with dummy data and FMAP */ + flash_buffer = malloc(FMAP_SECTION_FLASH_SIZE); + flash_buffer_size = FMAP_SECTION_FLASH_SIZE; + + /* Fill first part of buffer with dummy data */ + for (int i = 0; i < FMAP_SECTION_FMAP_START; ++i) + flash_buffer[i] = 'a' + i % ('z' - 'a'); + + /* Copy FMAP section into buffer */ + memcpy(flash_buffer + FMAP_SECTION_FMAP_START, tests_fmap_bin, FMAP_SIZE); + + /* Fill rest of buffer with dummy data */ + for (int i = FMAP_SECTION_FMAP_START + FMAP_SECTION_FMAP_SIZE; + i < FMAP_SECTION_FLASH_SIZE; ++i) + flash_buffer[i] = 'a' + i % ('z' - 'a'); +} + +static int setup_fmap(void **state) +{ + prepare_flash_buffer(); + + mem_rdev_rw = (struct mem_region_device) + MEM_REGION_DEV_RW_INIT(flash_buffer, FMAP_SECTION_FLASH_SIZE); + + mem_rdev_ro = (struct mem_region_device) + MEM_REGION_DEV_RO_INIT(flash_buffer, FMAP_SECTION_FLASH_SIZE); + + return 0; +} + +static int teardown_fmap(void **state) +{ + struct mem_region_device empty = { + .base = NULL, + .rdev = { + .root = NULL, + .ops = NULL, + .region = { + .offset = 0, + .size = 0 + } + } + }; + + mem_rdev_rw = empty; + mem_rdev_ro = empty; + + free(flash_buffer); + flash_buffer = NULL; + flash_buffer_size = 0; + + return 0; +} + +void boot_device_init(void) +{ + /* Setup in unit test setup function */ +} + +const struct region_device *boot_device_ro(void) +{ + return &mem_rdev_rw.rdev; +} + +const struct region_device *boot_device_rw(void) +{ + return &mem_rdev_rw.rdev; +} + +static void test_fmap_locate_area_as_rdev(void **state) +{ + const char buffer[] = "abcdefghijk0123456789"; + struct region_device rdev; + + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", &rdev)); + assert_int_equal(FMAP_SECTION_RO_VPD_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_RO_VPD_SIZE, region_device_sz(&rdev)); + + /* Check if locating area second time works */ + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RO_VPD", &rdev)); + assert_int_equal(FMAP_SECTION_RO_VPD_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_RO_VPD_SIZE, region_device_sz(&rdev)); + + assert_int_not_equal(-1, fmap_locate_area_as_rdev("RECOVERY_MRC_CACHE", &rdev)); + assert_int_equal(FMAP_SECTION_RECOVERY_MRC_CACHE_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_RECOVERY_MRC_CACHE_SIZE, region_device_sz(&rdev)); + + /* Expect error when writing to read-only area */ + assert_int_equal(-1, rdev_writeat(&rdev, buffer, + region_device_offset(&rdev), sizeof(buffer))); + + /* Expect error when looking for incorrect area */ + assert_int_equal(-1, fmap_locate_area_as_rdev("NONEXISTENT_AREA", &rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev("", &rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev(NULL, &rdev)); + + /* Function fmap_locate_area_as_rdev is not tested with NULL + as region_device pointer as it is not allowed. */ +} + +static void test_fmap_locate_area_as_rdev_rw(void **state) +{ + struct region_device rdev; + size_t ro_rw_section_size = FMAP_SECTION_MISC_RW_SIZE; + char *buffer1 = malloc(ro_rw_section_size); + char *buffer2 = malloc(ro_rw_section_size); + char *dummy_data = malloc(ro_rw_section_size); + + /* Fill buffer with dummy data */ + for (int i = 0; i < ro_rw_section_size; ++i) + dummy_data[i] = '0' + i % ('9' - '0'); + + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", &rdev)); + assert_int_equal(FMAP_SECTION_RW_SECTION_A_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_RW_SECTION_A_SIZE, region_device_sz(&rdev)); + + /* Check if locating area second time works */ + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("RW_SECTION_A", &rdev)); + assert_int_equal(FMAP_SECTION_RW_SECTION_A_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_RW_SECTION_A_SIZE, region_device_sz(&rdev)); + + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", &rdev)); + assert_int_equal(FMAP_SECTION_MISC_RW_START, region_device_offset(&rdev)); + assert_int_equal(FMAP_SECTION_MISC_RW_SIZE, region_device_sz(&rdev)); + + + /* Expect error when looking for incorrect area */ + assert_int_equal(-1, fmap_locate_area_as_rdev_rw("NONEXISTENT_AREA", &rdev)); + assert_int_equal(-1, fmap_locate_area_as_rdev_rw("", &rdev)); + + /* Expect error when passing invalid references */ + assert_int_equal(-1, fmap_locate_area_as_rdev_rw(NULL, &rdev)); + + /* Function fmap_locate_area_as_rdev_rw is not tested with NULL + as region_device pointer as it is not allowed. */ + + /* Test if returned section region device is writable */ + assert_int_not_equal(-1, fmap_locate_area_as_rdev_rw("MISC_RW", &rdev)); + assert_int_equal(ro_rw_section_size, + rdev_readat(&rdev, buffer1, 0, ro_rw_section_size)); + assert_int_equal(ro_rw_section_size, + rdev_writeat(&rdev, dummy_data, 0, ro_rw_section_size)); + /* Check if written data is visible and correct after locating area as RO */ + assert_int_not_equal(-1, fmap_locate_area_as_rdev("MISC_RW", &rdev)); + assert_int_equal(ro_rw_section_size, + rdev_readat(&rdev, buffer2, 0, ro_rw_section_size)); + assert_memory_not_equal(buffer1, buffer2, ro_rw_section_size); + assert_memory_equal(dummy_data, buffer2, ro_rw_section_size); + + free(buffer1); + free(buffer2); + free(dummy_data); +} + +static void test_fmap_locate_area(void **state) +{ + struct region ar; + + /* Try to locate named area */ + assert_int_not_equal(-1, fmap_locate_area("COREBOOT", &ar)); + assert_int_equal(FMAP_SECTION_COREBOOT_START, region_offset(&ar)); + assert_int_equal(FMAP_SECTION_COREBOOT_SIZE, region_sz(&ar)); + + /* Check if locating area second time works */ + assert_int_not_equal(-1, fmap_locate_area("COREBOOT", &ar)); + assert_int_equal(FMAP_SECTION_COREBOOT_START, region_offset(&ar)); + assert_int_equal(FMAP_SECTION_COREBOOT_SIZE, region_sz(&ar)); + + /* Look for another area */ + assert_int_not_equal(-1, fmap_locate_area("GBB", &ar)); + assert_int_equal(FMAP_SECTION_GBB_START, region_offset(&ar)); + assert_int_equal(FMAP_SECTION_GBB_SIZE, region_sz(&ar)); + + /* Expect error when looking for incorrect area */ + assert_int_equal(-1, fmap_locate_area("NONEXISTENT_AREA", &ar)); + assert_int_equal(-1, fmap_locate_area("", &ar)); + assert_int_equal(-1, fmap_locate_area(NULL, &ar)); + + /* Expect error when passing invalid region pointer */ + assert_int_equal(-1, fmap_locate_area("SHARED_DATA", NULL)); +} + +static void test_fmap_find_region_name(void **state) +{ + (void)state; + struct region ar; + char found_area_name[FMAP_STRLEN] = ""; + const char *area_name = "RW_PRESERVE"; + + /* Find area by name */ + assert_int_not_equal(-1, fmap_locate_area(area_name, &ar)); + + /* Find name of previously located region */ + assert_int_not_equal(-1, fmap_find_region_name(&ar, found_area_name)); + assert_string_equal(area_name, found_area_name); + + /* Expect error when passing invalid buffer */ + assert_int_equal(-1, fmap_find_region_name(&ar, NULL)); + + /* Expect error when passing invalid region pointer */ + assert_int_equal(-1, fmap_find_region_name(NULL, found_area_name)); + + /* Try to find area outside of flash region */ + ar.offset = FMAP_SECTION_FLASH_START + FMAP_SECTION_FLASH_SIZE + 0x100; + ar.size = 0x1000; + assert_int_equal(-1, fmap_find_region_name(&ar, found_area_name)); + + /* Try to find area with correct offset and incorrect size */ + ar.offset = FMAP_SECTION_COREBOOT_START; + ar.size = FMAP_SECTION_COREBOOT_SIZE / 4; + assert_int_equal(-1, fmap_find_region_name(&ar, found_area_name)); + + /* Try to find area with correct size and incorrect offset */ + ar.offset = FMAP_SECTION_GBB_START - 0x100; + ar.size = FMAP_SECTION_GBB_START; + assert_int_equal(-1, fmap_find_region_name(&ar, found_area_name)); + + /* Try to find area with correct offset overlapping with another area */ + ar.offset = FMAP_SECTION_MISC_RW_START; + ar.size = FMAP_SECTION_MISC_RW_START + 0x1000; + assert_int_equal(-1, fmap_find_region_name(&ar, found_area_name)); +} + +static void test_fmap_read_area(void **state) +{ + const unsigned int section_size = FMAP_SECTION_RW_SECTION_A_SIZE; + const unsigned int section_start = FMAP_SECTION_RW_SECTION_A_START; + char *buffer = malloc(section_size); + + /* Find and read area data. Compare with memory device simulating flash. */ + assert_int_equal(section_size, fmap_read_area("RW_SECTION_A", buffer, section_size)); + assert_memory_equal(flash_buffer + section_start, buffer, section_size); + + /* Expect error when reading incorrect area */ + assert_int_equal(-1, fmap_read_area("NONEXISTENT_SECTION", buffer, section_size)); + assert_int_equal(-1, fmap_read_area("", buffer, section_size)); + assert_int_equal(-1, fmap_read_area(NULL, buffer, section_size)); + + /* Function fmap_read_area is not tested with NULL + as output buffer pointer as it is not allowed. */ + + free(buffer); +} + +static void test_fmap_overwrite_area(void **state) +{ + const char *section_name = "FW_MAIN_A"; + const unsigned int section_size = FMAP_SECTION_FW_MAIN_A_SIZE; + char *buffer1 = malloc(section_size); + char *buffer2 = malloc(section_size); + char *new_data = malloc(section_size / 2); + char *zero_buffer = malloc(section_size / 2); + memset(zero_buffer, 0, section_size / 2); + memset(new_data, 0x42, section_size / 2); + + /* Save buffer for future comparisons */ + assert_int_equal(section_size, fmap_read_area(section_name, buffer1, section_size)); + + /* Overwrite part of section. */ + assert_int_equal(section_size / 2, + fmap_overwrite_area(section_name, new_data, section_size / 2)); + + /* Read and check if memory has changed as expected */ + assert_int_equal(section_size, fmap_read_area(section_name, buffer2, section_size)); + assert_memory_not_equal(buffer1, buffer2, section_size); + /* Check if requested section area was overwritten properly */ + assert_memory_equal(buffer2, new_data, section_size / 2); + /* Check if rest of section was zero-filled */ + assert_memory_equal(buffer2 + (section_size / 2), zero_buffer, section_size / 2); + + /* Expect error when overwriting incorrect section */ + assert_int_equal(-1, fmap_overwrite_area("NONEXISTENT_SECTION", + new_data, section_size / 2)); + assert_int_equal(-1, fmap_overwrite_area(NULL, new_data, section_size / 2)); + + /* Function fmap_overwrite_area is not tested with NULL + as input buffer pointer as it is not allowed. */ + + free(buffer1); + free(buffer2); + free(new_data); + free(zero_buffer); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev, + setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_locate_area_as_rdev_rw, + setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_locate_area, + setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_find_region_name, + setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_read_area, + setup_fmap, teardown_fmap), + cmocka_unit_test_setup_teardown(test_fmap_overwrite_area, + setup_fmap, teardown_fmap), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +}
Attention is currently required from: Jakub Czapiga. Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 7:
(1 comment)
File tests/lib/Makefile.inc:
https://review.coreboot.org/c/coreboot/+/48557/comment/f8b2bd27_0a24be71 PS7, Line 53: fmap-test-cflags += -I tests/include/tests/lib/fmap Does this do anything? fmap-test.c includes these by full path (as I think it should).
Jakub Czapiga has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 7:
(1 comment)
File tests/lib/Makefile.inc:
https://review.coreboot.org/c/coreboot/+/48557/comment/13e6115c_7b442a64 PS7, Line 53: fmap-test-cflags += -I tests/include/tests/lib/fmap
Does this do anything? fmap-test.c includes these by full path (as I think it should).
Yes, it does. If you open src/lib/fmap.c and look at includes, then you will see:
#include "fmap_config.h"
This path has to be in the compiler include paths for correct compilation. Includes in the test source file are using full test include paths to indicate, that those are not part of the original coreboot source.
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/48557 )
Change subject: tests: Add lib/fmap-test test case ......................................................................
Patch Set 7:
(1 comment)
File tests/lib/Makefile.inc:
https://review.coreboot.org/c/coreboot/+/48557/comment/df824ab7_de518ffa PS7, Line 53: fmap-test-cflags += -I tests/include/tests/lib/fmap
Yes, it does. If you open src/lib/fmap.c and look at includes, then you will see: […]
Right, sorry, forgot about that special case. Makes sense.