diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d67c574..a3b78b2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,6 +16,8 @@ if(DEFINED TARGET_LIKE_X86_WINDOWS_NATIVE OR DEFINED TARGET_LIKE_X86_LINUX_NATIV endif() if(DEFINED TARGET_LIKE_X86_LINUX_NATIVE) SET(TEST_EXECUTABLE "../../../build/x86-linux-native/test/mbed_trace_test") + find_package (Threads) + target_link_libraries (mbed_trace_test ${CMAKE_THREAD_LIBS_INIT}) add_test(mbed_trace_test ${TEST_EXECUTABLE}) add_dependencies(all_tests mbed_trace_test) endif() diff --git a/test/Test.cpp b/test/Test.cpp index 52b5934..9f24efa 100644 --- a/test/Test.cpp +++ b/test/Test.cpp @@ -9,6 +9,8 @@ #include #include #include +#include /* pthread_create() */ +#include /* usleep() */ #include "mbed-cpputest/CppUTest/TestHarness.h" #include "mbed-cpputest/CppUTest/SimpleString.h" @@ -474,3 +476,34 @@ TEST(trace, uninitialized) STRCMP_EQUAL("hello", buf); } +void* multithread_printer(void *ti) +{ + volatile int thread_index = *(int *)ti; + for(int i=0; i<10; i++) { + //printf("thread index = %d, round %d\n", thread_index, i); + mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "thread index = %d, round %d", thread_index, i); + usleep(1000 * (1 + thread_index)); /* (1 + thread_index) ms delay */ + } + return NULL; +} + +TEST(trace, multithread) +{ + const int thread_amount = 10; + pthread_t threads[thread_amount]; + int thread_indexes[thread_amount]; + int i, j; + + for(j=0; j<10; j++) + { + for(i=0; i