19 #include "ns3/calendar-scheduler.h"
20 #include "ns3/config.h"
21 #include "ns3/heap-scheduler.h"
22 #include "ns3/list-scheduler.h"
23 #include "ns3/map-scheduler.h"
24 #include "ns3/simulator.h"
25 #include "ns3/string.h"
67 const std::string& simulatorType,
68 unsigned int threads);
93 void DoNothing(
unsigned int threadno);
98 static void SchedulingThread(std::pair<ThreadedSimulatorEventsTestCase*, unsigned int> context);
116 void DoSetup()
override;
117 void DoRun()
override;
118 void DoTeardown()
override;
122 const std::string& simulatorType,
123 unsigned int threads)
124 :
TestCase(
"Check threaded event handling with " + std::
to_string(threads) +
" threads, " +
125 schedulerFactory.GetTypeId().GetName() +
" scheduler, in " + simulatorType),
127 m_schedulerFactory(schedulerFactory),
128 m_simulatorType(simulatorType)
138 if (thread.joinable())
147 std::pair<ThreadedSimulatorEventsTestCase*, unsigned int> context)
150 unsigned int threadno = context.second;
155 Simulator::ScheduleWithContext(threadno,
162 std::this_thread::sleep_for(std::chrono::nanoseconds(500));
172 m_error =
"Bad threaded scheduling";
265 for (
unsigned int i = 0; i <
m_threads; ++i)
269 std::pair<ThreadedSimulatorEventsTestCase*, unsigned int>(
this, i));
273 Simulator::Destroy();
292 std::string simulatorTypes[] = {
293 "ns3::RealtimeSimulatorImpl",
294 "ns3::DefaultSimulatorImpl",
296 std::string schedulerTypes[] = {
297 "ns3::ListScheduler",
298 "ns3::HeapScheduler",
300 "ns3::CalendarScheduler",
302 unsigned int threadCounts[] = {0, 2, 10, 20};
305 for (
auto& simulatorType : simulatorTypes)
307 for (
auto& schedulerType : schedulerTypes)
309 for (
auto& threadCount : threadCounts)
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.
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 DoTeardown() override
Implementation to do any local setup required for this TestCase.
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.
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.
void End()
End the thread execution.
void DoRun() override
Implementation to actually run this TestCase.
unsigned int m_threads
The number of threads.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
uint64_t m_a
The value incremented when EventA is called.
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.