A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
watchdog-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "ns3/watchdog.h"
21
#include "ns3/test.h"
22
23
using namespace
ns3
;
24
25
class
WatchdogTestCase
:
public
TestCase
26
{
27
public
:
28
WatchdogTestCase
();
29
virtual
void
DoRun (
void
);
30
void
Expire (
Time
expected);
31
bool
m_expired
;
32
Time
m_expiredTime
;
33
Time
m_expiredArgument
;
34
};
35
36
WatchdogTestCase::WatchdogTestCase
()
37
:
TestCase
(
"Check that we can keepalive a watchdog"
)
38
{
39
}
40
41
void
42
WatchdogTestCase::Expire
(
Time
expected)
43
{
44
m_expired
=
true
;
45
m_expiredTime
=
Simulator::Now
();
46
m_expiredArgument
= expected;
47
}
48
49
void
50
WatchdogTestCase::DoRun
(
void
)
51
{
52
m_expired
=
false
;
53
m_expiredArgument
=
Seconds
(0);
54
m_expiredTime
=
Seconds
(0);
55
Watchdog
watchdog;
56
watchdog.
SetFunction
(&
WatchdogTestCase::Expire
,
this
);
57
watchdog.
SetArguments
(
MicroSeconds
(40));
58
watchdog.
Ping
(
MicroSeconds
(10));
59
Simulator::Schedule (
MicroSeconds
(5), &Watchdog::Ping, &watchdog,
MicroSeconds
(20));
60
Simulator::Schedule (
MicroSeconds
(20), &Watchdog::Ping, &watchdog,
MicroSeconds
(2));
61
Simulator::Schedule (
MicroSeconds
(23), &Watchdog::Ping, &watchdog,
MicroSeconds
(17));
62
Simulator::Run ();
63
Simulator::Destroy ();
64
NS_TEST_ASSERT_MSG_EQ
(
m_expired
,
true
,
"The timer did not expire ??"
);
65
NS_TEST_ASSERT_MSG_EQ
(
m_expiredTime
,
MicroSeconds
(40),
"The timer did not expire at the expected time ?"
);
66
NS_TEST_ASSERT_MSG_EQ
(
m_expiredArgument
,
MicroSeconds
(40),
"We did not get the right argument"
);
67
}
68
69
70
71
static
class
WatchdogTestSuite
:
public
TestSuite
72
{
73
public
:
74
WatchdogTestSuite
()
75
:
TestSuite
(
"watchdog"
,
UNIT
)
76
{
77
AddTestCase
(
new
WatchdogTestCase
(), TestCase::QUICK);
78
}
79
}
g_watchdogTestSuite
;
WatchdogTestCase::Expire
void Expire(Time expected)
Definition:
watchdog-test-suite.cc:42
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:102
ns3::Watchdog::Ping
void Ping(Time delay)
Delay the timer.
Definition:
watchdog.cc:49
WatchdogTestCase::m_expiredArgument
Time m_expiredArgument
Definition:
watchdog-test-suite.cc:33
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1333
g_watchdogTestSuite
WatchdogTestSuite g_watchdogTestSuite
WatchdogTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
watchdog-test-suite.cc:50
ns3::TestCase
encapsulates test code
Definition:
test.h:1147
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1343
ns3::Watchdog::SetFunction
void SetFunction(FN fn)
Set the function to execute when the timer expires.
Definition:
watchdog.h:199
ns3::Watchdog
A very simple watchdog operating in virtual time.
Definition:
watchdog.h:56
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition:
test.cc:297
WatchdogTestSuite
Definition:
watchdog-test-suite.cc:71
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:161
WatchdogTestCase::WatchdogTestCase
WatchdogTestCase()
Definition:
watchdog-test-suite.cc:36
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WatchdogTestSuite::WatchdogTestSuite
WatchdogTestSuite()
Definition:
watchdog-test-suite.cc:74
WatchdogTestCase::m_expiredTime
Time m_expiredTime
Definition:
watchdog-test-suite.cc:32
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:895
ns3::Watchdog::SetArguments
void SetArguments(T1 a1)
Set the arguments to be used when invoking the expire function.
Definition:
watchdog.h:214
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition:
nstime.h:911
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition:
simulator.cc:330
WatchdogTestCase::m_expired
bool m_expired
Definition:
watchdog-test-suite.cc:31
WatchdogTestCase
Definition:
watchdog-test-suite.cc:25
src
core
test
watchdog-test-suite.cc
Generated on Thu Mar 24 2016 00:46:34 for ns-3 by
1.8.9.1