mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-29 16:03:47 +02:00
tests: Add tests to write on chip
This patch adds two tests and initialises page_size in mock chip chip_W25Q128_V. page_size was not needed for previous tests (erase and read). page_size only needed to execute writing on chip with dummyflasher, so it is added here. BUG=b:181803212 TEST=ninja test Change-Id: I6f0336613ab16a7e59857006496e3590ddb14d00 Signed-off-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-on: https://review.coreboot.org/c/flashrom/+/58357 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
This commit is contained in:
parent
4ab9bd7ffb
commit
8aaee03333
61
tests/chip.c
61
tests/chip.c
@ -148,6 +148,7 @@ static const struct flashchip chip_W25Q128_V = {
|
|||||||
.read = spi_chip_read,
|
.read = spi_chip_read,
|
||||||
.write = spi_chip_write_256,
|
.write = spi_chip_write_256,
|
||||||
.unlock = spi_disable_blockprotect,
|
.unlock = spi_disable_blockprotect,
|
||||||
|
.page_size = 256,
|
||||||
.block_erasers =
|
.block_erasers =
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -256,3 +257,63 @@ void read_chip_with_dummyflasher_test_success(void **state)
|
|||||||
|
|
||||||
free(param_dup);
|
free(param_dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_chip_test_success(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
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, &mock_chip, param);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Providing filename "-" means content is taken from standard input.
|
||||||
|
* This doesn't change much because all file operations are mocked.
|
||||||
|
* However filename "-" makes a difference for
|
||||||
|
* flashrom.c#read_buf_from_file and allows to avoid mocking
|
||||||
|
* image_stat.st_size.
|
||||||
|
*
|
||||||
|
* Now this does mean test covers successful path only, but this test
|
||||||
|
* is designed to cover only successful write operation anyway.
|
||||||
|
*
|
||||||
|
* To cover error path of image_stat.st_size != flash size, filename
|
||||||
|
* needs to be provided and image_stat.st_size needs to be mocked.
|
||||||
|
*/
|
||||||
|
const char *const filename = "-";
|
||||||
|
|
||||||
|
printf("Write chip operation started.\n");
|
||||||
|
assert_int_equal(0, do_write(&flash, filename, NULL));
|
||||||
|
printf("Write chip operation done.\n");
|
||||||
|
|
||||||
|
teardown(&layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_chip_with_dummyflasher_test_success(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
struct flashrom_flashctx flash = { 0 };
|
||||||
|
struct flashrom_layout *layout;
|
||||||
|
struct flashchip mock_chip = chip_W25Q128_V;
|
||||||
|
/*
|
||||||
|
* 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, &mock_chip, param_dup);
|
||||||
|
|
||||||
|
/* See comment in write_chip_test_success */
|
||||||
|
const char *const filename = "-";
|
||||||
|
|
||||||
|
printf("Write chip operation started.\n");
|
||||||
|
assert_int_equal(0, do_write(&flash, filename, NULL));
|
||||||
|
printf("Write chip operation done.\n");
|
||||||
|
|
||||||
|
teardown(&layout);
|
||||||
|
|
||||||
|
free(param_dup);
|
||||||
|
}
|
||||||
|
@ -41,6 +41,7 @@ mocks = [
|
|||||||
'-Wl,--wrap=write',
|
'-Wl,--wrap=write',
|
||||||
'-Wl,--wrap=fopen',
|
'-Wl,--wrap=fopen',
|
||||||
'-Wl,--wrap=fopen64',
|
'-Wl,--wrap=fopen64',
|
||||||
|
'-Wl,--wrap=fdopen',
|
||||||
'-Wl,--wrap=fwrite',
|
'-Wl,--wrap=fwrite',
|
||||||
'-Wl,--wrap=fflush',
|
'-Wl,--wrap=fflush',
|
||||||
'-Wl,--wrap=stat',
|
'-Wl,--wrap=stat',
|
||||||
|
@ -136,6 +136,12 @@ FILE *__wrap_fopen64(const char *pathname, const char *mode)
|
|||||||
return not_null();
|
return not_null();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE *__wrap_fdopen(int fd, const char *mode)
|
||||||
|
{
|
||||||
|
LOG_ME;
|
||||||
|
return not_null();
|
||||||
|
}
|
||||||
|
|
||||||
int __wrap_stat(const char *path, void *buf)
|
int __wrap_stat(const char *path, void *buf)
|
||||||
{
|
{
|
||||||
LOG_ME;
|
LOG_ME;
|
||||||
@ -343,6 +349,8 @@ int main(void)
|
|||||||
cmocka_unit_test(erase_chip_with_dummyflasher_test_success),
|
cmocka_unit_test(erase_chip_with_dummyflasher_test_success),
|
||||||
cmocka_unit_test(read_chip_test_success),
|
cmocka_unit_test(read_chip_test_success),
|
||||||
cmocka_unit_test(read_chip_with_dummyflasher_test_success),
|
cmocka_unit_test(read_chip_with_dummyflasher_test_success),
|
||||||
|
cmocka_unit_test(write_chip_test_success),
|
||||||
|
cmocka_unit_test(write_chip_with_dummyflasher_test_success),
|
||||||
};
|
};
|
||||||
ret |= cmocka_run_group_tests_name("chip.c tests", chip_tests, NULL, NULL);
|
ret |= cmocka_run_group_tests_name("chip.c tests", chip_tests, NULL, NULL);
|
||||||
|
|
||||||
|
@ -61,5 +61,7 @@ void erase_chip_test_success(void **state);
|
|||||||
void erase_chip_with_dummyflasher_test_success(void **state);
|
void erase_chip_with_dummyflasher_test_success(void **state);
|
||||||
void read_chip_test_success(void **state);
|
void read_chip_test_success(void **state);
|
||||||
void read_chip_with_dummyflasher_test_success(void **state);
|
void read_chip_with_dummyflasher_test_success(void **state);
|
||||||
|
void write_chip_test_success(void **state);
|
||||||
|
void write_chip_with_dummyflasher_test_success(void **state);
|
||||||
|
|
||||||
#endif /* TESTS_H */
|
#endif /* TESTS_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user