From cc2b6943c660bbf55a7ab9c0944db771da7ae5dc Mon Sep 17 00:00:00 2001 From: Ilya Matyukhin Date: Tue, 23 Mar 2021 23:08:41 -0700 Subject: [PATCH] Remove SessionState from IFace VTS Bug: 183570051 Test: atest VtsHalBiometricsFaceTargetTest Change-Id: I2b106449cbafeaff1d683eb4ef87e022e12b4ee0 --- .../vts/VtsHalBiometricsFaceTargetTest.cpp | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp b/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp index 936fcc69e5..60e0a2a41f 100644 --- a/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp +++ b/biometrics/face/aidl/vts/VtsHalBiometricsFaceTargetTest.cpp @@ -21,35 +21,31 @@ #include #include +#include #include namespace aidl::android::hardware::biometrics::face { namespace { +using namespace std::literals::chrono_literals; + constexpr int kSensorId = 0; constexpr int kUserId = 0; -constexpr auto kCallbackTimeout = std::chrono::seconds(1); -enum class SessionCallbackMethodName { - kOnStateChanged, +enum class MethodName { + kOnError, + kOnSessionClosed, }; -struct SessionCallbackInvocation { - SessionCallbackMethodName method_name; - SessionState state; +struct Invocation { + MethodName methodName; + Error error; + int32_t vendorCode; }; class SessionCallback : public BnSessionCallback { public: - explicit SessionCallback(std::promise invocation_promise) - : invocation_promise_(std::move(invocation_promise)) {} - ndk::ScopedAStatus onStateChanged(int32_t /*cookie*/, SessionState state) override { - SessionCallbackInvocation invocation = {}; - invocation.method_name = SessionCallbackMethodName::kOnStateChanged; - invocation.state = state; - invocation_promise_.set_value(invocation); - return ndk::ScopedAStatus::ok(); - } + explicit SessionCallback(Invocation* inv) : mInv(inv) {} ndk::ScopedAStatus onChallengeGenerated(int64_t /*challenge*/) override { return ndk::ScopedAStatus::ok(); @@ -67,7 +63,12 @@ class SessionCallback : public BnSessionCallback { return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus onError(Error /*error*/, int32_t /*vendorCode*/) override { + ndk::ScopedAStatus onError(Error error, int32_t vendorCode) override { + *mInv = {}; + mInv->methodName = MethodName::kOnError; + mInv->error = error; + mInv->vendorCode = vendorCode; + return ndk::ScopedAStatus::ok(); } @@ -120,10 +121,15 @@ class SessionCallback : public BnSessionCallback { return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus onSessionClosed() override { return ndk::ScopedAStatus::ok(); } + ndk::ScopedAStatus onSessionClosed() override { + *mInv = {}; + mInv->methodName = MethodName::kOnSessionClosed; + + return ndk::ScopedAStatus::ok(); + } private: - std::promise invocation_promise_; + Invocation* mInv; }; class Face : public testing::TestWithParam { @@ -131,28 +137,34 @@ class Face : public testing::TestWithParam { void SetUp() override { AIBinder* binder = AServiceManager_waitForService(GetParam().c_str()); ASSERT_NE(binder, nullptr); - hal_ = IFace::fromBinder(ndk::SpAIBinder(binder)); + mHal = IFace::fromBinder(ndk::SpAIBinder(binder)); } - std::shared_ptr hal_; + std::shared_ptr mHal; + Invocation mInv; }; TEST_P(Face, AuthenticateTest) { - std::promise invocation_promise; - std::future invocation_future = invocation_promise.get_future(); - std::shared_ptr session_cb = - ndk::SharedRefBase::make(std::move(invocation_promise)); + // Prepare the callback. + auto cb = ndk::SharedRefBase::make(&mInv); + // Create a session std::shared_ptr session; - ASSERT_TRUE(hal_->createSession(kSensorId, kUserId, session_cb, &session).isOk()); + ASSERT_TRUE(mHal->createSession(kSensorId, kUserId, cb, &session).isOk()); - std::shared_ptr cancel_cb; - ASSERT_TRUE(session->authenticate(0, 0, &cancel_cb).isOk()); - ASSERT_EQ(invocation_future.wait_for(kCallbackTimeout), std::future_status::ready); + // Call authenticate + std::shared_ptr cancellationSignal; + ASSERT_TRUE(session->authenticate(0 /* operationId */, &cancellationSignal).isOk()); - SessionCallbackInvocation invocation = invocation_future.get(); - EXPECT_EQ(invocation.method_name, SessionCallbackMethodName::kOnStateChanged); - EXPECT_EQ(invocation.state, SessionState::AUTHENTICATING); + // Get the results + EXPECT_EQ(mInv.methodName, MethodName::kOnError); + EXPECT_EQ(mInv.error, Error::UNABLE_TO_PROCESS); + EXPECT_EQ(mInv.vendorCode, 0); + + // Close the session + ASSERT_TRUE(session->close().isOk()); + + EXPECT_EQ(mInv.methodName, MethodName::kOnSessionClosed); } GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(Face); @@ -161,6 +173,7 @@ INSTANTIATE_TEST_SUITE_P(IFace, Face, ::android::PrintInstanceNameToString); } // namespace +} // namespace aidl::android::hardware::biometrics::face int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); @@ -169,4 +182,3 @@ int main(int argc, char** argv) { return RUN_ALL_TESTS(); } -} // namespace aidl::android::hardware::biometrics::face