Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/dcc/tests/state_machine_budget.cpp
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

62 lines
1.8 KiB
C++

#include <gtest/gtest.h>
#include <vanetza/common/clock.hpp>
#include <vanetza/common/manual_runtime.hpp>
#include <vanetza/dcc/fully_meshed_state_machine.hpp>
#include <vanetza/dcc/state_machine_budget.hpp>
using namespace vanetza::dcc;
using vanetza::ManualRuntime;
using std::chrono::milliseconds;
static const vanetza::Clock::duration immediately = milliseconds(0);
class StateMachineBudgetTest : public ::testing::Test
{
protected:
StateMachineBudgetTest() :
runtime(vanetza::Clock::time_point { std::chrono::seconds(4711) }),
budget(fsm, runtime) {}
ManualRuntime runtime;
FullyMeshedStateMachine fsm;
StateMachineBudget budget;
};
TEST_F(StateMachineBudgetTest, relaxed)
{
Relaxed relaxed;
const auto relaxed_tx_interval = relaxed.transmission_interval();
ASSERT_EQ(relaxed_tx_interval, fsm.transmission_interval());
EXPECT_EQ(immediately, budget.delay());
budget.notify();
EXPECT_EQ(relaxed_tx_interval, budget.delay());
runtime.trigger(relaxed_tx_interval - milliseconds(10));
EXPECT_EQ(milliseconds(10), budget.delay());
runtime.trigger(milliseconds(20));
EXPECT_EQ(immediately, budget.delay());
}
TEST_F(StateMachineBudgetTest, restrictive)
{
Restrictive restrictive;
const auto restrictive_tx_interval = restrictive.transmission_interval();
// put FSM into restrictive state
for (unsigned i = 0; i < 10; ++i) {
fsm.update(ChannelLoad(0.6));
}
ASSERT_STREQ("Restrictive", fsm.state().name());
EXPECT_EQ(immediately, budget.delay());
budget.notify();
EXPECT_EQ(restrictive_tx_interval, budget.delay());
runtime.trigger(restrictive_tx_interval / 2);
EXPECT_EQ(restrictive_tx_interval / 2, budget.delay());
runtime.trigger(restrictive_tx_interval / 2);
EXPECT_EQ(immediately, budget.delay());
}