Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
33 changes: 33 additions & 0 deletions test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h> /* pthread_create() */
#include <unistd.h> /* usleep() */

#include "mbed-cpputest/CppUTest/TestHarness.h"
#include "mbed-cpputest/CppUTest/SimpleString.h"
Expand Down Expand Up @@ -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<thread_amount; i++) {
//printf("creating %d\n", i);
thread_indexes[i] = i;
pthread_create(&threads[i], NULL, &multithread_printer, (void *)&thread_indexes[i]);
}
for(i=0; i<thread_amount; i++) {
//printf("joining %d\n", i);
pthread_join(threads[i], NULL);
}
}
}