#include "gtest/gtest.h"
#include <camutex.h>
-#include <uthreadpool.h>
+#include <cathreadpool.h>
#include <time.h>
#include <sys/time.h>
TEST(MutexTests, TC_03_THREAD_LOCKING)
{
- u_thread_pool_t mythreadpool;
+ ca_thread_pool_t mythreadpool;
- EXPECT_EQ(CA_STATUS_OK, u_thread_pool_init(3, &mythreadpool));
+ EXPECT_EQ(CA_STATUS_OK, ca_thread_pool_init(3, &mythreadpool));
_func1_struct pData = {};
DBG_printf("test: starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, mutexFunc, &pData));
+ ca_thread_pool_add_task(mythreadpool, mutexFunc, &pData));
DBG_printf("test: waiting for thread to be up.\n");
ca_mutex_free(pData.mutex);
}
- u_thread_pool_free(mythreadpool);
+ ca_thread_pool_free(mythreadpool);
}
TEST(ConditionTests, TC_01_CREATE)
TEST(ConditionTests, TC_02_SIGNAL)
{
const int MAX_WAIT_MS = 2000;
- u_thread_pool_t mythreadpool;
+ ca_thread_pool_t mythreadpool;
- EXPECT_EQ(CA_STATUS_OK, u_thread_pool_init(3, &mythreadpool));
+ EXPECT_EQ(CA_STATUS_OK, ca_thread_pool_init(3, &mythreadpool));
ca_mutex sharedMutex = ca_mutex_new();
ca_cond sharedCond = ca_cond_new();
if (pData1.mutex != NULL)
{
DBG_printf("starting thread\n");
- //start thread
+ // start threads
+ EXPECT_EQ(CA_STATUS_OK,
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData1));
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, condFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
//start thread
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, condFunc, &pData2));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
DBG_printf("test : sleeping\n");
ca_cond_free(pData1.condition);
- u_thread_pool_free(mythreadpool);
+ ca_thread_pool_free(mythreadpool);
}
TEST(ConditionTests, TC_03_BROADCAST)
{
const int MAX_WAIT_MS = 2000;
- u_thread_pool_t mythreadpool;
+ ca_thread_pool_t mythreadpool;
- EXPECT_EQ(CA_STATUS_OK, u_thread_pool_init(3, &mythreadpool));
+ EXPECT_EQ(CA_STATUS_OK, ca_thread_pool_init(3, &mythreadpool));
ca_mutex sharedMutex = ca_mutex_new();
ca_cond sharedCond = ca_cond_new();
if (pData1.mutex != NULL)
{
DBG_printf("starting thread\n");
- //start thread
+ // start threads
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, condFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData1));
+ EXPECT_EQ(CA_STATUS_OK,
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
//start thread
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, condFunc, &pData2));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
DBG_printf("test : sleeping\n");
ca_cond_free(sharedCond);
- u_thread_pool_free(mythreadpool);
+ ca_thread_pool_free(mythreadpool);
}
TEST(CondTests, TC_04_TIMECHECK)
ca_mutex_lock(pData->mutex);
- uint64_t abs = getAbsTime();
- abs += USECS_PER_SEC / 2; // 1/2 second
+ uint64_t abs = USECS_PER_SEC / 2; // 1/2 seconds
// test UTIMEDOUT
- CAWaitResult_t ret = ca_cond_wait_until(pData->condition,
- pData->mutex, abs);
+ CAWaitResult_t ret = ca_cond_wait_for(pData->condition,
+ pData->mutex, abs);
EXPECT_EQ(CA_WAIT_TIMEDOUT, ret);
pData->thread_up = true;
DBG_printf("Thread_%d: waiting for signal \n", pData->id);
- abs = getAbsTime();
- abs += 5 * USECS_PER_SEC; // 5 seconds
+ abs = 5 * USECS_PER_SEC; // 5 seconds
// test signal
- ret = ca_cond_wait_until(pData->condition, pData->mutex, abs);
+ ret = ca_cond_wait_for(pData->condition, pData->mutex, abs);
EXPECT_EQ(CA_WAIT_SUCCESS, ret);
pData->finished = true; // assignment guarded by lock
TEST(ConditionTests, TC_05_WAIT)
{
const int MAX_WAIT_MS = 5000;
- u_thread_pool_t mythreadpool;
+ ca_thread_pool_t mythreadpool;
- EXPECT_EQ(CA_STATUS_OK, u_thread_pool_init(3, &mythreadpool));
+ EXPECT_EQ(CA_STATUS_OK, ca_thread_pool_init(3, &mythreadpool));
ca_mutex sharedMutex = ca_mutex_new();
ca_cond sharedCond = ca_cond_new();
DBG_printf("test : starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
- u_thread_pool_add_task(mythreadpool, timedFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, timedFunc, &pData1));
DBG_printf("test : waiting for thread to timeout once.\n");
ca_cond_free(sharedCond);
- u_thread_pool_free(mythreadpool);
- }
+ ca_thread_pool_free(mythreadpool);
+}
-TEST(ConditionTests, TC_06_INVALIDWAIT)
+// Disabled because this should no longer be a valid test
+TEST(ConditionTests, DISABLED_TC_06_INVALIDWAIT)
{
ca_mutex sharedMutex = ca_mutex_new();
ca_mutex_lock(sharedMutex);
- int ret = ca_cond_wait_until(NULL, sharedMutex, 5000);
+ int ret = ca_cond_wait_for(NULL, sharedMutex, 5000);
EXPECT_EQ(CA_WAIT_INVAL,ret);
- ret = ca_cond_wait_until(sharedCond, NULL, 5000);
+ ret = ca_cond_wait_for(sharedCond, NULL, 5000);
EXPECT_EQ(CA_WAIT_INVAL,ret);
- ret = ca_cond_wait_until(NULL, NULL, 5000);
+ ret = ca_cond_wait_for(NULL, NULL, 5000);
EXPECT_EQ(CA_WAIT_INVAL,ret);
ca_mutex_unlock(sharedMutex);
ca_mutex_lock(sharedMutex);
- uint64_t abs = getAbsTime();
- uint64_t beg = abs;
- abs += TARGET_WAIT * USECS_PER_SEC;
+ uint64_t beg = getAbsTime();
- CAWaitResult_t ret = ca_cond_wait_until(sharedCond, sharedMutex, abs);
+ CAWaitResult_t ret = ca_cond_wait_for(sharedCond, sharedMutex,
+ TARGET_WAIT * USECS_PER_SEC);
EXPECT_EQ(CA_WAIT_TIMEDOUT,ret);
uint64_t end = getAbsTime();