summaryrefslogtreecommitdiffstats
path: root/camera/tests
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2013-01-30 10:14:24 -0800
committerIgor Murashkin <iam@google.com>2013-02-22 10:50:14 -0800
commit39f79f77a435c2f769477caeb071e2f9f6e78742 (patch)
tree0a9f096348c3f74921b16aa92054a8bac330a69f /camera/tests
parent5376573eff55f370f041889618c9a7a9e1894615 (diff)
downloadframeworks_av-39f79f77a435c2f769477caeb071e2f9f6e78742.zip
frameworks_av-39f79f77a435c2f769477caeb071e2f9f6e78742.tar.gz
frameworks_av-39f79f77a435c2f769477caeb071e2f9f6e78742.tar.bz2
Camera: ProCameraTests - add asynchronous locking unit test
Change-Id: Ib79eb84046c9ed898bfb086a6600265fc351924c
Diffstat (limited to 'camera/tests')
-rw-r--r--camera/tests/ProCameraTests.cpp46
1 files changed, 41 insertions, 5 deletions
diff --git a/camera/tests/ProCameraTests.cpp b/camera/tests/ProCameraTests.cpp
index ca9e224..adc3c75 100644
--- a/camera/tests/ProCameraTests.cpp
+++ b/camera/tests/ProCameraTests.cpp
@@ -42,6 +42,11 @@ namespace client {
#define dout if (0) std::cerr
#endif
+#define EXPECT_OK(x) EXPECT_EQ(OK, (x))
+#define ASSERT_OK(x) ASSERT_EQ(OK, (x))
+
+class ProCameraTest;
+
enum LockEvent {
UNKNOWN,
ACQUIRED,
@@ -63,9 +68,7 @@ public:
IPCThreadState *ptr = IPCThreadState::self();
- dout << "will join thread pool" << std::endl;
ptr->joinThreadPool();
- dout << "joined thread pool (done)" << std::endl;
return false;
}
@@ -178,10 +181,13 @@ public:
ProCameraTest() {
}
- virtual void SetUp() {
+ static void SetUpTestCase() {
+ // Binder Thread Pool Initialization
mTestThread = new ProCameraTestThread();
mTestThread->run("ProCameraTestThread");
+ }
+ virtual void SetUp() {
mCamera = ProCamera::connect(CAMERA_ID);
ASSERT_NE((void*)NULL, mCamera.get());
@@ -198,19 +204,49 @@ protected:
sp<ProCamera> mCamera;
sp<ProCameraTestListener> mListener;
- sp<Thread> mTestThread;
+ static sp<Thread> mTestThread;
};
+sp<Thread> ProCameraTest::mTestThread;
+
+// test around exclusiveTryLock (immediate locking)
TEST_F(ProCameraTest, LockingImmediate) {
if (HasFatalFailure()) {
return;
}
-
EXPECT_FALSE(mCamera->hasExclusiveLock());
EXPECT_EQ(OK, mCamera->exclusiveTryLock());
+ // at this point we definitely have the lock
+
+ EXPECT_EQ(OK, mListener->WaitForEvent());
+ EXPECT_EQ(ACQUIRED, mListener->ReadEvent());
+
+ EXPECT_TRUE(mCamera->hasExclusiveLock());
+ EXPECT_EQ(OK, mCamera->exclusiveUnlock());
+
+ EXPECT_EQ(OK, mListener->WaitForEvent());
+ EXPECT_EQ(RELEASED, mListener->ReadEvent());
+
+ EXPECT_FALSE(mCamera->hasExclusiveLock());
+}
+
+// test around exclusiveLock (locking at some future point in time)
+TEST_F(ProCameraTest, LockingAsynchronous) {
+
+ if (HasFatalFailure()) {
+ return;
+ }
+
+ // TODO: Add another procamera that has a lock here.
+ // then we can be test that the lock wont immediately be acquired
+
+ EXPECT_FALSE(mCamera->hasExclusiveLock());
+ EXPECT_EQ(OK, mCamera->exclusiveLock());
+ // at this point we may or may not have the lock
+ // we cant be sure until we get an ACQUIRED event
EXPECT_EQ(OK, mListener->WaitForEvent());
EXPECT_EQ(ACQUIRED, mListener->ReadEvent());