Skip to content

Commit 88bdc01

Browse files
Fix equeue test failure, add test for pthread_setname_np
1 parent 1cc4eba commit 88bdc01

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

RTXOff/CMakeLists.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,31 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
7070
else()
7171
target_compile_definitions(rtxoff PUBLIC USE_WINTHREAD=0 _GNU_SOURCE=1)
7272

73-
# check if the nonstandard pthread_setname_np() function exists
73+
# check for a thread yield function
7474
set(CMAKE_REQUIRED_LIBRARIES Threads::Threads)
75-
check_all_functions(pthread_setname_np pthread_yield sched_yield)
76-
77-
if(HAVE_PTHREAD_SETNAME_NP)
78-
target_compile_definitions(rtxoff PRIVATE HAVE_PTHREAD_SETNAME_NP)
79-
endif()
75+
check_all_functions(pthread_yield sched_yield)
8076

8177
if(NOT (HAVE_PTHREAD_YIELD OR HAVE_SCHED_YIELD))
8278
message(FATAL_ERROR "Your system does not provide pthread_yield() or sched_yield(). RTXOff cannot build.")
8379
endif()
8480
if(HAVE_PTHREAD_YIELD)
8581
target_compile_definitions(rtxoff PRIVATE HAVE_PTHREAD_YIELD)
8682
endif()
83+
84+
# Check for a linux API pthread_setname_np (as opposed to the Mac version that works differently).
85+
# The situation is summarized here: https://stackoverflow.com/questions/2369738/how-to-set-the-name-of-a-thread-in-linux-pthreads/7989973#7989973
86+
include(CheckCSourceCompiles)
87+
check_c_source_compiles(
88+
"#include <pthread.h>
89+
int main(int argc, char** argv)
90+
{
91+
pthread_setname_np(pthread_self(), \"TestThread\");
92+
}"
93+
PTHREAD_SETNAME_NP_WORKS)
94+
95+
if(PTHREAD_SETNAME_NP_WORKS)
96+
target_compile_definitions(rtxoff PRIVATE HAVE_PTHREAD_SETNAME_NP)
97+
endif()
8798
endif()
8899

89100
# manually apply mbed configs

tests/events/queue/main.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ void time_left_test()
302302
EventQueue queue(TEST_EQUEUE_SIZE);
303303

304304
// Enque check events
305-
TEST_ASSERT(queue.call_in(50ms, check_time_left, &queue, 0, 100 - 50));
306-
TEST_ASSERT(queue.call_in(200ms, check_time_left, &queue, 1, 200 - 200));
305+
TEST_ASSERT(queue.call_in(500ms, check_time_left, &queue, 0, 100 - 500));
306+
TEST_ASSERT(queue.call_in(2000ms, check_time_left, &queue, 1, 200 - 2000));
307307

308308
// Enque events to be checked
309-
timeleft_events[0] = queue.call_in(100ms, time_left, &queue, 0);
310-
timeleft_events[1] = queue.call_in(200ms, time_left, &queue, 1);
309+
timeleft_events[0] = queue.call_in(1000ms, time_left, &queue, 0);
310+
timeleft_events[1] = queue.call_in(2000ms, time_left, &queue, 1);
311311
TEST_ASSERT(timeleft_events[0]);
312312
TEST_ASSERT(timeleft_events[1]);
313313

@@ -500,6 +500,13 @@ void static_events_queue_test()
500500
TEST_ASSERT_EQUAL(6, test2.counter);
501501
TEST_ASSERT_EQUAL(30, test3.counter);
502502
TEST_ASSERT_EQUAL(15, test4.counter);
503+
504+
// cancel all events to prevent assertion failure when program shuts down
505+
ue0.cancel();
506+
ue1.cancel();
507+
ue2.cancel();
508+
ue3.cancel();
509+
ue4.cancel();
503510
}
504511

505512
// Test setup

0 commit comments

Comments
 (0)