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"
91 void DoNothing (
unsigned int threadno);
96 static void SchedulingThread (std::pair<ThreadedSimulatorEventsTestCase *, unsigned int> context);
114 virtual void DoSetup (
void);
115 virtual void DoRun (
void);
116 virtual void DoTeardown (
void);
120 :
TestCase (
"Check threaded event handling with " +
121 std::
to_string (threads) +
" threads, " +
122 schedulerFactory.GetTypeId ().GetName () +
" scheduler, in " +
125 m_schedulerFactory (schedulerFactory),
126 m_simulatorType (simulatorType)
135 if (thread.joinable ())
145 unsigned int threadno = context.second;
150 Simulator::ScheduleWithContext (threadno,
155 std::this_thread::sleep_for (std::chrono::nanoseconds (500));
164 m_error =
"Bad threaded scheduling";
258 for (
unsigned int i = 0; i <
m_threads; ++i)
262 std::pair<ThreadedSimulatorEventsTestCase *, unsigned int> (
this,i) ));
266 Simulator::Destroy ();
285 std::string simulatorTypes[] = {
287 "ns3::RealtimeSimulatorImpl",
289 "ns3::DefaultSimulatorImpl"
291 std::string schedulerTypes[] = {
292 "ns3::ListScheduler",
293 "ns3::HeapScheduler",
295 "ns3::CalendarScheduler"
297 unsigned int threadcounts[] = {
305 for (
unsigned int i = 0; i < (
sizeof(simulatorTypes) /
sizeof(simulatorTypes[0])); ++i)
307 for (
unsigned int j = 0; j < (
sizeof(threadcounts) /
sizeof(threadcounts[0])); ++j)
309 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.
std::list< std::thread > m_threadlist
Thread list.
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.
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.
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)
#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.
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr int MAXTHREADS
Maximum number of threads.
static ThreadedSimulatorTestSuite g_threadedSimulatorTestSuite
Static variable for test initialization.