Skip to content

Commit

Permalink
TraceBuilder: signal() - add support for vector<uint32_t>
Browse files Browse the repository at this point in the history
  • Loading branch information
JimKnowler committed Mar 16, 2021
1 parent b39f341 commit fa33866
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions gtestverilog/lib/TraceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ namespace gtestverilog {
return *this;
}

TraceBuilder& TraceBuilder::signal(const std::vector<uint32_t>& stepValues) {
if (!currentPort) {
throw std::logic_error("unable to add signal without current port");
}

if (stepValues.size() == 0) {
throw std::logic_error("unable to add zero-length signal");
}

concat();

currentSignal.insert(currentSignal.end(), stepValues.begin(), stepValues.end());

return *this;
}

TraceBuilder& TraceBuilder::repeat(size_t repetitions) {
applyModifier([=](std::vector<PortValue>& signal) {
std::vector<PortValue> newSignal;
Expand Down
4 changes: 4 additions & 0 deletions gtestverilog/lib/TraceBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace gtestverilog {
/// @note subsequent modifiers will be applied only to this signal, until concat() or allPorts() are called
TraceBuilder& signal(const std::initializer_list<uint32_t>& stepValues);

/// @brief append a new signal to the current port
/// @note subsequent modifiers will be applied only to this signal, until concat() or allPorts() are called
TraceBuilder& signal(const std::vector<uint32_t>& stepValues);

/// @brief repeat the current signal being added to the current port
/// @example TraceBuilder().port(myPort).signal("abcd").repeat(2) => "abcdabcd"
TraceBuilder& repeat(size_t repetitions);
Expand Down
17 changes: 17 additions & 0 deletions gtestverilog/test/TraceBuilder.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,20 @@ TEST(TraceBuilder, ShouldFailToAddEmptyPortValueSignal) {
.port(test_port_0).signal({})
);
}

TEST(TraceBuilder, ShouldAddSignalFromVectorAndInitialiserList) {
std::vector<uint32_t> steps1 = {3, 1};
Trace trace = TraceBuilder()
.port(test_port_1).signal(steps1).repeatEachStep(2).signal({2, 4}).repeatEachStep(2);

const std::vector<Step>& steps = trace.getSteps();
ASSERT_EQ(steps.size(), 8);
ASSERT_EQ(std::get<uint32_t>(steps[0].port(test_port_1)), 3);
ASSERT_EQ(std::get<uint32_t>(steps[1].port(test_port_1)), 3);
ASSERT_EQ(std::get<uint32_t>(steps[2].port(test_port_1)), 1);
ASSERT_EQ(std::get<uint32_t>(steps[3].port(test_port_1)), 1);
ASSERT_EQ(std::get<uint32_t>(steps[4].port(test_port_1)), 2);
ASSERT_EQ(std::get<uint32_t>(steps[5].port(test_port_1)), 2);
ASSERT_EQ(std::get<uint32_t>(steps[6].port(test_port_1)), 4);
ASSERT_EQ(std::get<uint32_t>(steps[7].port(test_port_1)), 4);
}

0 comments on commit fa33866

Please sign in to comment.