A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
19
namespace
ns3
20
{
21
22
namespace
tests
23
{
24
25
/**
26
* @ingroup timer-tests
27
* Watchdog test
28
*/
29
class
WatchdogTestCase
:
public
TestCase
30
{
31
public
:
32
/** Constructor. */
33
WatchdogTestCase
();
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
45
WatchdogTestCase::WatchdogTestCase
()
46
:
TestCase
(
"Check that we can keepalive a watchdog"
)
47
{
48
}
49
50
void
51
WatchdogTestCase::Expire
(
int
arg)
52
{
53
m_expired
=
true
;
54
m_expiredTime
=
Simulator::Now
();
55
m_expiredArgument
= arg;
56
}
57
58
void
59
WatchdogTestCase::DoRun
()
60
{
61
m_expired
=
false
;
62
m_expiredArgument
= 0;
63
m_expiredTime
=
Seconds
(0);
64
65
Watchdog
watchdog;
66
watchdog.
SetFunction
(&
WatchdogTestCase::Expire
,
this
);
67
watchdog.
SetArguments
(1);
68
watchdog.
Ping
(
MicroSeconds
(10));
69
Simulator::Schedule
(
MicroSeconds
(5), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(20));
70
Simulator::Schedule
(
MicroSeconds
(20), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(2));
71
Simulator::Schedule
(
MicroSeconds
(23), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(17));
72
Simulator::Run
();
73
Simulator::Destroy
();
74
NS_TEST_ASSERT_MSG_EQ
(
m_expired
,
true
,
"The timer did not expire ??"
);
75
NS_TEST_ASSERT_MSG_EQ
(
m_expiredTime
,
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
*/
85
class
WatchdogTestSuite
:
public
TestSuite
86
{
87
public
:
88
/** Constructor. */
89
WatchdogTestSuite
()
90
:
TestSuite
(
"watchdog"
)
91
{
92
AddTestCase
(
new
WatchdogTestCase
());
93
}
94
};
95
96
/**
97
* @ingroup timer-tests
98
* WatchdogTestSuite instance variable.
99
*/
100
static
WatchdogTestSuite
g_watchdogTestSuite
;
101
102
}
// namespace tests
103
104
}
// namespace ns3
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition
simulator.h:560
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition
watchdog.h:51
ns3::Watchdog::SetArguments
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition
watchdog.h:148
ns3::Watchdog::Ping
void Ping(Time delay)
Delay the timer.
Definition
watchdog.cc:39
ns3::Watchdog::SetFunction
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition
watchdog.h:132
ns3::tests::WatchdogTestCase
Watchdog test.
Definition
watchdog-test-suite.cc:30
ns3::tests::WatchdogTestCase::Expire
void Expire(int arg)
Function to invoke when Watchdog expires.
Definition
watchdog-test-suite.cc:51
ns3::tests::WatchdogTestCase::m_expiredArgument
int m_expiredArgument
Argument supplied to expired Watchdog.
Definition
watchdog-test-suite.cc:42
ns3::tests::WatchdogTestCase::m_expiredTime
Time m_expiredTime
Time when Watchdog expired.
Definition
watchdog-test-suite.cc:41
ns3::tests::WatchdogTestCase::m_expired
bool m_expired
Flag for expired Watchdog.
Definition
watchdog-test-suite.cc:40
ns3::tests::WatchdogTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
watchdog-test-suite.cc:59
ns3::tests::WatchdogTestCase::WatchdogTestCase
WatchdogTestCase()
Constructor.
Definition
watchdog-test-suite.cc:45
ns3::tests::WatchdogTestSuite
Watchdog test suite.
Definition
watchdog-test-suite.cc:86
ns3::tests::WatchdogTestSuite::WatchdogTestSuite
WatchdogTestSuite()
Constructor.
Definition
watchdog-test-suite.cc:89
NS_TEST_ASSERT_MSG_EQ
#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
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1368
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3::tests::g_watchdogTestSuite
static WatchdogTestSuite g_watchdogTestSuite
WatchdogTestSuite instance variable.
Definition
watchdog-test-suite.cc:100
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
test
watchdog-test-suite.cc
Generated on Fri Dec 13 2024 09:20:39 for ns-3 by
1.11.0