projects
/
platform
/
upstream
/
iotivity.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git]
/
resource
/
csdk
/
connectivity
/
test
/
octhread_tests.cpp
diff --git
a/resource/csdk/connectivity/test/camutex_tests.cpp
b/resource/csdk/connectivity/test/octhread_tests.cpp
similarity index 82%
rename from
resource/csdk/connectivity/test/camutex_tests.cpp
rename to
resource/csdk/connectivity/test/octhread_tests.cpp
index
9a8e6f6
..
d68ef48
100644
(file)
--- a/
resource/csdk/connectivity/test/camutex_tests.cpp
+++ b/
resource/csdk/connectivity/test/octhread_tests.cpp
@@
-36,7
+36,7
@@
#include "iotivity_config.h"
#include "gtest/gtest.h"
#include "iotivity_config.h"
#include "gtest/gtest.h"
-#include
<camutex.h>
+#include
"octhread.h"
#include <cathreadpool.h>
#ifdef HAVE_TIME_H
#include <cathreadpool.h>
#ifdef HAVE_TIME_H
@@
-102,18
+102,18
@@
uint64_t getAbsTime()
TEST(MutexTests, TC_01_CREATE)
{
TEST(MutexTests, TC_01_CREATE)
{
-
ca_mutex mymutex = ca
_mutex_new();
+
oc_mutex mymutex = oc
_mutex_new();
EXPECT_TRUE(mymutex != NULL);
if (mymutex != NULL)
{
EXPECT_TRUE(mymutex != NULL);
if (mymutex != NULL)
{
-
ca
_mutex_free(mymutex);
+
oc
_mutex_free(mymutex);
}
}
typedef struct _tagFunc1
{
}
}
typedef struct _tagFunc1
{
-
ca
_mutex mutex;
+
oc
_mutex mutex;
volatile bool thread_up;
volatile bool finished;
} _func1_struct;
volatile bool thread_up;
volatile bool finished;
} _func1_struct;
@@
-127,7
+127,7
@@
void mutexFunc(void *context)
// setting the flag must be done before lock attempt, as the test
// thread starts off with the mutex locked
pData->thread_up = true;
// setting the flag must be done before lock attempt, as the test
// thread starts off with the mutex locked
pData->thread_up = true;
-
ca
_mutex_lock(pData->mutex);
+
oc
_mutex_lock(pData->mutex);
DBG_printf("Thread: got lock\n");
usleep(MINIMAL_LOOP_SLEEP * USECS_PER_MSEC);
DBG_printf("Thread: got lock\n");
usleep(MINIMAL_LOOP_SLEEP * USECS_PER_MSEC);
@@
-135,7
+135,7
@@
void mutexFunc(void *context)
pData->finished = true; // assignment guarded by lock
pData->finished = true; // assignment guarded by lock
-
ca
_mutex_unlock(pData->mutex);
+
oc
_mutex_unlock(pData->mutex);
}
TEST(MutexTests, TC_03_THREAD_LOCKING)
}
TEST(MutexTests, TC_03_THREAD_LOCKING)
@@
-146,18
+146,18
@@
TEST(MutexTests, TC_03_THREAD_LOCKING)
_func1_struct pData = {0, false, false};
_func1_struct pData = {0, false, false};
- pData.mutex =
ca
_mutex_new();
+ pData.mutex =
oc
_mutex_new();
EXPECT_TRUE(pData.mutex != NULL);
if (pData.mutex != NULL)
{
DBG_printf("test: Holding mutex in test\n");
EXPECT_TRUE(pData.mutex != NULL);
if (pData.mutex != NULL)
{
DBG_printf("test: Holding mutex in test\n");
-
ca
_mutex_lock(pData.mutex);
+
oc
_mutex_lock(pData.mutex);
DBG_printf("test: starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
DBG_printf("test: starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, mutexFunc, &pData));
+ ca_thread_pool_add_task(mythreadpool, mutexFunc, &pData
, NULL
));
DBG_printf("test: waiting for thread to be up.\n");
DBG_printf("test: waiting for thread to be up.\n");
@@
-172,7
+172,7
@@
TEST(MutexTests, TC_03_THREAD_LOCKING)
DBG_printf("test: unlocking\n");
DBG_printf("test: unlocking\n");
-
ca
_mutex_unlock(pData.mutex);
+
oc
_mutex_unlock(pData.mutex);
DBG_printf("test: waiting for thread to release\n");
while (!pData.finished)
DBG_printf("test: waiting for thread to release\n");
while (!pData.finished)
@@
-180,12
+180,12
@@
TEST(MutexTests, TC_03_THREAD_LOCKING)
usleep(MINIMAL_LOOP_SLEEP * USECS_PER_MSEC);
}
usleep(MINIMAL_LOOP_SLEEP * USECS_PER_MSEC);
}
-
ca
_mutex_lock(pData.mutex);
+
oc
_mutex_lock(pData.mutex);
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_unlock(pData.mutex);
-
ca
_mutex_free(pData.mutex);
+
oc
_mutex_unlock(pData.mutex);
+
oc
_mutex_free(pData.mutex);
}
ca_thread_pool_free(mythreadpool);
}
ca_thread_pool_free(mythreadpool);
@@
-193,23
+193,23
@@
TEST(MutexTests, TC_03_THREAD_LOCKING)
TEST(ConditionTests, TC_01_CREATE)
{
TEST(ConditionTests, TC_01_CREATE)
{
-
ca_cond mycond = ca
_cond_new();
+
oc_cond mycond = oc
_cond_new();
EXPECT_TRUE(mycond != NULL);
if (mycond != NULL)
{
EXPECT_TRUE(mycond != NULL);
if (mycond != NULL)
{
-
ca
_cond_free(mycond);
+
oc
_cond_free(mycond);
}
}
// Normally we would use one pair of mutex/cond-var communicating to the
// worker threads and one pair back to the main thread. However since
}
}
// Normally we would use one pair of mutex/cond-var communicating to the
// worker threads and one pair back to the main thread. However since
-// testing the
ca
_cond itself is the point, only one pair is used here.
+// testing the
oc
_cond itself is the point, only one pair is used here.
typedef struct _tagFunc2
{
int id;
typedef struct _tagFunc2
{
int id;
-
ca
_mutex mutex;
-
ca
_cond condition;
+
oc
_mutex mutex;
+
oc
_cond condition;
volatile bool thread_up;
volatile bool finished;
} _func2_struct;
volatile bool thread_up;
volatile bool finished;
} _func2_struct;
@@
-220,15
+220,15
@@
void condFunc(void *context)
DBG_printf("Thread_%d: waiting on condition\n", pData->id);
DBG_printf("Thread_%d: waiting on condition\n", pData->id);
-
ca
_mutex_lock(pData->mutex);
+
oc
_mutex_lock(pData->mutex);
pData->thread_up = true;
pData->thread_up = true;
-
ca
_cond_wait(pData->condition, pData->mutex);
+
oc
_cond_wait(pData->condition, pData->mutex);
pData->finished = true; // assignment guarded by lock
pData->finished = true; // assignment guarded by lock
-
ca
_mutex_unlock(pData->mutex);
+
oc
_mutex_unlock(pData->mutex);
DBG_printf("Thread_%d: completed.\n", pData->id);
}
DBG_printf("Thread_%d: completed.\n", pData->id);
}
@@
-245,8
+245,8
@@
TEST(ConditionTests, TC_02_SIGNAL)
EXPECT_EQ(CA_STATUS_OK, ca_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();
+
oc_mutex sharedMutex = oc
_mutex_new();
+
oc_cond sharedCond = oc
_cond_new();
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
@@
-259,9
+259,9
@@
TEST(ConditionTests, TC_02_SIGNAL)
DBG_printf("starting thread\n");
// start threads
EXPECT_EQ(CA_STATUS_OK,
DBG_printf("starting thread\n");
// start threads
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, condFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData1
, NULL
));
EXPECT_EQ(CA_STATUS_OK,
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2
, NULL
));
DBG_printf("test : sleeping\n");
DBG_printf("test : sleeping\n");
@@
-275,11
+275,11
@@
TEST(ConditionTests, TC_02_SIGNAL)
// has already started waiting on the condition and the other is at
// least close.
// has already started waiting on the condition and the other is at
// least close.
-
ca
_mutex_lock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
// once the lock is acquired it means both threads were waiting.
DBG_printf("test : signaling first thread\n");
// once the lock is acquired it means both threads were waiting.
DBG_printf("test : signaling first thread\n");
-
ca
_cond_signal(sharedCond);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_cond_signal(sharedCond);
+
oc
_mutex_unlock(sharedMutex);
// At this point either of the child threads might lock the mutex in
// their cond_wait call, or this test thread might lock it again if
// At this point either of the child threads might lock the mutex in
// their cond_wait call, or this test thread might lock it again if
@@
-303,15
+303,15
@@
TEST(ConditionTests, TC_02_SIGNAL)
usleep(MINIMAL_EXTRA_SLEEP);
// only one should be finished
usleep(MINIMAL_EXTRA_SLEEP);
// only one should be finished
-
ca
_mutex_lock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
EXPECT_NE(pData1.finished, pData2.finished);
EXPECT_NE(pData1.finished, pData2.finished);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_mutex_unlock(sharedMutex);
DBG_printf("test : signaling another thread\n");
DBG_printf("test : signaling another thread\n");
-
ca
_mutex_lock(sharedMutex);
-
ca
_cond_signal(sharedCond);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
+
oc
_cond_signal(sharedCond);
+
oc
_mutex_unlock(sharedMutex);
waitCount = 0;
while ((!pData1.finished || !pData2.finished)
waitCount = 0;
while ((!pData1.finished || !pData2.finished)
@@
-327,10
+327,10
@@
TEST(ConditionTests, TC_02_SIGNAL)
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_free(pData1.mutex);
+
oc
_mutex_free(pData1.mutex);
}
}
-
ca
_cond_free(pData1.condition);
+
oc
_cond_free(pData1.condition);
ca_thread_pool_free(mythreadpool);
}
ca_thread_pool_free(mythreadpool);
}
@@
-342,8
+342,8
@@
TEST(ConditionTests, TC_03_BROADCAST)
EXPECT_EQ(CA_STATUS_OK, ca_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();
+
oc_mutex sharedMutex = oc
_mutex_new();
+
oc_cond sharedCond = oc
_cond_new();
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
@@
-356,9
+356,9
@@
TEST(ConditionTests, TC_03_BROADCAST)
DBG_printf("starting thread\n");
// start threads
EXPECT_EQ(CA_STATUS_OK,
DBG_printf("starting thread\n");
// start threads
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, condFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData1
, NULL
));
EXPECT_EQ(CA_STATUS_OK,
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, condFunc, &pData2));
+ ca_thread_pool_add_task(mythreadpool, condFunc, &pData2
, NULL
));
DBG_printf("test : sleeping\n");
DBG_printf("test : sleeping\n");
@@
-374,10
+374,10
@@
TEST(ConditionTests, TC_03_BROADCAST)
DBG_printf("test : signaling all threads\n");
DBG_printf("test : signaling all threads\n");
-
ca
_mutex_lock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
// once the lock is acquired it means both threads were waiting.
// once the lock is acquired it means both threads were waiting.
-
ca
_cond_broadcast(sharedCond);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_cond_broadcast(sharedCond);
+
oc
_mutex_unlock(sharedMutex);
int waitCount = 0;
while ((!pData1.finished || !pData2.finished)
int waitCount = 0;
while ((!pData1.finished || !pData2.finished)
@@
-393,10
+393,10
@@
TEST(ConditionTests, TC_03_BROADCAST)
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_free(sharedMutex);
+
oc
_mutex_free(sharedMutex);
}
}
-
ca
_cond_free(sharedCond);
+
oc
_cond_free(sharedCond);
ca_thread_pool_free(mythreadpool);
}
ca_thread_pool_free(mythreadpool);
}
@@
-423,14
+423,14
@@
void timedFunc(void *context)
DBG_printf("Thread_%d: waiting for timeout \n", pData->id);
DBG_printf("Thread_%d: waiting for timeout \n", pData->id);
-
ca
_mutex_lock(pData->mutex);
+
oc
_mutex_lock(pData->mutex);
uint64_t abs = USECS_PER_SEC / 2; // 1/2 seconds
// test UTIMEDOUT
uint64_t abs = USECS_PER_SEC / 2; // 1/2 seconds
// test UTIMEDOUT
-
CAWaitResult_t ret = ca
_cond_wait_for(pData->condition,
+
OCWaitResult_t ret = oc
_cond_wait_for(pData->condition,
pData->mutex, abs);
pData->mutex, abs);
- EXPECT_EQ(
CA
_WAIT_TIMEDOUT, ret);
+ EXPECT_EQ(
OC
_WAIT_TIMEDOUT, ret);
pData->thread_up = true;
pData->thread_up = true;
@@
-439,12
+439,12
@@
void timedFunc(void *context)
abs = 5 * USECS_PER_SEC; // 5 seconds
// test signal
abs = 5 * USECS_PER_SEC; // 5 seconds
// test signal
- ret =
ca
_cond_wait_for(pData->condition, pData->mutex, abs);
- EXPECT_EQ(
CA
_WAIT_SUCCESS, ret);
+ ret =
oc
_cond_wait_for(pData->condition, pData->mutex, abs);
+ EXPECT_EQ(
OC
_WAIT_SUCCESS, ret);
pData->finished = true; // assignment guarded by lock
pData->finished = true; // assignment guarded by lock
-
ca
_mutex_unlock(pData->mutex);
+
oc
_mutex_unlock(pData->mutex);
DBG_printf("Thread_%d: stopping\n", pData->id);
}
DBG_printf("Thread_%d: stopping\n", pData->id);
}
@@
-456,8
+456,8
@@
TEST(ConditionTests, TC_05_WAIT)
EXPECT_EQ(CA_STATUS_OK, ca_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();
+
oc_mutex sharedMutex = oc
_mutex_new();
+
oc_cond sharedCond = oc
_cond_new();
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
_func2_struct pData1 =
{ 1, sharedMutex, sharedCond, false, false };
@@
-468,7
+468,7
@@
TEST(ConditionTests, TC_05_WAIT)
DBG_printf("test : starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
DBG_printf("test : starting thread\n");
//start thread
EXPECT_EQ(CA_STATUS_OK,
- ca_thread_pool_add_task(mythreadpool, timedFunc, &pData1));
+ ca_thread_pool_add_task(mythreadpool, timedFunc, &pData1
, NULL
));
DBG_printf("test : waiting for thread to timeout once.\n");
DBG_printf("test : waiting for thread to timeout once.\n");
@@
-482,9
+482,9
@@
TEST(ConditionTests, TC_05_WAIT)
DBG_printf("test : signaling first thread\n");
DBG_printf("test : signaling first thread\n");
-
ca
_mutex_lock(sharedMutex);
-
ca
_cond_signal(sharedCond);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
+
oc
_cond_signal(sharedCond);
+
oc
_mutex_unlock(sharedMutex);
int waitCount = 0;
while (!pData1.finished
int waitCount = 0;
while (!pData1.finished
@@
-498,10
+498,10
@@
TEST(ConditionTests, TC_05_WAIT)
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_free(sharedMutex);
+
oc
_mutex_free(sharedMutex);
}
}
-
ca
_cond_free(sharedCond);
+
oc
_cond_free(sharedCond);
ca_thread_pool_free(mythreadpool);
}
ca_thread_pool_free(mythreadpool);
}
@@
-510,43
+510,43
@@
TEST(ConditionTests, TC_05_WAIT)
TEST(ConditionTests, DISABLED_TC_06_INVALIDWAIT)
{
TEST(ConditionTests, DISABLED_TC_06_INVALIDWAIT)
{
-
ca_mutex sharedMutex = ca
_mutex_new();
-
ca_cond sharedCond = ca
_cond_new();
+
oc_mutex sharedMutex = oc
_mutex_new();
+
oc_cond sharedCond = oc
_cond_new();
-
ca
_mutex_lock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
- int ret =
ca
_cond_wait_for(NULL, sharedMutex, 5000);
- EXPECT_EQ(
CA
_WAIT_INVAL,ret);
+ int ret =
oc
_cond_wait_for(NULL, sharedMutex, 5000);
+ EXPECT_EQ(
OC
_WAIT_INVAL,ret);
- ret =
ca
_cond_wait_for(sharedCond, NULL, 5000);
- EXPECT_EQ(
CA
_WAIT_INVAL,ret);
+ ret =
oc
_cond_wait_for(sharedCond, NULL, 5000);
+ EXPECT_EQ(
OC
_WAIT_INVAL,ret);
- ret =
ca
_cond_wait_for(NULL, NULL, 5000);
- EXPECT_EQ(
CA
_WAIT_INVAL,ret);
+ ret =
oc
_cond_wait_for(NULL, NULL, 5000);
+ EXPECT_EQ(
OC
_WAIT_INVAL,ret);
-
ca
_mutex_unlock(sharedMutex);
+
oc
_mutex_unlock(sharedMutex);
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_free(sharedMutex);
+
oc
_mutex_free(sharedMutex);
-
ca
_cond_free(sharedCond);
+
oc
_cond_free(sharedCond);
}
TEST(ConditionTests, TC_07_WAITDURATION)
{
const double TARGET_WAIT = 1.125;
}
TEST(ConditionTests, TC_07_WAITDURATION)
{
const double TARGET_WAIT = 1.125;
-
ca_mutex sharedMutex = ca
_mutex_new();
-
ca_cond sharedCond = ca
_cond_new();
+
oc_mutex sharedMutex = oc
_mutex_new();
+
oc_cond sharedCond = oc
_cond_new();
-
ca
_mutex_lock(sharedMutex);
+
oc
_mutex_lock(sharedMutex);
uint64_t beg = getAbsTime();
uint64_t beg = getAbsTime();
-
CAWaitResult_t ret = ca
_cond_wait_for(sharedCond, sharedMutex,
+
OCWaitResult_t ret = oc
_cond_wait_for(sharedCond, sharedMutex,
TARGET_WAIT * USECS_PER_SEC);
TARGET_WAIT * USECS_PER_SEC);
- EXPECT_EQ(
CA
_WAIT_TIMEDOUT,ret);
+ EXPECT_EQ(
OC
_WAIT_TIMEDOUT,ret);
uint64_t end = getAbsTime();
uint64_t end = getAbsTime();
@@
-561,11
+561,11
@@
TEST(ConditionTests, TC_07_WAITDURATION)
EXPECT_NEAR(TARGET_WAIT, secondsDiff, 0.05);
#endif
EXPECT_NEAR(TARGET_WAIT, secondsDiff, 0.05);
#endif
-
ca
_mutex_unlock(sharedMutex);
+
oc
_mutex_unlock(sharedMutex);
// Cleanup Everything
// Cleanup Everything
-
ca
_mutex_free(sharedMutex);
+
oc
_mutex_free(sharedMutex);
-
ca
_cond_free(sharedCond);
+
oc
_cond_free(sharedCond);
}
}