diff options
author | Anastasia Klimchuk <aklm@chromium.org> | 2021-05-10 10:19:25 +1000 |
---|---|---|
committer | Nico Huber <nico.h@gmx.de> | 2021-06-05 08:50:37 +0000 |
commit | 21e22ba8a7750f1cfe5cd3323e3137695ffef0a4 (patch) | |
tree | 61fbd63991b26eb67ea324817d23fd6c7a7e6c46 /hwaccess_x86_io_unittest.h | |
parent | 38c133438c98d70bcd46a6289bc4120e22606cf2 (diff) | |
download | flashrom-21e22ba8a7750f1cfe5cd3323e3137695ffef0a4.tar.gz flashrom-21e22ba8a7750f1cfe5cd3323e3137695ffef0a4.tar.bz2 flashrom-21e22ba8a7750f1cfe5cd3323e3137695ffef0a4.zip |
tests: Add unit test to run init/shutdown for mec1308.c, ene_lpc.c
This patch includes mocks for io operations in hwaccess_x86_io.h
because those are needed to test lifecycle of mec1308.c and
ene_lpc.c
BUG=b:181803212
TEST=builds and ninja test
Change-Id: I3af612defe1af3850dfc1626a208d873e3a3eddc
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/51487
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'hwaccess_x86_io_unittest.h')
-rw-r--r-- | hwaccess_x86_io_unittest.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/hwaccess_x86_io_unittest.h b/hwaccess_x86_io_unittest.h new file mode 100644 index 000000000..7bffc963a --- /dev/null +++ b/hwaccess_x86_io_unittest.h @@ -0,0 +1,52 @@ +/* + * This file is part of the flashrom project. + * + * Copyright 2021 Google LLC + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * This header is used instead of hwaccess_x86_io.h for unit tests + * (see flashrom_test_dep in meson.build). + * + * There is no hardware in unit test environment and all hardware operations + * need to be mocked. + */ + +/* + * The same guard is used intentionally for hwaccess_x86_io.h and + * hwaccess_x86_io_unittest.h. When build is made for the test environment, + * hwaccess_x86_io_unittest.h is included first, and it effectively + * replaces hwaccess_x86_io.h. + */ +#ifndef __HWACCESS_X86_IO_H__ +#define __HWACCESS_X86_IO_H__ 1 + +#define OUTB(v, p) test_outb(v, p) +#define OUTW(v, p) test_outw(v, p) +#define OUTL(v, p) test_outl(v, p) +#define INB(p) test_inb(p) +#define INW(p) test_inw(p) +#define INL(p) test_inl(p) + +#include <stdint.h> +#include <sys/io.h> + +/* All functions below are mocked in unit tests. */ + +void test_outb(uint8_t value, uint16_t port); +uint8_t test_inb(uint16_t port); +void test_outw(uint16_t value, uint16_t port); +uint16_t test_inw(uint16_t port); +void test_outl(uint32_t value, uint16_t port); +uint32_t test_inl(uint16_t port); + +#endif /* !__HWACCESS_X86_IO_H__ */ |