Skip to content

Commit

Permalink
Unit tests are updated to support Multidrop feature in Helper classes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lexus2k committed Feb 6, 2022
1 parent 28ccb9e commit 2191a15
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 149 deletions.
11 changes: 8 additions & 3 deletions unittest/fd_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ TEST(FD, arduino_to_pc)

TEST(FD, errors_on_tx_line)
{
FakeConnection conn;
// Limit hardware blocks to 32 byte buffers only.
// Too large blocks cause much frames to be bufferred, and each restransmission
// contains errors (because we set error every 200 bytes)
FakeConnection conn(32, 32);
uint16_t nsent = 0;
TinyHelperFd helper1(&conn.endpoint1(), 1024, nullptr, 7, 400);
TinyHelperFd helper2(&conn.endpoint2(), 1024, nullptr, 7, 400);
// Also, to make test logs more clear, we limit window size to 3 frames only.
// This will give us clear understanding what is happenning when something goes wrong
TinyHelperFd helper1(&conn.endpoint1(), 1024, nullptr, 3, 400);
TinyHelperFd helper2(&conn.endpoint2(), 1024, nullptr, 3, 400);
conn.line2().generate_error_every_n_byte(200);
helper1.run(true);
helper2.run(true);
Expand Down
8 changes: 4 additions & 4 deletions unittest/hal_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ TEST(HAL, micros)
std::this_thread::sleep_for(std::chrono::milliseconds(1));
uint32_t delta = static_cast<uint32_t>( tiny_micros() - start );
// fprintf(stderr, "DELTA: %d\n", delta );
bool result = delta >= 1000 && delta < 1900;
CHECK_TEXT( result, "Timestamping functions are incorrect" );
CHECK_TEXT( delta >= 1000, "Timestamping functions are incorrect" );
CHECK_TEXT( delta < 2100, "Timestamping functions are incorrect" );
tiny_sleep_us( 500 );
delta = static_cast<uint32_t>( tiny_micros() - start );
// fprintf(stderr, "DELTA: %d\n", delta );
result = delta >= 1500 && delta < 3500;
CHECK_TEXT( result, "Sleep function works incorrectly" );
CHECK_TEXT( delta >= 1500, "Sleep function works incorrectly" );
CHECK_TEXT( delta < 4000, "Sleep function works incorrectly" );
}
2 changes: 1 addition & 1 deletion unittest/hdlc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ TEST(HDLC, arduino_to_pc)
}
if ( arduino.tx_count() > pc.rx_count() + (conn.lostBytes() ? 5 : 0) )
CHECK_EQUAL(arduino.tx_count(), pc.rx_count());
if ( conn.lostBytes() > 30 )
if ( conn.lostBytes() > 2000 ) // 115200 / 8 * 100 milliseconds = 1440 bytes can be lost
CHECK_EQUAL(0, conn.lostBytes());
}

Expand Down
10 changes: 6 additions & 4 deletions unittest/helpers/fake_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class FakeConnection
}

FakeConnection(int p1_hw_size, int p2_hw_size)
: m_line1(p1_hw_size, p2_hw_size)
, m_line2(p2_hw_size, p1_hw_size)
: m_line1()
, m_line2()
, m_endpoint1(m_line1, m_line2, p1_hw_size, p1_hw_size)
, m_endpoint2(m_line2, m_line1, p2_hw_size, p2_hw_size)
, m_line_thread(TransferDataStatic, this)
{
setSpeed( 512000 );
Expand Down Expand Up @@ -80,8 +82,8 @@ class FakeConnection
private:
FakeWire m_line1{};
FakeWire m_line2{};
FakeEndpoint m_endpoint1{m_line1, m_line2};
FakeEndpoint m_endpoint2{m_line2, m_line1};
FakeEndpoint m_endpoint1{m_line1, m_line2, 256, 256};
FakeEndpoint m_endpoint2{m_line2, m_line1, 256, 256};
std::atomic<uint64_t> m_interval_us{50};
std::atomic<uint64_t> m_Bps{64000};
std::atomic<bool> m_stopped{false};
Expand Down
10 changes: 6 additions & 4 deletions unittest/helpers/fake_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

#include "fake_endpoint.h"

FakeEndpoint::FakeEndpoint(FakeWire &tx, FakeWire &rx)
FakeEndpoint::FakeEndpoint(FakeWire &tx, FakeWire &rx, int rxSize, int txSize)
: m_tx(tx)
, m_rx(rx)
{
m_txBlock = m_tx.CreateTxHardware(txSize);
m_rxBlock = m_rx.CreateRxHardware(rxSize);
}

FakeEndpoint::~FakeEndpoint()
Expand All @@ -31,15 +33,15 @@ FakeEndpoint::~FakeEndpoint()

int FakeEndpoint::read(uint8_t *data, int length)
{
return m_rx.read(data, length, m_timeout);
return m_rxBlock->Read(data, length, m_timeout);
}

int FakeEndpoint::write(const uint8_t *data, int length)
{
return m_tx.write(data, length, m_timeout);
return m_txBlock->Write(data, length, m_timeout);
}

bool FakeEndpoint::wait_until_rx_count(int count, int timeout)
{
return m_rx.wait_until_rx_count(count, timeout);
return m_rxBlock->WaitUntilRxCount(count, timeout);
}
10 changes: 6 additions & 4 deletions unittest/helpers/fake_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class FakeEndpoint
{
public:
FakeEndpoint(FakeWire &tx, FakeWire &rx);
FakeEndpoint(FakeWire &tx, FakeWire &rx, int rxSize, int txSize);

~FakeEndpoint();

Expand All @@ -42,20 +42,22 @@ class FakeEndpoint
}
void disable()
{
m_rx.disable();
m_rxBlock->Disable();
}
void enable()
{
m_rx.enable();
m_rxBlock->Enable();
}
void flush()
{
m_rx.flush();
m_rxBlock->Flush();
}

private:
FakeWire &m_tx;
FakeWire &m_rx;
TxHardwareBlock *m_txBlock = nullptr;
RxHardwareBlock *m_rxBlock = nullptr;
std::mutex m_mutex;
int m_timeout = 10;
};
Expand Down
Loading

0 comments on commit 2191a15

Please sign in to comment.