Skip to content

Commit

Permalink
fix: fixed failing tests due to noninitialized variable
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Aug 30, 2023
1 parent fed8718 commit 2ac8695
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/TraceReader/TraceReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class TraceReader
std::atomic<bool> isRunning{false};
std::string lastErrorMsg = "";

std::array<uint32_t, channels> previousEntry;
std::array<uint32_t, channels> previousEntry{};
std::unique_ptr<RingBuffer<std::pair<std::array<uint32_t, channels>, double>>> traceTable;

std::thread readerHandle;
Expand Down
2 changes: 1 addition & 1 deletion src/TraceReader/TraceReaderNew.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class TraceReaderNew
std::atomic<bool> isRunning{false};
std::string lastErrorMsg = "";

std::array<uint32_t, channels> previousEntry;
std::array<uint32_t, channels> previousEntry{};
std::unique_ptr<RingBuffer<std::pair<std::array<uint32_t, channels>, double>>> traceTable;

std::thread readerHandle;
Expand Down
90 changes: 45 additions & 45 deletions test/TraceReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,48 +217,48 @@ TEST_F(TraceReaderTest, testdoubleBuffers)
}
}

// TEST_F(TraceReaderTest, testdoubleBuffersBoundarySource)
// {
// uint8_t buf[] = {9, 187, 192, 206, 9,
// 17, 170, 192, 35,
// 17, 187, 192, 233, 2,
// 9, 170, 192, 165, 1, 9};

// uint8_t buf2[] = {187, 192, 202, 9,
// 17, 170, 192, 35,
// 17, 187, 192, 234, 2,
// 25, 170, 192, 23};

// std::array<uint32_t, channels> trace{};

// std::array<double, 10> expectedTimestamp = {7.6875e-06, 2.1875e-07, 2.25625e-06, 1.03125e-06, 7.6625e-06, 2.1875e-07, 2.2625e-06, 1.4375e-07};
// std::array<std::array<uint32_t, channels>, 8> expectedTrace{{{{0, 187, 0, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 170, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 170, 187, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 170, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
// {{0, 187, 187, 170, 0, 0, 0, 0, 0, 0}}}};

// EXPECT_CALL(*traceDevice, readTraceBuffer(_, _))
// .WillOnce(testing::Invoke([&](uint8_t* buffer, uint32_t size)
// {memcpy(buffer,buf,sizeof(buf));
// return sizeof(buf); }))
// .WillOnce(testing::Invoke([&](uint8_t* buffer, uint32_t size)
// {memcpy(buffer,buf2,sizeof(buf2));
// return sizeof(buf2); }))
// .WillRepeatedly(Return(0));

// traceReader->startAcqusition(activeChannels);
// std::this_thread::sleep_for(std::chrono::milliseconds(50));

// int i = 0;
// for (auto& e : expectedTrace)
// {
// double timestamp = 0.0;
// ASSERT_EQ(traceReader->readTrace(timestamp, trace), true);
// ASSERT_NEAR(expectedTimestamp[i++], timestamp, 10e-9);
// ASSERT_EQ(trace, e);
// }
// }
TEST_F(TraceReaderTest, testdoubleBuffersBoundarySource)
{
uint8_t buf[] = {9, 187, 192, 206, 9,
17, 170, 192, 35,
17, 187, 192, 233, 2,
9, 170, 192, 165, 1, 9};

uint8_t buf2[] = {187, 192, 202, 9,
17, 170, 192, 35,
17, 187, 192, 234, 2,
25, 170, 192, 23};

std::array<uint32_t, channels> trace{};

std::array<double, 10> expectedTimestamp = {7.6875e-06, 2.1875e-07, 2.25625e-06, 1.03125e-06, 7.6625e-06, 2.1875e-07, 2.2625e-06, 1.4375e-07};
std::array<std::array<uint32_t, channels>, 8> expectedTrace{{{{0, 187, 0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 170, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
{{0, 170, 187, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 170, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 187, 0, 0, 0, 0, 0, 0, 0}},
{{0, 187, 187, 170, 0, 0, 0, 0, 0, 0}}}};

EXPECT_CALL(*traceDevice, readTraceBuffer(_, _))
.WillOnce(testing::Invoke([&](uint8_t* buffer, uint32_t size)
{memcpy(buffer,buf,sizeof(buf));
return sizeof(buf); }))
.WillOnce(testing::Invoke([&](uint8_t* buffer, uint32_t size)
{memcpy(buffer,buf2,sizeof(buf2));
return sizeof(buf2); }))
.WillRepeatedly(Return(0));

traceReader->startAcqusition(activeChannels);
std::this_thread::sleep_for(std::chrono::milliseconds(50));

int i = 0;
for (auto& e : expectedTrace)
{
double timestamp = 0.0;
ASSERT_EQ(traceReader->readTrace(timestamp, trace), true);
ASSERT_NEAR(expectedTimestamp[i++], timestamp, 10e-9);
ASSERT_EQ(trace, e);
}
}

0 comments on commit 2ac8695

Please sign in to comment.