mirror of
https://github.com/meekrosoft/fff
synced 2026-01-27 02:11:37 +01:00
Migrate build to CMake and standard github workflows
Replace makefiles with CMakeLists.txt. This will allow for IDE and platform agnostic builds of FFF. Update the CI for FFF to use github workflows which don't depend on MS VC. The workflow added will verify the pull requests sent to master buy running 'buildandtest' which mirrors the developer workflow. Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
24
examples/driver_testing/src/driver.c
Normal file
24
examples/driver_testing/src/driver.c
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
|
||||
#include "hardware_abstraction.h"
|
||||
#include "registers.h"
|
||||
|
||||
void driver_write(uint8_t val)
|
||||
{
|
||||
IO_MEM_WR8(DRIVER_OUTPUT_REGISTER, val);
|
||||
}
|
||||
|
||||
uint8_t driver_read()
|
||||
{
|
||||
return IO_MEM_RD8(DRIVER_INPUT_REGISTER);
|
||||
}
|
||||
|
||||
void driver_init_device()
|
||||
{
|
||||
uint8_t hw_version = IO_MEM_RD8(HARDWARE_VERSION_REGISTER);
|
||||
if(HARDWARE_REV_B == hw_version)
|
||||
{
|
||||
IO_MEM_WR8(DRIVER_PERIPHERAL_ENABLE_REG, 1);
|
||||
}
|
||||
IO_MEM_WR8(DRIVER_PERIPHERAL_INITIALIZE_REG, 1);
|
||||
}
|
||||
50
examples/driver_testing/src/driver.test.cpp
Normal file
50
examples/driver_testing/src/driver.test.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "driver.h"
|
||||
#include "registers.h"
|
||||
}
|
||||
#include "../../../fff.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static uint8_t readVal;
|
||||
static int readCalled;
|
||||
static uint32_t readRegister;
|
||||
uint8_t IO_MEM_RD8(uint32_t reg)
|
||||
{
|
||||
readRegister = reg;
|
||||
readCalled++;
|
||||
return readVal;
|
||||
}
|
||||
|
||||
static uint32_t writeRegister;
|
||||
static uint8_t writeVal;
|
||||
static int writeCalled;
|
||||
void IO_MEM_WR8(uint32_t reg, uint8_t val)
|
||||
{
|
||||
writeRegister = reg;
|
||||
writeVal = val;
|
||||
writeCalled++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Driver, When_writing_Then_writes_data_to_DRIVER_OUTPUT_REGISTER)
|
||||
{
|
||||
driver_write(0x34);
|
||||
ASSERT_EQ(1u, writeCalled);
|
||||
ASSERT_EQ(0x34u, writeVal);
|
||||
ASSERT_EQ(DRIVER_OUTPUT_REGISTER, writeRegister);
|
||||
}
|
||||
|
||||
|
||||
TEST(Driver, When_reading_data_Then_reads_from_DRIVER_INPUT_REGISTER)
|
||||
{
|
||||
readVal = 0x55;
|
||||
uint8_t returnedValue = driver_read();
|
||||
ASSERT_EQ(1u, readCalled);
|
||||
ASSERT_EQ(0x55u, returnedValue);
|
||||
ASSERT_EQ(readRegister, DRIVER_INPUT_REGISTER);
|
||||
}
|
||||
|
||||
63
examples/driver_testing/src/driver.test.fff.cpp
Normal file
63
examples/driver_testing/src/driver.test.fff.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
extern "C"{
|
||||
#include "driver.h"
|
||||
#include "registers.h"
|
||||
#include "hardware_abstraction.h"
|
||||
}
|
||||
#include "fff.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
DEFINE_FFF_GLOBALS;
|
||||
|
||||
FAKE_VOID_FUNC(IO_MEM_WR8, uint32_t, uint8_t);
|
||||
FAKE_VALUE_FUNC(uint8_t, IO_MEM_RD8, uint32_t);
|
||||
|
||||
class DriverTestFFF : public testing::Test
|
||||
{
|
||||
public:
|
||||
void SetUp()
|
||||
{
|
||||
RESET_FAKE(IO_MEM_WR8);
|
||||
RESET_FAKE(IO_MEM_RD8);
|
||||
FFF_RESET_HISTORY();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST_F(DriverTestFFF, When_writing_Then_writes_data_to_DRIVER_OUTPUT_REGISTER)
|
||||
{
|
||||
driver_write(0x34);
|
||||
ASSERT_EQ(1u, IO_MEM_WR8_fake.call_count);
|
||||
ASSERT_EQ(0x34u, IO_MEM_WR8_fake.arg1_val);
|
||||
ASSERT_EQ(DRIVER_OUTPUT_REGISTER, IO_MEM_WR8_fake.arg0_val);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DriverTestFFF, When_reading_data_Then_reads_from_DRIVER_INPUT_REGISTER)
|
||||
{
|
||||
IO_MEM_RD8_fake.return_val = 0x55;
|
||||
uint8_t returnedValue = driver_read();
|
||||
ASSERT_EQ(1u, IO_MEM_RD8_fake.call_count);
|
||||
ASSERT_EQ(0x55u, returnedValue);
|
||||
ASSERT_EQ(IO_MEM_RD8_fake.arg0_val, DRIVER_INPUT_REGISTER);
|
||||
}
|
||||
|
||||
TEST_F(DriverTestFFF, Given_revisionB_device_When_initialize_Then_enable_peripheral_before_initializing_it)
|
||||
{
|
||||
// Given
|
||||
IO_MEM_RD8_fake.return_val = HARDWARE_REV_B;
|
||||
// When
|
||||
driver_init_device();
|
||||
|
||||
//Then
|
||||
// Gets the hardware revision
|
||||
ASSERT_EQ((void*) IO_MEM_RD8, fff.call_history[0]);
|
||||
ASSERT_EQ(HARDWARE_VERSION_REGISTER, IO_MEM_RD8_fake.arg0_history[0]);
|
||||
// Enables Peripheral
|
||||
ASSERT_EQ((void*) IO_MEM_WR8, fff.call_history[1]);
|
||||
ASSERT_EQ(DRIVER_PERIPHERAL_ENABLE_REG, IO_MEM_WR8_fake.arg0_history[0]);
|
||||
ASSERT_EQ(1, IO_MEM_WR8_fake.arg1_history[0]);
|
||||
// Initializes Peripheral
|
||||
ASSERT_EQ((void*) IO_MEM_WR8, fff.call_history[2]);
|
||||
ASSERT_EQ(DRIVER_PERIPHERAL_INITIALIZE_REG,IO_MEM_WR8_fake.arg0_history[1]);
|
||||
ASSERT_EQ(1, IO_MEM_WR8_fake.arg1_history[1]);
|
||||
}
|
||||
Reference in New Issue
Block a user