A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
watchdog-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "ns3/test.h"
9#include "ns3/watchdog.h"
10
11/**
12 * @file
13 * @ingroup core-tests
14 * @ingroup timer
15 * @ingroup timer-tests
16 * Watchdog test suite.
17 */
18
19namespace ns3
20{
21
22namespace tests
23{
24
25/**
26 * @ingroup timer-tests
27 * Watchdog test
28 */
30{
31 public:
32 /** Constructor. */
34 void DoRun() override;
35 /**
36 * Function to invoke when Watchdog expires.
37 * @param arg The argument passed.
38 */
39 void Expire(int arg);
40 bool m_expired; //!< Flag for expired Watchdog
41 Time m_expiredTime; //!< Time when Watchdog expired
42 int m_expiredArgument; //!< Argument supplied to expired Watchdog
43};
44
46 : TestCase("Check that we can keepalive a watchdog")
47{
48}
49
50void
57
58void
60{
61 m_expired = false;
64
65 Watchdog watchdog;
67 watchdog.SetArguments(1);
68 watchdog.Ping(MicroSeconds(10));
74 NS_TEST_ASSERT_MSG_EQ(m_expired, true, "The timer did not expire ??");
76 MicroSeconds(40),
77 "The timer did not expire at the expected time ?");
78 NS_TEST_ASSERT_MSG_EQ(m_expiredArgument, 1, "We did not get the right argument");
79}
80
81/**
82 * @ingroup timer-tests
83 * Watchdog test suite
84 */
86{
87 public:
88 /** Constructor. */
90 : TestSuite("watchdog")
91 {
93 }
94};
95
96/**
97 * @ingroup timer-tests
98 * WatchdogTestSuite instance variable.
99 */
101
102} // namespace tests
103
104} // namespace ns3
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
A very simple watchdog operating in virtual time.
Definition watchdog.h:51
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition watchdog.h:148
void Ping(Time delay)
Delay the timer.
Definition watchdog.cc:39
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition watchdog.h:132
void Expire(int arg)
Function to invoke when Watchdog expires.
int m_expiredArgument
Argument supplied to expired Watchdog.
Time m_expiredTime
Time when Watchdog expired.
bool m_expired
Flag for expired Watchdog.
void DoRun() override
Implementation to actually run this TestCase.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
static WatchdogTestSuite g_watchdogTestSuite
WatchdogTestSuite instance variable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.