summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>2014-05-26 22:14:38 -0700
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>2014-06-17 09:56:31 +0900
commitc97448038bd74cc9c86986440d516c7379e1a60e (patch)
tree17d2d0256200eb0633f75a6096fb73ed3b5ca443
parentc6b918c9a74ed566f060664e6812b0a4262ad352 (diff)
downloadwayland-ivi-extension-c97448038bd74cc9c86986440d516c7379e1a60e.tar.gz
test: Fix a lock issue when the API tests is running.
Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
-rw-r--r--ivi-layermanagement-api/test/ilm_control_notification_test.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/ivi-layermanagement-api/test/ilm_control_notification_test.cpp b/ivi-layermanagement-api/test/ilm_control_notification_test.cpp
index 2f9f3bc..8edd9e6 100644
--- a/ivi-layermanagement-api/test/ilm_control_notification_test.cpp
+++ b/ivi-layermanagement-api/test/ilm_control_notification_test.cpp
@@ -42,6 +42,22 @@ static pthread_cond_t waiterVariable = PTHREAD_COND_INITIALIZER;
static int timesCalled=0;
class NotificationTest: public TestBase, public ::testing::Test {
+ class PthreadMutexLock {
+ private:
+ pthread_mutex_t &mutex_;
+
+ PthreadMutexLock(const PthreadMutexLock&);
+ PthreadMutexLock& operator=(const PthreadMutexLock&);
+
+ public:
+ explicit PthreadMutexLock(pthread_mutex_t &mutex): mutex_(mutex) {
+ pthread_mutex_lock(&mutex_);
+ }
+ ~PthreadMutexLock() {
+ pthread_mutex_unlock(&mutex_);
+ }
+ };
+
public:
static void SetUpTestCase() {
@@ -93,7 +109,7 @@ public:
static struct timespec theTime;
clock_gettime(CLOCK_REALTIME, &theTime);
theTime.tv_sec += 2;
- pthread_mutex_lock( &notificationMutex );
+ PthreadMutexLock lock(notificationMutex);
int status = 0;
do {
if (numberOfExpectedCalls!=timesCalled){
@@ -101,7 +117,6 @@ public:
}
} while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);
ASSERT_NE(ETIMEDOUT, status);
- pthread_mutex_unlock( &notificationMutex );
timesCalled=0;
}
@@ -109,35 +124,32 @@ public:
struct timespec theTime;
clock_gettime(CLOCK_REALTIME, &theTime);
theTime.tv_sec += 1;
- pthread_mutex_lock( &notificationMutex );
+ PthreadMutexLock lock(notificationMutex);
// assert that we have not been notified
ASSERT_EQ(ETIMEDOUT, pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime));
- pthread_mutex_unlock( &notificationMutex );
}
static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* LayerProperties, t_ilm_notification_mask mask)
{
- pthread_mutex_lock( &notificationMutex );
+ PthreadMutexLock lock(notificationMutex);
NotificationTest::callbackLayerId = layer;
NotificationTest::LayerProperties = *LayerProperties;
NotificationTest::mask = mask;
timesCalled++;
pthread_cond_signal( &waiterVariable );
- pthread_mutex_unlock( &notificationMutex );
}
static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask mask)
{
- pthread_mutex_lock( &notificationMutex );
+ PthreadMutexLock lock(notificationMutex);
NotificationTest::callbackSurfaceId = surface;
NotificationTest::SurfaceProperties = *surfaceProperties;
NotificationTest::mask = mask;
timesCalled++;
pthread_cond_signal( &waiterVariable );
- pthread_mutex_unlock( &notificationMutex );
}
};