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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#include "ns3/test.h"
20#include "ns3/watchdog.h"
21
30namespace ns3
31{
32
33namespace tests
34{
35
41{
42 public:
45 void DoRun() override;
50 void Expire(int arg);
51 bool m_expired;
54};
55
57 : TestCase("Check that we can keepalive a watchdog")
58{
59}
60
61void
63{
64 m_expired = true;
67}
68
69void
71{
72 m_expired = false;
75
76 Watchdog watchdog;
78 watchdog.SetArguments(1);
79 watchdog.Ping(MicroSeconds(10));
85 NS_TEST_ASSERT_MSG_EQ(m_expired, true, "The timer did not expire ??");
87 MicroSeconds(40),
88 "The timer did not expire at the expected time ?");
89 NS_TEST_ASSERT_MSG_EQ(m_expiredArgument, 1, "We did not get the right argument");
90}
91
97{
98 public:
101 : TestSuite("watchdog")
102 {
104 }
105};
106
112
113} // namespace tests
114
115} // namespace ns3
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
A very simple watchdog operating in virtual time.
Definition: watchdog.h:57
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition: watchdog.h:154
void Ping(Time delay)
Delay the timer.
Definition: watchdog.cc:50
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition: watchdog.h:138
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:145
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
static WatchdogTestSuite g_watchdogTestSuite
WatchdogTestSuite instance variable.
Every class exported by the ns3 library is enclosed in the ns3 namespace.