Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b2340b7 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4464948 from 784e993e to pi-release

Change-Id: I28b9470afa6a97984dc3ac6c9979d3c463616299
parents 6a74abee 784e993e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -62,3 +62,4 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib64/hw/android.hardware.au
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/etc/init/android.hardware.automotive*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/android.hardware.tests*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/vndk/android.hardware.tests*)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/vndk-sp/android.hardware.graphics.allocator*)
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ hidl_interface {
    root: "android.hardware",
    vndk: {
        enabled: true,
        support_system_process: true,
    },
    srcs: [
        "IAllocator.hal",
+29 −57
Original line number Diff line number Diff line
@@ -68,23 +68,24 @@ class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
};

class Callback : public IHealthInfoCallback {
    using Function = std::function<void(const HealthInfo&)>;

   public:
    Callback(const Function& f) : mInternal(f) {}
    Return<void> healthInfoChanged(const HealthInfo& info) override {
        std::unique_lock<std::mutex> lock(mMutex);
        if (mInternal) mInternal(info);
    Return<void> healthInfoChanged(const HealthInfo&) override {
        std::lock_guard<std::mutex> lock(mMutex);
        mInvoked = true;
        mInvokedNotify.notify_all();
        return Void();
    }
    void clear() {
    template <typename R, typename P>
    bool waitInvoke(std::chrono::duration<R, P> duration) {
        std::unique_lock<std::mutex> lock(mMutex);
        mInternal = nullptr;
        bool r = mInvokedNotify.wait_for(lock, duration, [this] { return this->mInvoked; });
        mInvoked = false;
        return r;
    }

   private:
    std::mutex mMutex;
    Function mInternal;
    std::condition_variable mInvokedNotify;
    bool mInvoked = false;
};

#define ASSERT_OK(r) ASSERT_TRUE(isOk(r))
@@ -112,71 +113,42 @@ AssertionResult isAllOk(const Return<Result>& r) {
 */
TEST_F(HealthHidlTest, Callbacks) {
    using namespace std::chrono_literals;

    std::mutex mutex;
    std::condition_variable cv;
    bool firstCallbackInvoked = false;
    bool secondCallbackInvoked = false;

    sp<Callback> firstCallback = new Callback([&](const auto&) {
        std::unique_lock<std::mutex> lk(mutex);
        firstCallbackInvoked = true;
    });

    sp<Callback> secondCallback = new Callback([&](const auto&) {
        std::unique_lock<std::mutex> lk(mutex);
        secondCallbackInvoked = true;
        cv.notify_all();
    });
    sp<Callback> firstCallback = new Callback();
    sp<Callback> secondCallback = new Callback();

    ASSERT_ALL_OK(mHealth->registerCallback(firstCallback));
    ASSERT_ALL_OK(mHealth->registerCallback(secondCallback));

    // assert that the first callback is invoked when update is called.
    {
        std::unique_lock<std::mutex> lk(mutex);
        firstCallbackInvoked = false;
        secondCallbackInvoked = false;
    }
    // registerCallback may or may not invoke the callback immediately, so the test needs
    // to wait for the invocation. If the implementation chooses not to invoke the callback
    // immediately, just wait for some time.
    firstCallback->waitInvoke(200ms);
    secondCallback->waitInvoke(200ms);

    // assert that the first callback is invoked when update is called.
    ASSERT_ALL_OK(mHealth->update());

    {
        std::unique_lock<std::mutex> lk(mutex);
        EXPECT_TRUE(cv.wait_for(lk, 1s, [&] {
            return firstCallbackInvoked && secondCallbackInvoked;
        })) << "Timeout.";
        ASSERT_TRUE(firstCallbackInvoked);
        ASSERT_TRUE(secondCallbackInvoked);
    }
    ASSERT_TRUE(firstCallback->waitInvoke(1s));
    ASSERT_TRUE(secondCallback->waitInvoke(1s));

    ASSERT_ALL_OK(mHealth->unregisterCallback(firstCallback));

    // assert that the second callback is still invoked even though the first is unregistered.
    {
        std::unique_lock<std::mutex> lk(mutex);
        firstCallbackInvoked = false;
        secondCallbackInvoked = false;
    }
    // clear any potentially pending callbacks result from wakealarm / kernel events
    // If there is none, just wait for some time.
    firstCallback->waitInvoke(200ms);
    secondCallback->waitInvoke(200ms);

    // assert that the second callback is still invoked even though the first is unregistered.
    ASSERT_ALL_OK(mHealth->update());

    {
        std::unique_lock<std::mutex> lk(mutex);
        EXPECT_TRUE(cv.wait_for(lk, 1s, [&] { return secondCallbackInvoked; })) << "Timeout.";
        ASSERT_FALSE(firstCallbackInvoked);
        ASSERT_TRUE(secondCallbackInvoked);
    }
    ASSERT_FALSE(firstCallback->waitInvoke(200ms));
    ASSERT_TRUE(secondCallback->waitInvoke(1s));

    ASSERT_ALL_OK(mHealth->unregisterCallback(secondCallback));

    // avoid reference to lambda function that goes out of scope.
    firstCallback->clear();
    secondCallback->clear();
}

TEST_F(HealthHidlTest, UnregisterNonExistentCallback) {
    sp<Callback> callback = new Callback([](const auto&) {});
    sp<Callback> callback = new Callback();
    auto ret = mHealth->unregisterCallback(callback);
    ASSERT_OK(ret);
    ASSERT_EQ(Result::NOT_FOUND, static_cast<Result>(ret)) << "Actual: " << toString(ret);
+4 −2
Original line number Diff line number Diff line
@@ -2775,7 +2775,8 @@ TEST_F(EncryptionOperationsTest, RsaOaepTooLarge) {
              Begin(KeyPurpose::ENCRYPT,
                    AuthorizationSetBuilder().Padding(PaddingMode::RSA_OAEP).Digest(Digest::SHA1)));
    string result;
    EXPECT_EQ(ErrorCode::INVALID_INPUT_LENGTH, Finish(message, &result));
    auto error = Finish(message, &result);
    EXPECT_TRUE(error == ErrorCode::INVALID_INPUT_LENGTH || error == ErrorCode::INVALID_ARGUMENT);
    EXPECT_EQ(0U, result.size());
}

@@ -2833,7 +2834,8 @@ TEST_F(EncryptionOperationsTest, RsaPkcs1TooLarge) {
    auto params = AuthorizationSetBuilder().Padding(PaddingMode::RSA_PKCS1_1_5_ENCRYPT);
    EXPECT_EQ(ErrorCode::OK, Begin(KeyPurpose::ENCRYPT, params));
    string result;
    EXPECT_EQ(ErrorCode::INVALID_INPUT_LENGTH, Finish(message, &result));
    auto error = Finish(message, &result);
    EXPECT_TRUE(error == ErrorCode::INVALID_INPUT_LENGTH || error == ErrorCode::INVALID_ARGUMENT);
    EXPECT_EQ(0U, result.size());
}