8#include "ns3/calendar-scheduler.h"
10#include "ns3/heap-scheduler.h"
11#include "ns3/list-scheduler.h"
12#include "ns3/map-scheduler.h"
13#include "ns3/simulator.h"
14#include "ns3/string.h"
56 const std::string& simulatorType,
57 unsigned int threads);
87 static void SchedulingThread(std::pair<ThreadedSimulatorEventsTestCase*, unsigned int> context);
106 void DoRun()
override;
111 const std::string& simulatorType,
112 unsigned int threads)
113 :
TestCase(
"Check threaded event handling with " +
std::to_string(threads) +
" threads, " +
114 schedulerFactory.GetTypeId().GetName() +
" scheduler, in " + simulatorType),
116 m_schedulerFactory(schedulerFactory),
117 m_simulatorType(simulatorType)
127 if (thread.joinable())
136 std::pair<ThreadedSimulatorEventsTestCase*, unsigned int> context)
139 unsigned int threadno = context.second;
151 std::this_thread::sleep_for(std::chrono::nanoseconds(500));
161 m_error =
"Bad threaded scheduling";
254 for (
unsigned int i = 0; i <
m_threads; ++i)
258 std::pair<ThreadedSimulatorEventsTestCase*, unsigned int>(
this, i));
281 std::string simulatorTypes[] = {
282 "ns3::RealtimeSimulatorImpl",
283 "ns3::DefaultSimulatorImpl",
285 std::string schedulerTypes[] = {
286 "ns3::ListScheduler",
287 "ns3::HeapScheduler",
289 "ns3::CalendarScheduler",
291 unsigned int threadCounts[] = {0, 2, 10, 20};
294 for (
auto& simulatorType : simulatorTypes)
296 for (
auto& schedulerType : schedulerTypes)
298 for (
auto& threadCount : threadCounts)
303 TestCase::Duration::QUICK);
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.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
static void Run()
Run the simulation.
static void SetScheduler(ObjectFactory schedulerFactory)
Set the scheduler type with an ObjectFactory.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=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.
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.