21 #include "ns3/simulator.h"
22 #include "ns3/list-scheduler.h"
23 #include "ns3/heap-scheduler.h"
24 #include "ns3/map-scheduler.h"
25 #include "ns3/calendar-scheduler.h"
33 virtual void DoRun (
void);
39 uint64_t NowUs (
void);
51 SimulatorEventsTestCase::SimulatorEventsTestCase (
ObjectFactory schedulerFactory)
52 :
TestCase (
"Check that basic event handling is working with " +
53 schedulerFactory.GetTypeId ().GetName ()),
54 m_schedulerFactory (schedulerFactory)
58 SimulatorEventsTestCase::NowUs (
void)
65 SimulatorEventsTestCase::A (
int a)
71 SimulatorEventsTestCase::B (
int b)
73 if (b != 2 || NowUs () != 11)
81 Simulator::Remove (m_idC);
82 Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D,
this, 4);
86 SimulatorEventsTestCase::C (
int c)
92 SimulatorEventsTestCase::D (
int d)
94 if (d != 4 || NowUs () != (11+10))
105 SimulatorEventsTestCase::foo0 (
void)
109 SimulatorEventsTestCase::destroy (
void)
124 Simulator::SetScheduler (m_schedulerFactory);
127 Simulator::Schedule (
MicroSeconds (11), &SimulatorEventsTestCase::B,
this, 2);
128 m_idC = Simulator::Schedule (
MicroSeconds (12), &SimulatorEventsTestCase::C,
this, 3);
130 NS_TEST_EXPECT_MSG_EQ (!m_idC.
IsExpired (),
true,
"");
131 NS_TEST_EXPECT_MSG_EQ (!a.
IsExpired (),
true,
"");
132 Simulator::Cancel (a);
133 NS_TEST_EXPECT_MSG_EQ (a.
IsExpired (),
true,
"");
135 NS_TEST_EXPECT_MSG_EQ (m_a,
true,
"Event A did not run ?");
136 NS_TEST_EXPECT_MSG_EQ (m_b,
true,
"Event B did not run ?");
137 NS_TEST_EXPECT_MSG_EQ (m_c,
true,
"Event C did not run ?");
138 NS_TEST_EXPECT_MSG_EQ (m_d,
true,
"Event D did not run ?");
140 EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::foo0,
this);
142 NS_TEST_EXPECT_MSG_EQ (!(anId.
IsExpired () || anotherId.
IsExpired ()),
true,
"Event should not have expired yet.");
144 Simulator::Remove (anId);
145 NS_TEST_EXPECT_MSG_EQ (anId.
IsExpired (),
true,
"Event was removed: it is now expired");
146 NS_TEST_EXPECT_MSG_EQ (anotherId.
IsExpired (),
true,
"Event was removed: it is now expired");
149 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy,
this);
150 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.
IsExpired (),
true,
"Event should not have expired yet");
152 NS_TEST_EXPECT_MSG_EQ (m_destroyId.
IsExpired (),
true,
"Event was canceled: should have expired now");
154 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy,
this);
155 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (),
true,
"Event should not have expired yet");
156 Simulator::Remove (m_destroyId);
157 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (),
true,
"Event was canceled: should have expired now");
159 m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy,
this);
160 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (),
true,
"Event should not have expired yet");
163 NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (),
true,
"Event should not have expired yet");
164 NS_TEST_EXPECT_MSG_EQ (!m_destroy,
true,
"Event should not have run");
166 Simulator::Destroy ();
167 NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (),
true,
"Event should have expired now");
168 NS_TEST_EXPECT_MSG_EQ (m_destroy,
true,
"Event should have run");
176 void Ref (
void)
const {}
177 void Unref (
void)
const {}
179 virtual void DoRun (
void);
183 void bar2 (
int,
int) {}
184 void bar3 (
int,
int,
int) {}
185 void bar4 (
int,
int,
int,
int) {}
186 void bar5 (
int,
int,
int,
int,
int) {}
188 void baz2 (
int &,
int &) {}
189 void baz3 (
int &,
int &,
int &) {}
190 void baz4 (
int &,
int &,
int &,
int &) {}
191 void baz5 (
int &,
int &,
int &,
int &,
int &) {}
192 void cbaz1 (
const int &) {}
193 void cbaz2 (
const int &,
const int &) {}
194 void cbaz3 (
const int &,
const int &,
const int &) {}
195 void cbaz4 (
const int &,
const int &,
const int &,
const int &) {}
196 void cbaz5 (
const int &,
const int &,
const int &,
const int &,
const int &) {}
198 void bar0c (
void)
const {}
199 void bar1c (
int)
const {}
200 void bar2c (
int,
int)
const {}
201 void bar3c (
int,
int,
int)
const {}
202 void bar4c (
int,
int,
int,
int)
const {}
203 void bar5c (
int,
int,
int,
int,
int)
const {}
204 void baz1c (
int &)
const {}
205 void baz2c (
int &,
int &)
const {}
206 void baz3c (
int &,
int &,
int &)
const {}
207 void baz4c (
int &,
int &,
int &,
int &)
const {}
208 void baz5c (
int &,
int &,
int &,
int &,
int &)
const {}
209 void cbaz1c (
const int &)
const {}
210 void cbaz2c (
const int &,
const int &)
const {}
211 void cbaz3c (
const int &,
const int &,
const int &)
const {}
212 void cbaz4c (
const int &,
const int &,
const int &,
const int &)
const {}
213 void cbaz5c (
const int &,
const int &,
const int &,
const int &,
const int &)
const {}
217 static void foo0 (
void)
219 static void foo1 (
int)
221 static void foo2 (
int,
int)
223 static void foo3 (
int,
int,
int)
225 static void foo4 (
int,
int,
int,
int)
227 static void foo5 (
int,
int,
int,
int,
int)
229 static void ber1 (
int &)
231 static void ber2 (
int &,
int &)
233 static void ber3 (
int &,
int &,
int &)
235 static void ber4 (
int &,
int &,
int &,
int &)
237 static void ber5 (
int &,
int &,
int &,
int &,
int &)
239 static void cber1 (
const int &)
241 static void cber2 (
const int &,
const int &)
243 static void cber3 (
const int &,
const int &,
const int &)
245 static void cber4 (
const int &,
const int &,
const int &,
const int &)
247 static void cber5 (
const int &,
const int &,
const int &,
const int &,
const int &)
250 SimulatorTemplateTestCase::SimulatorTemplateTestCase ()
251 :
TestCase (
"Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.")
258 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar0c,
this);
259 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar1c,
this, 0);
260 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar2c,
this, 0, 0);
261 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar3c,
this, 0, 0, 0);
262 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar4c,
this, 0, 0, 0, 0);
263 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar5c,
this, 0, 0, 0, 0, 0);
264 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c,
this, 0);
265 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c,
this, 0, 0);
266 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c,
this, 0, 0, 0);
267 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c,
this, 0, 0, 0, 0);
268 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c,
this, 0, 0, 0, 0, 0);
269 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c,
this);
270 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c,
this, 0);
271 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c,
this, 0, 0);
272 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c,
this, 0, 0, 0);
273 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c,
this, 0, 0, 0, 0);
274 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c,
this, 0, 0, 0, 0, 0);
275 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c,
this, 0);
276 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c,
this, 0, 0);
277 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c,
this, 0, 0, 0);
278 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c,
this, 0, 0, 0, 0);
279 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c,
this, 0, 0, 0, 0, 0);
280 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c,
this);
281 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c,
this, 0);
282 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c,
this, 0, 0);
283 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c,
this, 0, 0, 0);
284 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c,
this, 0, 0, 0, 0);
285 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c,
this, 0, 0, 0, 0, 0);
286 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c,
this, 0);
287 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c,
this, 0, 0);
288 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c,
this, 0, 0, 0);
289 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c,
this, 0, 0, 0, 0);
290 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c,
this, 0, 0, 0, 0, 0);
291 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz1c,
this, 0);
292 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz2c,
this, 0, 0);
293 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz3c,
this, 0, 0, 0);
294 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz4c,
this, 0, 0, 0, 0);
295 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz5c,
this, 0, 0, 0, 0, 0);
296 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c,
this, 0);
297 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c,
this, 0, 0);
298 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c,
this, 0, 0, 0);
299 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c,
this, 0, 0, 0, 0);
300 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c,
this, 0, 0, 0, 0, 0);
301 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c,
this, 0);
302 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c,
this, 0, 0);
303 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c,
this, 0, 0, 0);
304 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c,
this, 0, 0, 0, 0);
305 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c,
this, 0, 0, 0, 0, 0);
329 Simulator::Schedule (
Seconds (0.0), &foo0);
330 Simulator::Schedule (
Seconds (0.0), &foo1, 0);
331 Simulator::Schedule (
Seconds (0.0), &foo2, 0, 0);
332 Simulator::Schedule (
Seconds (0.0), &foo3, 0, 0, 0);
333 Simulator::Schedule (
Seconds (0.0), &foo4, 0, 0, 0, 0);
334 Simulator::Schedule (
Seconds (0.0), &foo5, 0, 0, 0, 0, 0);
335 Simulator::Schedule (
Seconds (0.0), &cber1, 0);
336 Simulator::Schedule (
Seconds (0.0), &cber2, 0, 0);
337 Simulator::Schedule (
Seconds (0.0), &cber3, 0, 0, 0);
338 Simulator::Schedule (
Seconds (0.0), &cber4, 0, 0, 0, 0);
339 Simulator::Schedule (
Seconds (0.0), &cber5, 0, 0, 0, 0, 0);
340 Simulator::ScheduleNow (&foo0);
341 Simulator::ScheduleNow (&foo1, 0);
342 Simulator::ScheduleNow (&foo2, 0, 0);
343 Simulator::ScheduleNow (&foo3, 0, 0, 0);
344 Simulator::ScheduleNow (&foo4, 0, 0, 0, 0);
345 Simulator::ScheduleNow (&foo5, 0, 0, 0, 0, 0);
346 Simulator::ScheduleNow (&cber1, 0);
347 Simulator::ScheduleNow (&cber2, 0, 0);
348 Simulator::ScheduleNow (&cber3, 0, 0, 0);
349 Simulator::ScheduleNow (&cber4, 0, 0, 0, 0);
350 Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0);
351 Simulator::ScheduleDestroy (&foo0);
352 Simulator::ScheduleDestroy (&foo1, 0);
353 Simulator::ScheduleDestroy (&foo2, 0, 0);
354 Simulator::ScheduleDestroy (&foo3, 0, 0, 0);
355 Simulator::ScheduleDestroy (&foo4, 0, 0, 0, 0);
356 Simulator::ScheduleDestroy (&foo5, 0, 0, 0, 0, 0);
357 Simulator::ScheduleDestroy (&cber1, 0);
358 Simulator::ScheduleDestroy (&cber2, 0, 0);
359 Simulator::ScheduleDestroy (&cber3, 0, 0, 0);
360 Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0);
361 Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0);
365 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar0,
this);
366 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar1,
this, 0);
367 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar2,
this, 0, 0);
368 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar3,
this, 0, 0, 0);
369 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar4,
this, 0, 0, 0, 0);
370 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::bar5,
this, 0, 0, 0, 0, 0);
371 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz1,
this, 0);
372 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz2,
this, 0, 0);
373 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz3,
this, 0, 0, 0);
374 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz4,
this, 0, 0, 0, 0);
375 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::cbaz5,
this, 0, 0, 0, 0, 0);
376 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0,
this);
377 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1,
this, 0);
378 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2,
this, 0, 0);
379 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3,
this, 0, 0, 0);
380 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4,
this, 0, 0, 0, 0);
381 Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5,
this, 0, 0, 0, 0, 0);
382 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1,
this, 0);
383 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2,
this, 0, 0);
384 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3,
this, 0, 0, 0);
385 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4,
this, 0, 0, 0, 0);
386 Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5,
this, 0, 0, 0, 0, 0);
387 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0,
this);
388 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1,
this, 0);
389 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2,
this, 0, 0);
390 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3,
this, 0, 0, 0);
391 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4,
this, 0, 0, 0, 0);
392 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5,
this, 0, 0, 0, 0, 0);
393 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1,
this, 0);
394 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2,
this, 0, 0);
395 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3,
this, 0, 0, 0);
396 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4,
this, 0, 0, 0, 0);
397 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5,
this, 0, 0, 0, 0, 0);
426 Simulator::Schedule (
Seconds (0.0), &ber1, 0);
427 Simulator::Schedule (
Seconds (0.0), &ber2, 0, 0);
428 Simulator::Schedule (
Seconds (0.0), &ber3, 0, 0, 0);
429 Simulator::Schedule (
Seconds (0.0), &ber4, 0, 0, 0, 0);
430 Simulator::Schedule (
Seconds (0.0), &ber5, 0, 0, 0, 0, 0);
431 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz1,
this, 0);
432 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz2,
this, 0, 0);
433 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz3,
this, 0, 0, 0);
434 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz4,
this, 0, 0, 0, 0);
435 Simulator::Schedule (
Seconds (0.0), &SimulatorTemplateTestCase::baz5,
this, 0, 0, 0, 0, 0);
436 Simulator::ScheduleNow (&ber1, 0);
437 Simulator::ScheduleNow (&ber2, 0, 0);
438 Simulator::ScheduleNow (&ber3, 0, 0, 0);
439 Simulator::ScheduleNow (&ber4, 0, 0, 0, 0);
440 Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0);
441 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1,
this, 0);
442 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2,
this, 0, 0);
443 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3,
this, 0, 0, 0);
444 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4,
this, 0, 0, 0, 0);
445 Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5,
this, 0, 0, 0, 0, 0);
446 Simulator::ScheduleDestroy (&ber1, 0);
447 Simulator::ScheduleDestroy (&ber2, 0, 0);
448 Simulator::ScheduleDestroy (&ber3, 0, 0, 0);
449 Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0);
450 Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0);
451 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1,
this, 0);
452 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2,
this, 0, 0);
453 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3,
this, 0, 0, 0);
454 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4,
this, 0, 0, 0, 0);
455 Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5,
this, 0, 0, 0, 0, 0);
459 Simulator::Destroy ();
469 factory.
SetTypeId (ListScheduler::GetTypeId ());
472 factory.
SetTypeId (MapScheduler::GetTypeId ());
474 factory.
SetTypeId (HeapScheduler::GetTypeId ());
476 factory.
SetTypeId (CalendarScheduler::GetTypeId ());
479 } g_simulatorTestSuite;
smart pointer class similar to boost::intrusive_ptr
void SetTypeId(TypeId tid)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
virtual void DoRun(void)
Implementation to actually run this test case.
int64_t GetNanoSeconds(void) const
instantiate subclasses of ns3::Object.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
an identifier for simulation events.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
bool IsExpired(void) const
Time MicroSeconds(uint64_t us)
create ns3::Time instances in units of microseconds.