aboutsummaryrefslogtreecommitdiff
path: root/devices/uart/sys_io.hh
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-03-12 14:53:27 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-03-12 14:53:27 +0200
commit92e4b6d5522e53e6868b9b0c52b8e54d10bbf606 (patch)
treea23bd7054b6d0fdd9703e69035cd303d6b448e35 /devices/uart/sys_io.hh
parentMove all tests next to the code they're testing (diff)
downloadkernel-92e4b6d5522e53e6868b9b0c52b8e54d10bbf606.tar.xz
Add unit tests for C drivers
Diffstat (limited to 'devices/uart/sys_io.hh')
-rw-r--r--devices/uart/sys_io.hh34
1 files changed, 34 insertions, 0 deletions
diff --git a/devices/uart/sys_io.hh b/devices/uart/sys_io.hh
new file mode 100644
index 0000000..142c9c1
--- /dev/null
+++ b/devices/uart/sys_io.hh
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <gmock/gmock.h>
+
+class IPort {
+public:
+ virtual unsigned char inb(unsigned short) const = 0;
+ virtual void outb(unsigned char, unsigned short) const = 0;
+};
+
+class MockPort : public IPort {
+public:
+ MOCK_METHOD(unsigned char, inb, (unsigned short), (const, override));
+ MOCK_METHOD(void, outb, (unsigned char, unsigned short), (const, override));
+};
+
+static std::unique_ptr<MockPort> mockPort;
+
+// mock free functions
+extern "C" {
+unsigned char
+inb(unsigned short v)
+{
+ EXPECT_TRUE(mockPort) << "MockPort was not set up by the test fixture";
+ return mockPort->inb(v);
+}
+
+void
+outb(unsigned char p, unsigned short v)
+{
+ EXPECT_TRUE(mockPort) << "MockPort was not set up by the test fixture";
+ return mockPort->outb(p, v);
+}
+}