1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-01 22:21:16 +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

@ -31,6 +31,9 @@
#ifndef _IO_MOCK_H_
#define _IO_MOCK_H_
/* Required for `FILE *` */
#include <stdio.h>
/* Define libusb symbols to avoid dependency on libusb.h */
struct libusb_device_handle;
typedef struct libusb_device_handle libusb_device_handle;
@ -79,6 +82,12 @@ struct io_mock {
int (*ioctl)(void *state, int fd, unsigned long request, va_list args);
int (*read)(void *state, int fd, void *buf, size_t sz);
int (*write)(void *state, int fd, const void *buf, size_t sz);
/* Standard I/O */
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 (*fclose)(void *state, FILE *fp);
};
void io_mock_register(const struct io_mock *io);