1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

tests: add fprintf() mock with redirection to io_mock

We've seen somewhat obscure test failures where the real fprintf()
function was passed a fake file returned by the fopen() mock.

Although the code that caused the specific failure was cros-specific,
adding an fprintf() mock should help avoid future debugging.

TEST=ninja test
BRANCH=none
BUG=b:217661133

Change-Id: I3f8594ea24d17436a7932732d9d05416b804dc93
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61708
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Nikolai Artemiev 2022-02-08 16:56:02 +11:00 committed by Edward O'Callaghan
parent a8be6dace8
commit 94f91ef864
3 changed files with 16 additions and 0 deletions

View File

@ -102,6 +102,7 @@ struct io_mock {
FILE* (*fopen)(void *state, const char *pathname, const char *mode);
char* (*fgets)(void *state, char *buf, int len, FILE *fp);
size_t (*fread)(void *state, void *buf, size_t size, size_t len, FILE *fp);
int (*fprintf)(void *state, FILE *fp, const char *fmt, va_list args);
int (*fclose)(void *state, FILE *fp);
};

View File

@ -56,6 +56,7 @@ mocks = [
'-Wl,--wrap=fsync',
'-Wl,--wrap=fread',
'-Wl,--wrap=fgets',
'-Wl,--wrap=fprintf',
'-Wl,--wrap=fclose',
'-Wl,--wrap=feof',
'-Wl,--wrap=ferror',

View File

@ -236,6 +236,20 @@ int __wrap_setvbuf(FILE *fp, char *buf, int type, size_t size)
return 0;
}
int __wrap_fprintf(FILE *fp, const char *fmt, ...)
{
LOG_ME;
if (get_io() && get_io()->fprintf) {
va_list args;
int out;
va_start(args, fmt);
out = get_io()->fprintf(get_io()->state, fp, fmt, args);
va_end(args);
return out;
}
return 0;
}
int __wrap_fclose(FILE *fp)
{
LOG_ME;