MCPcopy Create free account
hub / github.com/DISTORTEC/distortos / run_

Method run_

test/Thread/ThreadSleepForTestCase.cpp:102–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100+---------------------------------------------------------------------------------------------------------------------*/
101
102bool ThreadSleepForTestCase::run_() const
103{
104 const auto allocatedMemory = mallinfo().uordblks;
105
106 for (const auto& phase : priorityTestPhases)
107 {
108 {
109 SequenceAsserter sequenceAsserter;
110 std::array<TickClock::duration, totalThreads> durationDeviations {{}};
111 std::array<int, totalThreads> sharedRets {{}};
112 TickClock::time_point sleepStart;
113
114 std::array<DynamicThread, totalThreads> threads
115 {{
116 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[0]], sequenceAsserter, sleepStart,
117 durationDeviations[0], sharedRets[0]),
118 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[1]], sequenceAsserter, sleepStart,
119 durationDeviations[1], sharedRets[1]),
120 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[2]], sequenceAsserter, sleepStart,
121 durationDeviations[2], sharedRets[2]),
122 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[3]], sequenceAsserter, sleepStart,
123 durationDeviations[3], sharedRets[3]),
124 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[4]], sequenceAsserter, sleepStart,
125 durationDeviations[4], sharedRets[4]),
126 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[5]], sequenceAsserter, sleepStart,
127 durationDeviations[5], sharedRets[5]),
128 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[6]], sequenceAsserter, sleepStart,
129 durationDeviations[6], sharedRets[6]),
130 makeTestThread(testCasePriority_ - 1, phase.first[phase.second[7]], sequenceAsserter, sleepStart,
131 durationDeviations[7], sharedRets[7]),
132 }};
133
134 ThisThread::setPriority(testCasePriority_);
135
136 for (auto& thread : threads)
137 thread.start();
138
139 // wait for beginning of next tick - test threads should be started in the same tick
140 wasteTime(TickClock::duration{});
141 sleepStart = TickClock::now();
142
143 ThisThread::setPriority(testCasePriority_ - 2);
144
145 bool invalidState {};
146 for (const auto& thread : threads)
147 if (thread.getState() != ThreadState::sleeping)
148 invalidState = true;
149
150 for (auto& thread : threads)
151 thread.join();
152
153 if (invalidState != false)
154 return false;
155
156 if (sequenceAsserter.assertSequence(totalThreads) == false)
157 return false;
158
159 // sleepFor() always sleeps one tick longer

Callers

nothing calls this directly

Calls 7

setPriorityFunction · 0.85
assertSequenceMethod · 0.80
makeTestThreadFunction · 0.70
wasteTimeFunction · 0.50
startMethod · 0.45
getStateMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected