1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00

tests/erase: record the opcode for each erase

This allows tests to verify that the correct opcode is used when
erasing, which is required to unit-test the fix to issue #525 where in
some situations an incorrect erase opcode will be used.

BUG=https://ticket.coreboot.org/issues/525

Change-Id: I3983fe42c2e7f06668a1bd20d2db7fafa93b8043
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/82251
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Peter Marheine 2024-05-10 17:06:50 +10:00
parent 9a9ccdb6e6
commit 510ef74653
5 changed files with 157 additions and 58 deletions

View File

@ -402,8 +402,10 @@ int check_for_unwritable_regions(const struct flashctx *flash, unsigned int star
return 0; return 0;
} }
/* special unit-test hook */ #ifdef FLASHROM_TEST
erasefunc_t *g_test_erase_injector; /* special unit-test hooks */
erasefunc_t *g_test_erase_injector[NUM_TEST_ERASE_INJECTORS];
#endif
erasefunc_t *lookup_erase_func_ptr(const struct block_eraser *const eraser) erasefunc_t *lookup_erase_func_ptr(const struct block_eraser *const eraser)
{ {
@ -442,7 +444,14 @@ erasefunc_t *lookup_erase_func_ptr(const struct block_eraser *const eraser)
case ERASE_SECTOR_49LFXXXC: return &erase_sector_49lfxxxc; case ERASE_SECTOR_49LFXXXC: return &erase_sector_49lfxxxc;
case STM50_SECTOR_ERASE: return &erase_sector_stm50; // TODO rename to &stm50_sector_erase; case STM50_SECTOR_ERASE: return &erase_sector_stm50; // TODO rename to &stm50_sector_erase;
case EDI_CHIP_BLOCK_ERASE: return &edi_chip_block_erase; case EDI_CHIP_BLOCK_ERASE: return &edi_chip_block_erase;
case TEST_ERASE_INJECTOR: return g_test_erase_injector; #ifdef FLASHROM_TEST
case TEST_ERASE_INJECTOR_1:
case TEST_ERASE_INJECTOR_2:
case TEST_ERASE_INJECTOR_3:
case TEST_ERASE_INJECTOR_4:
case TEST_ERASE_INJECTOR_5:
return g_test_erase_injector[eraser->block_erase - TEST_ERASE_INJECTOR_1];
#endif
/* default: total function, 0 indicates no erase function set. /* default: total function, 0 indicates no erase function set.
* We explicitly do not want a default catch-all case in the switch * We explicitly do not want a default catch-all case in the switch
* to ensure unhandled enum's are compiler warnings. * to ensure unhandled enum's are compiler warnings.
@ -540,8 +549,10 @@ int check_erased_range(struct flashctx *flash, unsigned int start, unsigned int
return ret; return ret;
} }
#ifdef FLASHROM_TEST
/* special unit-test hook */ /* special unit-test hook */
read_func_t *g_test_read_injector; read_func_t *g_test_read_injector;
#endif
static read_func_t *lookup_read_func_ptr(const struct flashchip *chip) static read_func_t *lookup_read_func_ptr(const struct flashchip *chip)
{ {
@ -552,7 +563,9 @@ static read_func_t *lookup_read_func_ptr(const struct flashchip *chip)
case EDI_CHIP_READ: return &edi_chip_read; case EDI_CHIP_READ: return &edi_chip_read;
case SPI_READ_AT45DB: return spi_read_at45db; case SPI_READ_AT45DB: return spi_read_at45db;
case SPI_READ_AT45DB_E8: return spi_read_at45db_e8; case SPI_READ_AT45DB_E8: return spi_read_at45db_e8;
#ifdef FLASHROM_TEST
case TEST_READ_INJECTOR: return g_test_read_injector; case TEST_READ_INJECTOR: return g_test_read_injector;
#endif
/* default: total function, 0 indicates no read function set. /* default: total function, 0 indicates no read function set.
* We explicitly do not want a default catch-all case in the switch * We explicitly do not want a default catch-all case in the switch
* to ensure unhandled enum's are compiler warnings. * to ensure unhandled enum's are compiler warnings.
@ -976,7 +989,9 @@ static int init_default_layout(struct flashctx *flash)
} }
/* special unit-test hook */ /* special unit-test hook */
#ifdef FLASHROM_TEST
write_func_t *g_test_write_injector; write_func_t *g_test_write_injector;
#endif
static write_func_t *lookup_write_func_ptr(const struct flashchip *chip) static write_func_t *lookup_write_func_ptr(const struct flashchip *chip)
{ {
@ -992,7 +1007,9 @@ static write_func_t *lookup_write_func_ptr(const struct flashchip *chip)
case WRITE_82802AB: return &write_82802ab; case WRITE_82802AB: return &write_82802ab;
case WRITE_EN29LV640B: return &write_en29lv640b; case WRITE_EN29LV640B: return &write_en29lv640b;
case EDI_CHIP_WRITE: return &edi_chip_write; case EDI_CHIP_WRITE: return &edi_chip_write;
#ifdef FLASHROM_TEST
case TEST_WRITE_INJECTOR: return g_test_write_injector; case TEST_WRITE_INJECTOR: return g_test_write_injector;
#endif
/* default: total function, 0 indicates no write function set. /* default: total function, 0 indicates no write function set.
* We explicitly do not want a default catch-all case in the switch * We explicitly do not want a default catch-all case in the switch
* to ensure unhandled enum's are compiler warnings. * to ensure unhandled enum's are compiler warnings.

View File

@ -266,10 +266,16 @@ enum write_func {
WRITE_82802AB, WRITE_82802AB,
WRITE_EN29LV640B, WRITE_EN29LV640B,
EDI_CHIP_WRITE, EDI_CHIP_WRITE,
#ifdef FLASHROM_TEST
TEST_WRITE_INJECTOR, /* special case must come last. */ TEST_WRITE_INJECTOR, /* special case must come last. */
#endif
}; };
typedef int (write_func_t)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); typedef int (write_func_t)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
#ifdef FLASHROM_TEST
extern write_func_t *g_test_write_injector;
#endif
enum read_func { enum read_func {
NO_READ_FUNC = 0, /* 0 indicates no read function set. */ NO_READ_FUNC = 0, /* 0 indicates no read function set. */
SPI_CHIP_READ = 1, SPI_CHIP_READ = 1,
@ -278,11 +284,17 @@ enum read_func {
EDI_CHIP_READ, EDI_CHIP_READ,
SPI_READ_AT45DB, SPI_READ_AT45DB,
SPI_READ_AT45DB_E8, SPI_READ_AT45DB_E8,
#ifdef FLASHROM_TEST
TEST_READ_INJECTOR, /* special case must come last. */ TEST_READ_INJECTOR, /* special case must come last. */
#endif
}; };
typedef int (read_func_t)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); typedef int (read_func_t)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
int read_flash(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); int read_flash(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
#ifdef FLASHROM_TEST
extern read_func_t *g_test_read_injector;
#endif
enum block_erase_func { enum block_erase_func {
NO_BLOCK_ERASE_FUNC = 0, /* 0 indicates no block erase function set. */ NO_BLOCK_ERASE_FUNC = 0, /* 0 indicates no block erase function set. */
SPI_BLOCK_ERASE_EMULATION = 1, SPI_BLOCK_ERASE_EMULATION = 1,
@ -319,9 +331,21 @@ enum block_erase_func {
ERASE_SECTOR_49LFXXXC, ERASE_SECTOR_49LFXXXC,
STM50_SECTOR_ERASE, STM50_SECTOR_ERASE,
EDI_CHIP_BLOCK_ERASE, EDI_CHIP_BLOCK_ERASE,
TEST_ERASE_INJECTOR, /* special case must come last. */ #ifdef FLASHROM_TEST
/* special cases must come last. */
TEST_ERASE_INJECTOR_1,
TEST_ERASE_INJECTOR_2,
TEST_ERASE_INJECTOR_3,
TEST_ERASE_INJECTOR_4,
TEST_ERASE_INJECTOR_5,
#endif
}; };
#ifdef FLASHROM_TEST
#define NUM_TEST_ERASE_INJECTORS 5
extern erasefunc_t *g_test_erase_injector[NUM_TEST_ERASE_INJECTORS];
#endif
enum blockprotect_func { enum blockprotect_func {
NO_BLOCKPROTECT_FUNC = 0, /* 0 indicates no unlock function set. */ NO_BLOCKPROTECT_FUNC = 0, /* 0 indicates no unlock function set. */
SPI_DISABLE_BLOCKPROTECT, SPI_DISABLE_BLOCKPROTECT,

View File

@ -118,10 +118,6 @@ static void teardown(struct flashrom_layout **layout)
io_mock_register(NULL); io_mock_register(NULL);
} }
extern write_func_t *g_test_write_injector;
extern read_func_t *g_test_read_injector;
extern erasefunc_t *g_test_erase_injector;
static const struct flashchip chip_8MiB = { static const struct flashchip chip_8MiB = {
.vendor = "aklm", .vendor = "aklm",
.total_size = MOCK_CHIP_SIZE / KiB, .total_size = MOCK_CHIP_SIZE / KiB,
@ -132,7 +128,7 @@ static const struct flashchip chip_8MiB = {
{{ {{
/* All blocks within total size of the chip. */ /* All blocks within total size of the chip. */
.eraseblocks = { {2 * MiB, 4} }, .eraseblocks = { {2 * MiB, 4} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_1,
}}, }},
}; };
@ -179,7 +175,7 @@ void erase_chip_test_success(void **state)
g_test_write_injector = write_chip; g_test_write_injector = write_chip;
g_test_read_injector = read_chip; g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip; g_test_erase_injector[0] = block_erase_chip;
struct flashrom_flashctx flashctx = { 0 }; struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout; struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB; struct flashchip mock_chip = chip_8MiB;
@ -238,7 +234,7 @@ void read_chip_test_success(void **state)
g_test_write_injector = write_chip; g_test_write_injector = write_chip;
g_test_read_injector = read_chip; g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip; g_test_erase_injector[0] = block_erase_chip;
struct flashrom_flashctx flashctx = { 0 }; struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout; struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB; struct flashchip mock_chip = chip_8MiB;
@ -313,7 +309,7 @@ void write_chip_test_success(void **state)
g_test_write_injector = write_chip; g_test_write_injector = write_chip;
g_test_read_injector = read_chip; g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip; g_test_erase_injector[0] = block_erase_chip;
struct flashrom_flashctx flashctx = { 0 }; struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout; struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB; struct flashchip mock_chip = chip_8MiB;
@ -504,7 +500,7 @@ void verify_chip_test_success(void **state)
g_test_write_injector = write_chip; g_test_write_injector = write_chip;
g_test_read_injector = read_chip; g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip; g_test_erase_injector[0] = block_erase_chip;
struct flashrom_flashctx flashctx = { 0 }; struct flashrom_flashctx flashctx = { 0 };
struct flashrom_layout *layout; struct flashrom_layout *layout;
struct flashchip mock_chip = chip_8MiB; struct flashchip mock_chip = chip_8MiB;

View File

@ -39,6 +39,7 @@ struct test_region {
struct erase_invoke { struct erase_invoke {
unsigned int blockaddr; unsigned int blockaddr;
unsigned int blocklen; unsigned int blocklen;
enum block_erase_func erase_func;
}; };
struct test_case { struct test_case {
@ -82,16 +83,17 @@ static int write_chip(struct flashctx *flash, const uint8_t *buf, unsigned int s
return 0; return 0;
} }
static int block_erase_chip(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) static int block_erase_chip_tagged(struct flashctx *flash, enum block_erase_func erase_func, unsigned int blockaddr, unsigned int blocklen)
{ {
if (blockaddr + blocklen <= MOCK_CHIP_SIZE) { if (blockaddr + blocklen <= MOCK_CHIP_SIZE) {
LOG_ERASE_FUNC; LOG_ERASE_FUNC;
/* Register eraseblock invocation. */ /* Register eraseblock invocation. */
g_state.eraseblocks_actual[g_state.eraseblocks_actual_ind].blocklen g_state.eraseblocks_actual[g_state.eraseblocks_actual_ind] = (struct erase_invoke){
= blocklen; .blocklen = blocklen,
g_state.eraseblocks_actual[g_state.eraseblocks_actual_ind].blockaddr .blockaddr = blockaddr,
= blockaddr; .erase_func = erase_func,
};
g_state.eraseblocks_actual_ind++; g_state.eraseblocks_actual_ind++;
} }
@ -101,10 +103,6 @@ static int block_erase_chip(struct flashctx *flash, unsigned int blockaddr, unsi
return 0; return 0;
} }
extern write_func_t *g_test_write_injector;
extern read_func_t *g_test_read_injector;
extern erasefunc_t *g_test_erase_injector;
static struct flashchip chip_1_2_4_8_16 = { static struct flashchip chip_1_2_4_8_16 = {
.vendor = "aklm", .vendor = "aklm",
/* /*
@ -127,19 +125,19 @@ static struct flashchip chip_1_2_4_8_16 = {
{ {
{ {
.eraseblocks = { {1, MIN_REAL_CHIP_SIZE} }, .eraseblocks = { {1, MIN_REAL_CHIP_SIZE} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_1,
}, { }, {
.eraseblocks = { {2, MIN_REAL_CHIP_SIZE / 2} }, .eraseblocks = { {2, MIN_REAL_CHIP_SIZE / 2} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_2,
}, { }, {
.eraseblocks = { {4, MIN_REAL_CHIP_SIZE / 4} }, .eraseblocks = { {4, MIN_REAL_CHIP_SIZE / 4} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_3,
}, { }, {
.eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} }, .eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_4,
}, { }, {
.eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} }, .eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_5,
} }
}, },
}; };
@ -156,13 +154,13 @@ static struct flashchip chip_1_8_16 = {
{ {
{ {
.eraseblocks = { {1, MIN_REAL_CHIP_SIZE} }, .eraseblocks = { {1, MIN_REAL_CHIP_SIZE} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_1,
}, { }, {
.eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} }, .eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_4,
}, { }, {
.eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} }, .eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_5,
} }
}, },
}; };
@ -179,20 +177,41 @@ static struct flashchip chip_8_16 = {
{ {
{ {
.eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} }, .eraseblocks = { {8, MIN_REAL_CHIP_SIZE / 8} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_4,
}, { }, {
.eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} }, .eraseblocks = { {16, MIN_REAL_CHIP_SIZE / 16} },
.block_erase = TEST_ERASE_INJECTOR, .block_erase = TEST_ERASE_INJECTOR_5,
} }
}, },
}; };
#define BLOCK_ERASE_FUNC(n) \
static int block_erase_chip_ ## n (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen) { \
return block_erase_chip_tagged(flash, TEST_ERASE_INJECTOR_ ## n, blockaddr, blocklen); \
}
BLOCK_ERASE_FUNC(1)
BLOCK_ERASE_FUNC(2)
BLOCK_ERASE_FUNC(3)
BLOCK_ERASE_FUNC(4)
BLOCK_ERASE_FUNC(5)
static void setup_chip(struct flashrom_flashctx *flashctx, struct flashrom_layout **layout, static void setup_chip(struct flashrom_flashctx *flashctx, struct flashrom_layout **layout,
const char *programmer_param, struct test_case *current_test_case) const char *programmer_param, struct test_case *current_test_case)
{ {
g_test_write_injector = write_chip; g_test_write_injector = write_chip;
g_test_read_injector = read_chip; g_test_read_injector = read_chip;
g_test_erase_injector = block_erase_chip; /* Each erasefunc corresponds to an operation that erases a block of
* the chip with a particular size in bytes. */
memcpy(g_test_erase_injector,
(erasefunc_t *const[]){
block_erase_chip_1, // 1 byte
block_erase_chip_2, // 2 bytes
block_erase_chip_3, // 4 bytes
block_erase_chip_4, // 8 bytes
block_erase_chip_5, // 16 bytes
},
sizeof(g_test_erase_injector)
);
/* First MOCK_CHIP_SIZE bytes have a meaning and set with given values for this test case. */ /* First MOCK_CHIP_SIZE bytes have a meaning and set with given values for this test case. */
memcpy(g_state.buf, current_test_case->initial_buf, MOCK_CHIP_SIZE); memcpy(g_state.buf, current_test_case->initial_buf, MOCK_CHIP_SIZE);
@ -271,7 +290,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #0", .erase_test_name = "Erase test case #0",
.write_test_name = "Write test case #0", .write_test_name = "Write test case #0",
@ -293,7 +312,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, .written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f},
.eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x8}}, .eraseblocks_expected = {{0x8, 0x8, TEST_ERASE_INJECTOR_4}, {0x0, 0x8, TEST_ERASE_INJECTOR_4}},
.eraseblocks_expected_ind = 2, .eraseblocks_expected_ind = 2,
.erase_test_name = "Erase test case #1", .erase_test_name = "Erase test case #1",
.write_test_name = "Write test case #1", .write_test_name = "Write test case #1",
@ -315,7 +334,13 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f, .written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f,
0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f}, 0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f},
.eraseblocks_expected = {{0xb, 0x1}, {0xc, 0x4}, {0xa, 0x1}, {0x8, 0x2}, {0x0, 0x8}}, .eraseblocks_expected = {
{0xb, 0x1, TEST_ERASE_INJECTOR_1},
{0xc, 0x4, TEST_ERASE_INJECTOR_3},
{0xa, 0x1, TEST_ERASE_INJECTOR_1},
{0x8, 0x2, TEST_ERASE_INJECTOR_2},
{0x0, 0x8, TEST_ERASE_INJECTOR_4}
},
.eraseblocks_expected_ind = 5, .eraseblocks_expected_ind = 5,
.erase_test_name = "Erase test case #2", .erase_test_name = "Erase test case #2",
.write_test_name = "Write test case #2", .write_test_name = "Write test case #2",
@ -337,7 +362,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4, .written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #3", .erase_test_name = "Erase test case #3",
.write_test_name = "Write test case #3", .write_test_name = "Write test case #3",
@ -359,7 +384,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff, .written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #4", .erase_test_name = "Erase test case #4",
.write_test_name = "Write test case #4", .write_test_name = "Write test case #4",
@ -381,7 +406,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff, .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #5", .erase_test_name = "Erase test case #5",
.write_test_name = "Write test case #5", .write_test_name = "Write test case #5",
@ -403,7 +428,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xdd, .written_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xdd,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #6", .erase_test_name = "Erase test case #6",
.write_test_name = "Write test case #6", .write_test_name = "Write test case #6",
@ -425,8 +450,16 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
.eraseblocks_expected = {{0xf, 0x1}, {0xe, 0x1}, {0xc, 0x2}, {0x8, 0x4}, .eraseblocks_expected = {
{0x3, 0x1}, {0x4, 0x4}, {0x2, 0x1}, {0x0, 0x2}}, {0xf, 0x1, TEST_ERASE_INJECTOR_1},
{0xe, 0x1, TEST_ERASE_INJECTOR_1},
{0xc, 0x2, TEST_ERASE_INJECTOR_2},
{0x8, 0x4, TEST_ERASE_INJECTOR_3},
{0x3, 0x1, TEST_ERASE_INJECTOR_1},
{0x4, 0x4, TEST_ERASE_INJECTOR_3},
{0x2, 0x1, TEST_ERASE_INJECTOR_1},
{0x0, 0x2, TEST_ERASE_INJECTOR_2}
},
.eraseblocks_expected_ind = 8, .eraseblocks_expected_ind = 8,
.erase_test_name = "Erase test case #7", .erase_test_name = "Erase test case #7",
.write_test_name = "Write test case #7", .write_test_name = "Write test case #7",
@ -448,7 +481,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #8", .erase_test_name = "Erase test case #8",
.write_test_name = "Write test case #8", .write_test_name = "Write test case #8",
@ -471,7 +504,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, .written_buf = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 0xf8, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f},
.eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x8}}, .eraseblocks_expected = {{0x8, 0x8, TEST_ERASE_INJECTOR_4}, {0x0, 0x8, TEST_ERASE_INJECTOR_4}},
.eraseblocks_expected_ind = 2, .eraseblocks_expected_ind = 2,
.erase_test_name = "Erase test case #9", .erase_test_name = "Erase test case #9",
.write_test_name = "Write test case #9", .write_test_name = "Write test case #9",
@ -493,8 +526,17 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f, .written_buf = {0xff, 0xff, 0x0, 0xff, 0x0, 0xff, 0x20, 0x2f,
0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f}, 0x20, 0x2f, 0x0, 0xff, 0xff, 0xff, 0x2f, 0x2f},
.eraseblocks_expected = {{0xb, 0x1}, {0xc, 0x1}, {0xd, 0x1}, {0xe, 0x1}, .eraseblocks_expected = {
{0xf, 0x1}, {0x8, 0x1}, {0x9, 0x1}, {0xa, 0x1}, {0x0, 0x8}}, {0xb, 0x1, TEST_ERASE_INJECTOR_1},
{0xc, 0x1, TEST_ERASE_INJECTOR_1},
{0xd, 0x1, TEST_ERASE_INJECTOR_1},
{0xe, 0x1, TEST_ERASE_INJECTOR_1},
{0xf, 0x1, TEST_ERASE_INJECTOR_1},
{0x8, 0x1, TEST_ERASE_INJECTOR_1},
{0x9, 0x1, TEST_ERASE_INJECTOR_1},
{0xa, 0x1, TEST_ERASE_INJECTOR_1},
{0x0, 0x8, TEST_ERASE_INJECTOR_4}
},
.eraseblocks_expected_ind = 9, .eraseblocks_expected_ind = 9,
.erase_test_name = "Erase test case #10", .erase_test_name = "Erase test case #10",
.write_test_name = "Write test case #10", .write_test_name = "Write test case #10",
@ -516,7 +558,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4, .written_buf = {0xff, 0xff, 0xff, 0xff, 0x1, 0x2, 0x3, 0x4,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #11", .erase_test_name = "Erase test case #11",
.write_test_name = "Write test case #11", .write_test_name = "Write test case #11",
@ -538,7 +580,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff, .written_buf = {0x11, 0x22, 0x33, 0x44, 0xff, 0xff, 0xff, 0xff,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #12", .erase_test_name = "Erase test case #12",
.write_test_name = "Write test case #12", .write_test_name = "Write test case #12",
@ -560,7 +602,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff, .written_buf = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xff,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #13", .erase_test_name = "Erase test case #13",
.write_test_name = "Write test case #13", .write_test_name = "Write test case #13",
@ -582,7 +624,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xdd, .written_buf = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xdd,
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8}, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8},
.eraseblocks_expected = {{0x0, 0x10}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #14", .erase_test_name = "Erase test case #14",
.write_test_name = "Write test case #14", .write_test_name = "Write test case #14",
@ -605,10 +647,24 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, .written_buf = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f},
.eraseblocks_expected = {{0xf, 0x1}, {0x8, 0x1}, {0x9, 0x1}, {0xa, 0x1}, .eraseblocks_expected = {
{0xb, 0x1}, {0xc, 0x1}, {0xd, 0x1}, {0xe, 0x1}, {0xf, 0x1, TEST_ERASE_INJECTOR_1},
{0x3, 0x1}, {0x4, 0x1}, {0x5, 0x1}, {0x6, 0x1}, {0x8, 0x1, TEST_ERASE_INJECTOR_1},
{0x7, 0x1}, {0x0, 0x1}, {0x1, 0x1}, {0x2, 0x1}}, {0x9, 0x1, TEST_ERASE_INJECTOR_1},
{0xa, 0x1, TEST_ERASE_INJECTOR_1},
{0xb, 0x1, TEST_ERASE_INJECTOR_1},
{0xc, 0x1, TEST_ERASE_INJECTOR_1},
{0xd, 0x1, TEST_ERASE_INJECTOR_1},
{0xe, 0x1, TEST_ERASE_INJECTOR_1},
{0x3, 0x1, TEST_ERASE_INJECTOR_1},
{0x4, 0x1, TEST_ERASE_INJECTOR_1},
{0x5, 0x1, TEST_ERASE_INJECTOR_1},
{0x6, 0x1, TEST_ERASE_INJECTOR_1},
{0x7, 0x1, TEST_ERASE_INJECTOR_1},
{0x0, 0x1, TEST_ERASE_INJECTOR_1},
{0x1, 0x1, TEST_ERASE_INJECTOR_1},
{0x2, 0x1, TEST_ERASE_INJECTOR_1},
},
.eraseblocks_expected_ind = 16, .eraseblocks_expected_ind = 16,
.erase_test_name = "Erase test case #15", .erase_test_name = "Erase test case #15",
.write_test_name = "Write test case #15", .write_test_name = "Write test case #15",
@ -631,7 +687,12 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, .written_buf = {0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16,
0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x17}, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x17},
.eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x10}, {0x0, 0x8}, {0x0, 0x8}}, .eraseblocks_expected = {
{0x8, 0x8, TEST_ERASE_INJECTOR_4},
{0x0, 0x10, TEST_ERASE_INJECTOR_5},
{0x0, 0x8, TEST_ERASE_INJECTOR_4},
{0x0, 0x8, TEST_ERASE_INJECTOR_4},
},
.eraseblocks_expected_ind = 4, .eraseblocks_expected_ind = 4,
.erase_test_name = "Erase test case #16", .erase_test_name = "Erase test case #16",
.write_test_name = "Write test case #16", .write_test_name = "Write test case #16",
@ -653,7 +714,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x14, 0x14, 0x14, 0x16, 0x16, 0x16, 0x16, 0x16, .written_buf = {0x14, 0x14, 0x14, 0x16, 0x16, 0x16, 0x16, 0x16,
0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16}, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16},
.eraseblocks_expected = {{0x0, 0x10}, {0x0, 0x8}}, .eraseblocks_expected = {{0x0, 0x10, TEST_ERASE_INJECTOR_5}, {0x0, 0x8, TEST_ERASE_INJECTOR_4}},
.eraseblocks_expected_ind = 2, .eraseblocks_expected_ind = 2,
.erase_test_name = "Erase test case #17", .erase_test_name = "Erase test case #17",
.write_test_name = "Write test case #17", .write_test_name = "Write test case #17",
@ -675,7 +736,7 @@ static struct test_case test_cases[] = {
ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE}, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE, ERASE_VALUE},
.written_buf = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, .written_buf = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16}, 0x14, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16},
.eraseblocks_expected = {{0x8, 0x8}, {0x0, 0x10}}, .eraseblocks_expected = {{0x8, 0x8, TEST_ERASE_INJECTOR_4}, {0x0, 0x10, TEST_ERASE_INJECTOR_5}},
.eraseblocks_expected_ind = 2, .eraseblocks_expected_ind = 2,
.erase_test_name = "Erase test case #18", .erase_test_name = "Erase test case #18",
.write_test_name = "Write test case #18", .write_test_name = "Write test case #18",
@ -696,7 +757,7 @@ static struct test_case test_cases[] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
.written_buf = {0x14, 0x14, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, .written_buf = {0x14, 0x14, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
.eraseblocks_expected = {{0x0, 0x8}}, .eraseblocks_expected = {{0x0, 0x8, TEST_ERASE_INJECTOR_4}},
.eraseblocks_expected_ind = 1, .eraseblocks_expected_ind = 1,
.erase_test_name = "Erase test case #19", .erase_test_name = "Erase test case #19",
.write_test_name = "Write test case #19", .write_test_name = "Write test case #19",

View File

@ -124,6 +124,7 @@ flashrom_tests = executable('flashrom_unit_tests',
'-ffunction-sections', '-ffunction-sections',
'-fdata-sections', '-fdata-sections',
'-U_FORTIFY_SOURCE', '-U_FORTIFY_SOURCE',
'-DFLASHROM_TEST',
], ],
export_dynamic : true, export_dynamic : true,
link_args : mocks + link_args, link_args : mocks + link_args,