Attention is currently required from: Angel Pons, Anastasia Klimchuk. Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/51487 )
Change subject: Add unit test to run init/shutdown for enabled drivers ......................................................................
Patch Set 1:
(1 comment)
File mec1308.c:
https://review.coreboot.org/c/flashrom/+/51487/comment/8440124f_ff22057f PS1, Line 115: #endif /* UNIT_TEST_ENV */
I was thinking about separate compilation units for a while, how exactly to do this. […]
I guess we could have something like a `hwaccess_unittest.h`, yes. It could be hooked up via `-include` and `#define __HW_ACCESS_H__`. This way the original `hwaccess.h` would be bypassed.
It could provide a single definition for the used macros, e.g.
#define OUTB(v, p) test_outb(v, p) #define INB(p) test_inb(p)
etc.
However, the original `hwaccess.h` provides more than the I/O macros. Maybe we should split that out?
There are probably many ways to solve the per-driver mocking issue. Two ideas from the top of my head:
1. Build multiple test binaries, each with its own versions of test_outb() etc.
2. Provide some abstraction via function pointers. e.g. a struct per test with
struct test_io { void (*outb)(unsigned char value, unsigned short port); unsigned char (*inb)(unsigned short port); /* etc. */ } extern const struct test_io *test_io;
And then before each test, set
test_io = test_io_mec1308;
The test_*() functions would then simply call the respective function in `test_io`, e.g.:
void test_outb(unsigned char value, unsigned short port) { test_io->outb(value, port); }