1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 15:12:36 +02:00
flashrom/tests/hwaccess_x86_io_unittest.h
Anastasia Klimchuk 4abb62c4ac hwaccess_x86_io_unittest: Add dummy iopl to avoid including sys/io.h
sys/io.h is platform specific, and also in tests environment we
don't need real functions anyway. Adding dummy implementation of
iopl is sufficient for tests. The rest of io is not needed
because hwaccess_x86_io_unittest.h re-defines macros OUTB/INB/etc
and those macros evaluate to test-only functions.

This is a follow up on commit 21e22ba8a7750f1cfe5cd3323e3137695ffef0a4
which introduced hwaccess_x86_io_unittest.h

BUG=b:181803212
TEST=builds and ninja test on x86 (same as before)

Change-Id: I3f2f0408be7c00f954b899031b52b2b97ef19ca3
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/55741
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
2021-06-26 11:54:32 +00:00

63 lines
1.8 KiB
C

/*
* 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>
/*
* Dummy implementation of iopl from sys/io.h.
* sys/io.h by itself is platform-specific, so instead of including
* the header we just have this dummy function, which is sufficient
* for test purposes.
*/
static inline int iopl(int level)
{
return 0;
}
/* 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__ */