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"
26#include "ns3/config.h"
27#include "ns3/string.h"
28#include "ns3/system-thread.h"
97 static void SchedulingThread (std::pair<ThreadedSimulatorEventsTestCase *, unsigned int> context);
116 virtual void DoRun (
void);
121 :
TestCase (
"Check threaded event handling with " +
122 std::to_string (threads) +
" threads, " +
123 schedulerFactory.GetTypeId ().GetName () +
" scheduler, in " +
126 m_schedulerFactory (schedulerFactory),
127 m_simulatorType (simulatorType)
143 unsigned int threadno = context.second;
148 Simulator::ScheduleWithContext (threadno,
153 std::this_thread::sleep_for (std::chrono::nanoseconds (500));
162 m_error =
"Bad threaded scheduling";
240 for (
unsigned int i = 0; i <
m_threads; ++i)
245 std::pair<ThreadedSimulatorEventsTestCase *, unsigned int> (
this,i) )) );
271 Simulator::Destroy ();
290 std::string simulatorTypes[] = {
292 "ns3::RealtimeSimulatorImpl",
294 "ns3::DefaultSimulatorImpl"
296 std::string schedulerTypes[] = {
297 "ns3::ListScheduler",
298 "ns3::HeapScheduler",
300 "ns3::CalendarScheduler"
302 unsigned int threadcounts[] = {
310 for (
unsigned int i = 0; i < (
sizeof(simulatorTypes) /
sizeof(simulatorTypes[0])); ++i)
312 for (
unsigned int j = 0; j < (
sizeof(threadcounts) /
sizeof(threadcounts[0])); ++j)
314 for (
unsigned int k = 0;
k < (
sizeof(schedulerTypes) /
sizeof(schedulerTypes[0])); ++
k)
Check threaded event handling with various thread number, schedulers, and simulator types.
void EventB(int b)
Event B.
static void SchedulingThread(std::pair< ThreadedSimulatorEventsTestCase *, unsigned int > context)
Schedule a thread.
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
bool m_stop
Stop variable.
void EventA(int a)
Event A.
ThreadedSimulatorEventsTestCase(ObjectFactory schedulerFactory, const std::string &simulatorType, unsigned int threads)
Constructor.
ObjectFactory m_schedulerFactory
Scheduler factory.
void End(void)
End the thread execution.
bool m_threadWaiting[MAXTHREADS]
Threads waiting to be scheduled.
std::string m_error
Error condition.
uint64_t m_c
The value incremented when EventC is called.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void EventD(int d)
Event D.
uint64_t m_b
The value incremented when EventB is called.
void EventC(int c)
Event C.
std::string m_simulatorType
Simulator type.
uint64_t m_d
The value incremented when EventD is called.
std::list< Ptr< SystemThread > > m_threadlist
Thread list.
unsigned int m_threads
The number of threads.
uint64_t m_a
The value incremented when EventA is called.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
void DoNothing(unsigned int threadno)
No-op function, records the thread that called it.
The threaded simulator Test Suite.
ThreadedSimulatorTestSuite()
Instantiate subclasses of ns3::Object.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
void SetGlobal(std::string name, const AttributeValue &value)
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define MAXTHREADS
Maximum number of threads.
static ThreadedSimulatorTestSuite g_threadedSimulatorTestSuite
Static variable for test initialization.