1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-02 14:33:18 +02:00

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>
This commit is contained in:
Anastasia Klimchuk
2021-08-19 15:15:19 +10:00
committed by Edward O'Callaghan
parent 099e378512
commit 05b59d2ca3
5 changed files with 180 additions and 4 deletions

View File

@ -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),
};