Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/57437 )
Change subject: tests: Make chip definitions static global ......................................................................
tests: Make chip definitions static global
This way chip definitions can be reused between test functions.
BUG=b:181803212 TEST=builds and ninja test
Change-Id: Ia9b5fc71e30610684e68e9aca9fb1970da8f840a Signed-off-by: Anastasia Klimchuk aklm@chromium.org --- M tests/chip.c 1 file changed, 51 insertions(+), 112 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/37/57437/1
diff --git a/tests/chip.c b/tests/chip.c index 8b254e4..757d14d 100644 --- a/tests/chip.c +++ b/tests/chip.c @@ -21,7 +21,7 @@ #include "flash.h" #include "programmer.h"
-#define CHIP_TOTAL_SIZE 8192 +#define CHIP_TOTAL_SIZE 8388608
static struct { unsigned int unlock_calls; /* how many times unlock function was called */ @@ -130,33 +130,59 @@ printf("done\n"); }
+struct flashchip chip_8MiB = { + .vendor = "aklm", + .total_size = 8 * 1024, + .tested = TEST_OK_PREW, + .read = read_chip, + .write = write_chip, + .unlock = unlock_chip, + .block_erasers = + {{ + /* All blocks within total size of the chip. */ + .eraseblocks = { {2 * 1024 * 1024, 4} }, + .block_erase = block_erase_chip, + }}, +}; + +/* Setup the struct for W25Q128.V, all values come from flashchips.c */ +struct flashchip chip_W25Q128_V = { + .vendor = "aklm&dummyflasher", + .total_size = 16 * 1024, + .tested = TEST_OK_PREW, + .read = spi_chip_read, + .write = spi_chip_write_256, + .unlock = spi_disable_blockprotect, + .block_erasers = + { + { + .eraseblocks = { {4 * 1024, 4096} }, + .block_erase = spi_block_erase_20, + }, { + .eraseblocks = { {32 * 1024, 512} }, + .block_erase = spi_block_erase_52, + }, { + .eraseblocks = { {64 * 1024, 256} }, + .block_erase = spi_block_erase_d8, + }, { + .eraseblocks = { {16 * 1024 * 1024, 1} }, + .block_erase = spi_block_erase_60, + }, { + .eraseblocks = { {16 * 1024 * 1024, 1} }, + .block_erase = spi_block_erase_c7, + } + }, +}; + void erase_chip_test_success(void **state) { (void) state; /* unused */
- struct flashchip chip = { - .vendor = "aklm", - /* - * Total size less than 16 to skip some steps - * in flashrom.c#prepare_flash_access. - */ - .total_size = 8, - .tested = TEST_OK_PREW, - .read = read_chip, - .write = write_chip, - .unlock = unlock_chip, - .block_erasers = - {{ - /* All blocks within total size of the chip. */ - .eraseblocks = { {2 * 1024, 4} }, - .block_erase = block_erase_chip, - }}, - }; struct flashrom_flashctx flash = { 0 }; struct flashrom_layout *layout; const char *param = ""; /* Default values for all params. */
- setup_for_chip(&flash, &layout, &chip, param); + setup_for_chip(&flash, &layout, &chip_8MiB, param);
printf("Erase chip operation started.\n"); assert_int_equal(0, do_erase(&flash)); @@ -169,49 +195,15 @@ { (void) state; /* unused */
- struct flashchip chip = { - .vendor = "aklm&dummyflasher", - /* - * Setup the values for W25Q128.V because we ask dummyflasher - * to emulate this chip. All operations: read/write/unlock/erase - * are real, not mocks, and they are expected to be handled by - * dummyflasher. - */ - .total_size = 16 * 1024, - .tested = TEST_OK_PREW, - .read = spi_chip_read, - .write = spi_chip_write_256, - .unlock = spi_disable_blockprotect, - .block_erasers = - { - { - .eraseblocks = { {4 * 1024, 4096} }, - .block_erase = spi_block_erase_20, - }, { - .eraseblocks = { {32 * 1024, 512} }, - .block_erase = spi_block_erase_52, - }, { - .eraseblocks = { {64 * 1024, 256} }, - .block_erase = spi_block_erase_d8, - }, { - .eraseblocks = { {16 * 1024 * 1024, 1} }, - .block_erase = spi_block_erase_60, - }, { - .eraseblocks = { {16 * 1024 * 1024, 1} }, - .block_erase = spi_block_erase_c7, - } - }, - }; - struct flashrom_flashctx flash = { 0 }; struct flashrom_layout *layout; /* - * Dummyflasher is capable to emulate a chip, so we ask it to do this. + * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. * Nothing to mock, dummy is taking care of this already. */ char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
- setup_for_chip(&flash, &layout, &chip, param_dup); + setup_for_chip(&flash, &layout, &chip_W25Q128_V, param_dup);
printf("Erase chip operation started.\n"); assert_int_equal(0, do_erase(&flash)); @@ -226,30 +218,11 @@ { (void) state; /* unused */
- struct flashchip chip = { - .vendor = "aklm", - /* - * Total size less than 16 to skip some steps - * in flashrom.c#prepare_flash_access. - */ - .total_size = 8, - .tested = TEST_OK_PREW, - .read = read_chip, - .write = write_chip, - .unlock = unlock_chip, - .block_erasers = - {{ - /* All blocks within total size of the chip. */ - .eraseblocks = { {2 * 1024, 4} }, - .block_erase = block_erase_chip, - }}, - }; - struct flashrom_flashctx flash = { 0 }; struct flashrom_layout *layout; const char *param = ""; /* Default values for all params. */
- setup_for_chip(&flash, &layout, &chip, param); + setup_for_chip(&flash, &layout, &chip_8MiB, param);
const char *const filename = "read_chip.test";
@@ -264,49 +237,15 @@ { (void) state; /* unused */
- struct flashchip chip = { - .vendor = "aklm&dummyflasher", - /* - * Setup the values for W25Q128.V because we ask dummyflasher - * to emulate this chip. All operations: read/write/unlock/erase - * are real, not mocks, and they are expected to be handled by - * dummyflasher. - */ - .total_size = 16 * 1024, - .tested = TEST_OK_PREW, - .read = spi_chip_read, - .write = spi_chip_write_256, - .unlock = spi_disable_blockprotect, - .block_erasers = - { - { - .eraseblocks = { {4 * 1024, 4096} }, - .block_erase = spi_block_erase_20, - }, { - .eraseblocks = { {32 * 1024, 512} }, - .block_erase = spi_block_erase_52, - }, { - .eraseblocks = { {64 * 1024, 256} }, - .block_erase = spi_block_erase_d8, - }, { - .eraseblocks = { {16 * 1024 * 1024, 1} }, - .block_erase = spi_block_erase_60, - }, { - .eraseblocks = { {16 * 1024 * 1024, 1} }, - .block_erase = spi_block_erase_c7, - } - }, - }; - struct flashrom_flashctx flash = { 0 }; struct flashrom_layout *layout; /* - * Dummyflasher is capable to emulate a chip, so we ask it to do this. + * Dummyflasher is capable to emulate W25Q128.V, so we ask it to do this. * Nothing to mock, dummy is taking care of this already. */ char *param_dup = strdup("bus=spi,emulate=W25Q128FV");
- setup_for_chip(&flash, &layout, &chip, param_dup); + setup_for_chip(&flash, &layout, &chip_W25Q128_V, param_dup);
const char *const filename = "read_chip.test";