Skip to content

Commit

Permalink
testability: bench test commands should have automated coverage using…
Browse files Browse the repository at this point in the history
… simulator #5562
  • Loading branch information
rusefillc committed Sep 14, 2023
1 parent 1dc0cab commit 735e442
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions firmware/controllers/can/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#define HAS_CAN_FRAME (EFI_SIMULATOR || HAL_USE_CAN || EFI_UNIT_TEST)

#if EFI_UNIT_TEST || !EFI_CAN_SUPPORT
#include "can_mocks.h"
#endif // EFI_PROD_CODE
Expand Down
13 changes: 11 additions & 2 deletions firmware/hw_layer/drivers/can/can_msg_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

#include "can.h"

#if EFI_SIMULATOR
#include "fifo_buffer.h"
fifo_buffer<CANTxFrame, 1024> txCanBuffer;
#endif // EFI_SIMULATOR

#if EFI_CAN_SUPPORT
/*static*/ CANDriver* CanTxMessage::s_devices[2] = {nullptr, nullptr};

Expand All @@ -25,7 +30,7 @@

CanTxMessage::CanTxMessage(CanCategory category, uint32_t eid, uint8_t dlc, size_t bus, bool isExtended) {
this->category = category;
#if HAL_USE_CAN || EFI_UNIT_TEST
#if HAS_CAN_FRAME
#ifndef STM32H7XX
// ST bxCAN device
m_frame.IDE = isExtended ? CAN_IDE_EXT : CAN_IDE_STD;
Expand All @@ -51,10 +56,14 @@ CanTxMessage::CanTxMessage(CanCategory category, uint32_t eid, uint8_t dlc, size
setBus(bus);

memset(m_frame.data8, 0, sizeof(m_frame.data8));
#endif // HAL_USE_CAN || EFI_UNIT_TEST
#endif // HAS_CAN_FRAME
}

CanTxMessage::~CanTxMessage() {
#if EFI_SIMULATOR
txCanBuffer.put(m_frame);
#endif // EFI_SIMULATOR

#if EFI_CAN_SUPPORT
auto device = s_devices[busIndex];

Expand Down
4 changes: 2 additions & 2 deletions firmware/hw_layer/drivers/can/can_msg_tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class CanTxMessage

void setBus(size_t bus);

#if HAL_USE_CAN || EFI_UNIT_TEST
#if HAS_CAN_FRAME
const CANTxFrame *getFrame() const {
return &m_frame;
}
#endif // HAL_USE_CAN || EFI_UNIT_TEST

protected:
#if HAL_USE_CAN || EFI_UNIT_TEST
#if HAS_CAN_FRAME
CANTxFrame m_frame;
#endif // HAL_USE_CAN || EFI_UNIT_TEST

Expand Down

0 comments on commit 735e442

Please sign in to comment.