A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
30
namespace
ns3
31
{
32
33
namespace
tests
34
{
35
40
class
WatchdogTestCase
:
public
TestCase
41
{
42
public
:
44
WatchdogTestCase
();
45
void
DoRun
()
override
;
50
void
Expire
(
int
arg);
51
bool
m_expired
;
52
Time
m_expiredTime
;
53
int
m_expiredArgument
;
54
};
55
56
WatchdogTestCase::WatchdogTestCase
()
57
:
TestCase
(
"Check that we can keepalive a watchdog"
)
58
{
59
}
60
61
void
62
WatchdogTestCase::Expire
(
int
arg)
63
{
64
m_expired
=
true
;
65
m_expiredTime
=
Simulator::Now
();
66
m_expiredArgument
= arg;
67
}
68
69
void
70
WatchdogTestCase::DoRun
()
71
{
72
m_expired
=
false
;
73
m_expiredArgument
= 0;
74
m_expiredTime
=
Seconds
(0);
75
76
Watchdog
watchdog;
77
watchdog.
SetFunction
(&
WatchdogTestCase::Expire
,
this
);
78
watchdog.
SetArguments
(1);
79
watchdog.
Ping
(
MicroSeconds
(10));
80
Simulator::Schedule
(
MicroSeconds
(5), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(20));
81
Simulator::Schedule
(
MicroSeconds
(20), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(2));
82
Simulator::Schedule
(
MicroSeconds
(23), &
Watchdog::Ping
, &watchdog,
MicroSeconds
(17));
83
Simulator::Run
();
84
Simulator::Destroy
();
85
NS_TEST_ASSERT_MSG_EQ
(
m_expired
,
true
,
"The timer did not expire ??"
);
86
NS_TEST_ASSERT_MSG_EQ
(
m_expiredTime
,
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
96
class
WatchdogTestSuite
:
public
TestSuite
97
{
98
public
:
100
WatchdogTestSuite
()
101
:
TestSuite
(
"watchdog"
)
102
{
103
AddTestCase
(
new
WatchdogTestCase
());
104
}
105
};
106
111
static
WatchdogTestSuite
g_watchdogTestSuite
;
112
113
}
// namespace tests
114
115
}
// 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:571
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:208
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition:
watchdog.h:57
ns3::Watchdog::SetArguments
void SetArguments(Ts &&... args)
Set the arguments to be used when invoking the expire function.
Definition:
watchdog.h:154
ns3::Watchdog::Ping
void Ping(Time delay)
Delay the timer.
Definition:
watchdog.cc:50
ns3::Watchdog::SetFunction
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition:
watchdog.h:138
ns3::tests::WatchdogTestCase
Watchdog test.
Definition:
watchdog-test-suite.cc:41
ns3::tests::WatchdogTestCase::Expire
void Expire(int arg)
Function to invoke when Watchdog expires.
Definition:
watchdog-test-suite.cc:62
ns3::tests::WatchdogTestCase::m_expiredArgument
int m_expiredArgument
Argument supplied to expired Watchdog.
Definition:
watchdog-test-suite.cc:53
ns3::tests::WatchdogTestCase::m_expiredTime
Time m_expiredTime
Time when Watchdog expired.
Definition:
watchdog-test-suite.cc:52
ns3::tests::WatchdogTestCase::m_expired
bool m_expired
Flag for expired Watchdog.
Definition:
watchdog-test-suite.cc:51
ns3::tests::WatchdogTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
watchdog-test-suite.cc:70
ns3::tests::WatchdogTestCase::WatchdogTestCase
WatchdogTestCase()
Constructor.
Definition:
watchdog-test-suite.cc:56
ns3::tests::WatchdogTestSuite
Watchdog test suite.
Definition:
watchdog-test-suite.cc:97
ns3::tests::WatchdogTestSuite::WatchdogTestSuite
WatchdogTestSuite()
Constructor.
Definition:
watchdog-test-suite.cc:100
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:144
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1350
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
ns3::tests::g_watchdogTestSuite
static WatchdogTestSuite g_watchdogTestSuite
WatchdogTestSuite instance variable.
Definition:
watchdog-test-suite.cc:111
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
test
watchdog-test-suite.cc
Generated on Sun Mar 3 2024 17:10:56 for ns-3 by
1.9.1