aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/chip.c177
1 files changed, 60 insertions, 117 deletions
diff --git a/tests/chip.c b/tests/chip.c
index 2f6581fb..54e14d22 100644
--- a/tests/chip.c
+++ b/tests/chip.c
@@ -21,11 +21,11 @@
#include "flash.h"
#include "programmer.h"
-#define CHIP_TOTAL_SIZE 8192
+#define MOCK_CHIP_SIZE (8*MiB)
static struct {
unsigned int unlock_calls; /* how many times unlock function was called */
- uint8_t buf[CHIP_TOTAL_SIZE]; /* buffer of total size of chip, to emulate a chip */
+ uint8_t buf[MOCK_CHIP_SIZE]; /* buffer of total size of chip, to emulate a chip */
} g_chip_state = {
.unlock_calls = 0,
.buf = { 0 },
@@ -39,7 +39,7 @@ int read_chip(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned
return 1;
}
- assert_in_range(start + len, 0, CHIP_TOTAL_SIZE);
+ assert_in_range(start + len, 0, MOCK_CHIP_SIZE);
memcpy(buf, &g_chip_state.buf[start], len);
return 0;
@@ -53,7 +53,7 @@ int write_chip(struct flashctx *flash, const uint8_t *buf, unsigned int start, u
return 1;
}
- assert_in_range(start + len, 0, CHIP_TOTAL_SIZE);
+ assert_in_range(start + len, 0, MOCK_CHIP_SIZE);
memcpy(&g_chip_state.buf[start], buf, len);
return 0;
@@ -80,7 +80,7 @@ int block_erase_chip(struct flashctx *flash, unsigned int blockaddr, unsigned in
return 1;
}
- assert_in_range(blockaddr + blocklen, 0, CHIP_TOTAL_SIZE);
+ assert_in_range(blockaddr + blocklen, 0, MOCK_CHIP_SIZE);
memset(&g_chip_state.buf[blockaddr], 0xff, blocklen);
return 0;
@@ -96,7 +96,7 @@ static void setup_chip(struct flashrom_flashctx *flash, struct flashrom_layout *
printf("Creating layout with one included region... ");
assert_int_equal(0, flashrom_layout_new(layout));
/* One region which covers total size of chip. */
- assert_int_equal(0, flashrom_layout_add_region(*layout, 0, chip->total_size * 1024 - 1, "region"));
+ assert_int_equal(0, flashrom_layout_add_region(*layout, 0, chip->total_size * KiB - 1, "region"));
assert_int_equal(0, flashrom_layout_include_region(*layout, "region"));
flashrom_layout_set(flash, *layout);
@@ -125,33 +125,60 @@ static void teardown(struct flashrom_layout **layout)
printf("done\n");
}
+static const struct flashchip chip_8MiB = {
+ .vendor = "aklm",
+ .total_size = MOCK_CHIP_SIZE / KiB,
+ .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 * MiB, 4} },
+ .block_erase = block_erase_chip,
+ }},
+};
+
+/* Setup the struct for W25Q128.V, all values come from flashchips.c */
+static const 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;
+ struct flashchip mock_chip = chip_8MiB;
const char *param = ""; /* Default values for all params. */
- setup_chip(&flash, &layout, &chip, param);
+ setup_chip(&flash, &layout, &mock_chip, param);
printf("Erase chip operation started.\n");
assert_int_equal(0, do_erase(&flash));
@@ -164,49 +191,16 @@ void erase_chip_with_dummyflasher_test_success(void **state)
{
(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;
+ struct flashchip mock_chip = chip_W25Q128_V;
/*
- * 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_chip(&flash, &layout, &chip, param_dup);
+ setup_chip(&flash, &layout, &mock_chip, param_dup);
printf("Erase chip operation started.\n");
assert_int_equal(0, do_erase(&flash));
@@ -221,30 +215,12 @@ void read_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;
+ struct flashchip mock_chip = chip_8MiB;
const char *param = ""; /* Default values for all params. */
- setup_chip(&flash, &layout, &chip, param);
+ setup_chip(&flash, &layout, &mock_chip, param);
const char *const filename = "read_chip.test";
@@ -259,49 +235,16 @@ void read_chip_with_dummyflasher_test_success(void **state)
{
(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;
+ struct flashchip mock_chip = chip_W25Q128_V;
/*
- * 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_chip(&flash, &layout, &chip, param_dup);
+ setup_chip(&flash, &layout, &mock_chip, param_dup);
const char *const filename = "read_chip.test";