@@ -145,3 +145,220 @@ TEST(TestHelpers, robotSeriesString)
145145 EXPECT_EQ (robotSeriesString (RobotSeries::UR_SERIES ), " UR_SERIES" );
146146 EXPECT_EQ (robotSeriesString (RobotSeries::UNDEFINED ), " UNDEFINED" );
147147}
148+
149+ // Thread Affinity Tests
150+
151+ TEST (TestHelpers, setThreadAffinity_basic)
152+ {
153+ pthread_t thread = pthread_self ();
154+ #ifdef _WIN32
155+ DWORD_PTR mask = (1ULL << 0 );
156+ EXPECT_TRUE (setThreadAffinity (thread, mask));
157+ #else
158+ cpu_set_t cpuset;
159+ CPU_ZERO (&cpuset);
160+ CPU_SET (0 , &cpuset);
161+ EXPECT_TRUE (setThreadAffinity (thread, cpuset));
162+ #endif
163+ }
164+
165+ TEST (TestHelpers, setThreadAffinity_mult)
166+ {
167+ pthread_t thread = pthread_self ();
168+ #ifdef _WIN32
169+ DWORD_PTR mask = (1ULL << 6 ) | (1ULL << 7 );
170+ EXPECT_TRUE (setThreadAffinity (thread, mask));
171+ #else
172+ cpu_set_t cpuset;
173+ CPU_ZERO (&cpuset);
174+ CPU_SET (6 , &cpuset);
175+ CPU_SET (7 , &cpuset);
176+ EXPECT_TRUE (setThreadAffinity (thread, cpuset));
177+ #endif
178+ }
179+
180+ TEST (TestHelpers, setThreadAffinity_invalid)
181+ {
182+ #ifdef _WIN32
183+ pthread_t thread = pthread_self ();
184+ uint64_t invalid_mask = 1ULL << 63 ;
185+ EXPECT_FALSE (setThreadAffinity (thread, invalid_mask));
186+ #else
187+ cpu_set_t cpuset;
188+ CPU_ZERO (&cpuset);
189+ CPU_SET (63 , &cpuset);
190+ EXPECT_TRUE (setThreadAffinity (thread, cpuset));
191+ #endif
192+ }
193+
194+ TEST (TestHelpers, setThreadAffinity_invalidHandle)
195+ {
196+ #ifdef _WIN32
197+ pthread_t thread = nullptr ;
198+ EXPECT_FALSE (setThreadAffinity (thread, (1ULL << 0 )));
199+ #else
200+ pthread_t thread{};
201+ cpu_set_t cpuset;
202+ CPU_ZERO (&cpuset);
203+ CPU_SET (0 , &cpuset);
204+ EXPECT_FALSE (setThreadAffinity (thread, cpuset));
205+ #endif
206+ }
207+
208+ TEST (TestHelpers, setThreadAffinity_empty)
209+ {
210+ #ifdef _WIN32
211+ pthread_t thread = pthread_self ();
212+ EXPECT_FALSE (setThreadAffinity (thread, 0 ));
213+ #else
214+ pthread_t thread = pthread_self ();
215+ cpu_set_t cpuset;
216+ CPU_ZERO (&cpuset);
217+ EXPECT_FALSE (setThreadAffinity (thread, cpuset));
218+ #endif
219+
220+ }
221+
222+ // Thread Priority Tests
223+
224+ TEST (TestHelpers, setThreadPriority_allValidPriorities)
225+ {
226+ #ifdef _WIN32
227+ pthread_t thread = pthread_self ();
228+
229+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_LOWEST ));
230+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_BELOW_NORMAL ));
231+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_NORMAL ));
232+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_ABOVE_NORMAL ));
233+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_HIGHEST ));
234+ EXPECT_TRUE (setThreadPriority (thread, THREAD_PRIORITY_TIME_CRITICAL ));
235+ #endif
236+ }
237+
238+ TEST (TestHelpers, setThreadPriority_invalid)
239+ {
240+ #ifdef _WIN32
241+ pthread_t thread = pthread_self ();
242+ EXPECT_FALSE (setThreadPriority (thread, 999999 ));
243+ #endif
244+ }
245+
246+ TEST (TestHelpers, setThreadPriority_invalidHandle)
247+ {
248+ #ifdef _WIN32
249+ pthread_t thread = nullptr ;
250+ EXPECT_FALSE (setThreadPriority (thread, THREAD_PRIORITY_HIGHEST ));
251+ #endif
252+ }
253+
254+ // Process Priority tests
255+
256+ TEST (TestHelpers, setProcessPriority_allValidPriorities)
257+ {
258+ #ifdef _WIN32
259+ pprocess_t process = pprocess_self ();
260+
261+ EXPECT_TRUE (setProcessPriority (process, IDLE_PRIORITY_CLASS ));
262+ EXPECT_TRUE (setProcessPriority (process, BELOW_NORMAL_PRIORITY_CLASS ));
263+ EXPECT_TRUE (setProcessPriority (process, NORMAL_PRIORITY_CLASS ));
264+ EXPECT_TRUE (setProcessPriority (process, ABOVE_NORMAL_PRIORITY_CLASS ));
265+ EXPECT_TRUE (setProcessPriority (process, HIGH_PRIORITY_CLASS ));
266+ #endif
267+ }
268+
269+ TEST (TestHelpers, setProcessPriority_invalid)
270+ {
271+ #ifdef _WIN32
272+ pprocess_t process = pprocess_self ();
273+ EXPECT_FALSE (setProcessPriority (process, 999999 ));
274+ #endif
275+ }
276+
277+ TEST (TestHelpers, setProcessPriority_invalidHandle)
278+ {
279+ #ifdef _WIN32
280+ pprocess_t process = nullptr ;
281+ EXPECT_FALSE (setProcessPriority (process, NORMAL_PRIORITY_CLASS ));
282+ #endif
283+ }
284+
285+ // Process Affinity Tests
286+
287+ TEST (TestHelpers, setProcessAffinity_basic)
288+ {
289+ #ifdef _WIN32
290+ pprocess_t process = pprocess_self ();
291+ DWORD_PTR mask = (1ULL << 0 );
292+ EXPECT_TRUE (setProcessAffinity (process, mask));
293+ #endif
294+ }
295+
296+ TEST (TestHelpers, setProcessAffinity_multi)
297+ {
298+ #ifdef _WIN32
299+ pprocess_t process = pprocess_self ();
300+ DWORD_PTR mask = (1ULL << 0 ) | (1ULL << 1 );
301+ EXPECT_TRUE (setProcessAffinity (process, mask));
302+ #endif
303+ }
304+
305+ TEST (TestHelpers, setProcessAffinity_invalidHandle)
306+ {
307+ #ifdef _WIN32
308+ pprocess_t process = nullptr ;
309+ EXPECT_FALSE (setProcessAffinity (process, (1ULL << 0 )));
310+ #endif
311+ }
312+
313+ TEST (TestHelpers, setProcessAffinity_zeroMask)
314+ {
315+ #ifdef _WIN32
316+ pprocess_t process = pprocess_self ();
317+ EXPECT_FALSE (setProcessAffinity (process,0 ));
318+ #endif
319+ }
320+
321+ TEST (TestHelpers, setProcessAffinity_invalidMask)
322+ {
323+ #ifdef _WIN32
324+ pprocess_t process = pprocess_self ();
325+ DWORD_PTR mask = 0xFFFFFFFFFFFFFFFFULL ;
326+ EXPECT_FALSE (setProcessAffinity (process, mask));
327+ #endif
328+ }
329+
330+ // FIFO Scheduling Tests
331+
332+ TEST (TestHelpers, setFiFoScheduling_normal)
333+ {
334+ pthread_t thread = pthread_self ();
335+ #ifdef _WIN32
336+ EXPECT_TRUE (setFiFoScheduling (thread, THREAD_PRIORITY_NORMAL ));
337+ #else
338+ EXPECT_TRUE (setFiFoScheduling (thread, 50 ));
339+ #endif
340+ }
341+
342+ TEST (TestHelpers, setFiFoScheduling_invalidPriority)
343+ {
344+ pthread_t thread = pthread_self ();
345+ EXPECT_FALSE (setFiFoScheduling (thread, 999 ));
346+ }
347+
348+ TEST (TestHelpers, setFiFoScheduling_invalidHandle)
349+ {
350+ #ifdef _WIN32
351+ pthread_t thread = nullptr ;
352+ EXPECT_FALSE (setFiFoScheduling (thread, THREAD_PRIORITY_NORMAL ));
353+ #else
354+ pthread_t thread{};
355+ EXPECT_FALSE (setFiFoScheduling (thread, 50 ));
356+ #endif
357+ }
358+
359+ TEST (TestHelpers, setFiFoScheduling_maxPriority)
360+ {
361+ pthread_t thread = pthread_self ();
362+ int max_prio = sched_get_priority_max (SCHED_FIFO );
363+ EXPECT_TRUE (setFiFoScheduling (thread, max_prio));
364+ }
0 commit comments