diff options
| author | Anastasia Klimchuk <aklm@chromium.org> | 2021-08-19 15:15:19 +1000 |
|---|---|---|
| committer | Edward O'Callaghan <quasisec@chromium.org> | 2021-08-30 02:44:17 +0000 |
| commit | 05b59d2ca30548f8460d87dbf8353ab1437cb204 (patch) | |
| tree | 5298405692008e8230849f60ffc4887c90a00a62 /tests/tests.c | |
| parent | 099e3785126437abafb4f4784f05ae469deb2d1d (diff) | |
| download | flashrom-05b59d2ca30548f8460d87dbf8353ab1437cb204.tar.gz flashrom-05b59d2ca30548f8460d87dbf8353ab1437cb204.tar.bz2 flashrom-05b59d2ca30548f8460d87dbf8353ab1437cb204.zip | |
tests: Mock file i/o for linux_mtd and linux_spi tests
This patch adds an init-shutdown test for linux_mtd. Since
linux_mtd is using file i/o operations, those are added to the
framework and mocked.
Another driver linux_spi which is also using file i/o, got an upgrade
in this patch, and it is now reading max buffer size from sysfs (using
mocked file i/o).
A good side-effect is that linux_mtd is the first test for opaque
masters, which is great to have in preparation for a change like
CB:56103 but for opaque masters.
BUG=b:181803212
TEST=builds and ninja test
Change-Id: I73f0d6ff2ad5074add7a721ed3416230d3647e3f
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/56413
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Diffstat (limited to 'tests/tests.c')
| -rw-r--r-- | tests/tests.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/tests.c b/tests/tests.c index bfc0e53c..4965fe1c 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -129,15 +129,78 @@ int __wrap_read(int fd, void *buf, size_t sz) FILE *__wrap_fopen(const char *pathname, const char *mode) { LOG_ME; - return NULL; + if (current_io && current_io->fopen) + return current_io->fopen(current_io->state, pathname, mode); + return (void *)MOCK_HANDLE; } FILE *__wrap_fopen64(const char *pathname, const char *mode) { LOG_ME; + if (current_io && current_io->fopen) + return current_io->fopen(current_io->state, pathname, mode); + return (void *)MOCK_HANDLE; +} + +int __wrap_stat(const char *path, void *buf) +{ + LOG_ME; + return 0; +} + +int __wrap_stat64(const char *path, void *buf) +{ + LOG_ME; + return 0; +} + +char *__wrap_fgets(char *buf, int len, FILE *fp) +{ + LOG_ME; + if (current_io && current_io->fgets) + return current_io->fgets(current_io->state, buf, len, fp); return NULL; } +size_t __wrap_fread(void *ptr, size_t size, size_t len, FILE *fp) +{ + LOG_ME; + if (current_io && current_io->fread) + return current_io->fread(current_io->state, ptr, size, len, fp); + return 0; +} + +int __wrap_setvbuf(FILE *fp, char *buf, int type, size_t size) +{ + LOG_ME; + return 0; +} + +int __wrap_fclose(FILE *fp) +{ + LOG_ME; + if (current_io && current_io->fclose) + return current_io->fclose(current_io->state, fp); + return 0; +} + +int __wrap_feof(FILE *fp) +{ + /* LOG_ME; */ + return 0; +} + +int __wrap_ferror(FILE *fp) +{ + /* LOG_ME; */ + return 0; +} +void __wrap_clearerr(FILE *fp) +{ + /* LOG_ME; */ + return; +} + int __wrap_rget_io_perms(void) { LOG_ME; @@ -277,6 +340,7 @@ int main(void) cmocka_unit_test(nicrealtek_init_and_shutdown_test_success), cmocka_unit_test(dediprog_init_and_shutdown_test_success), cmocka_unit_test(ene_lpc_init_and_shutdown_test_success), + cmocka_unit_test(linux_mtd_init_and_shutdown_test_success), cmocka_unit_test(linux_spi_init_and_shutdown_test_success), cmocka_unit_test(realtek_mst_init_and_shutdown_test_success), }; |
