awtk/tests/mutex_test.cc

26 lines
527 B
C++
Raw Normal View History

2019-10-28 07:07:48 +08:00
#include "gtest/gtest.h"
#include "tkc/mutex.h"
#include "tkc/thread.h"
#include "tkc/platform.h"
static void* thread_entry(void* args) {
tk_mutex_t* mutex = (tk_mutex_t*)args;
sleep_ms(100);
tk_mutex_lock(mutex);
return NULL;
}
2019-10-28 09:07:28 +08:00
TEST(Mutex, basic) {
tk_mutex_t* mutex = tk_mutex_create();
2019-10-28 07:07:48 +08:00
tk_thread_t* thread = tk_thread_create(thread_entry, mutex);
tk_thread_start(thread);
ASSERT_EQ(tk_mutex_unlock(mutex), RET_OK);
tk_thread_join(thread);
tk_thread_destroy(thread);
tk_mutex_destroy(mutex);
}