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

Commit 9cfc6d81 authored by Valerie Hau's avatar Valerie Hau
Browse files

Refactoring Transaction_test continued

Bug: 140128949
Test: build, boot, SurfaceFlinger_test
Change-Id: Ibe0bdf04e1667051aa2126a676839cdcdbe7579d
parent 39485717
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -19,10 +19,19 @@ cc_test {
    srcs: [
        "BufferGenerator.cpp",
        "Credentials_test.cpp",
	"DereferenceSurfaceControl_test.cpp",
        "DisplayActiveConfig_test.cpp",
	"InvalidHandles_test.cpp",
        "LayerCallback_test.cpp",
	"LayerRenderTypeTransaction_test.cpp",
	"LayerTransaction_test.cpp",
	"LayerTypeAndRenderTypeTransaction_test.cpp",
	"LayerTypeTransaction_test.cpp",
	"LayerUpdate_test.cpp",
	"MultiDisplayLayerBounds_test.cpp",
	"RelativeZ_test.cpp",
	"Stress_test.cpp",
        "SurfaceInterceptor_test.cpp",
        "Transaction_test.cpp",
        "VirtualDisplay_test.cpp",
    ],
    data: ["SurfaceFlinger_test.filter"],
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "LayerTransactionTest.h"
namespace android {

using android::hardware::graphics::common::V1_1::BufferUsage;

::testing::Environment* const binderEnv =
        ::testing::AddGlobalTestEnvironment(new BinderEnvironment());

class DereferenceSurfaceControlTest : public LayerTransactionTest {
protected:
    void SetUp() override {
        LayerTransactionTest::SetUp();
        bgLayer = createLayer("BG layer", 20, 20);
        fillBufferQueueLayerColor(bgLayer, Color::RED, 20, 20);
        fgLayer = createLayer("FG layer", 20, 20);
        fillBufferQueueLayerColor(fgLayer, Color::BLUE, 20, 20);
        Transaction().setLayer(fgLayer, mLayerZBase + 1).apply();
        {
            SCOPED_TRACE("before anything");
            auto shot = screenshot();
            shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE);
        }
    }
    void TearDown() override {
        LayerTransactionTest::TearDown();
        bgLayer = 0;
        fgLayer = 0;
    }

    sp<SurfaceControl> bgLayer;
    sp<SurfaceControl> fgLayer;
};

TEST_F(DereferenceSurfaceControlTest, LayerNotInTransaction) {
    fgLayer = nullptr;
    {
        SCOPED_TRACE("after setting null");
        auto shot = screenshot();
        shot->expectColor(Rect(0, 0, 20, 20), Color::RED);
    }
}

TEST_F(DereferenceSurfaceControlTest, LayerInTransaction) {
    auto transaction = Transaction().show(fgLayer);
    fgLayer = nullptr;
    {
        SCOPED_TRACE("after setting null");
        auto shot = screenshot();
        shot->expectColor(Rect(0, 0, 20, 20), Color::BLUE);
    }
}

} // namespace android
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <thread>
#include "LayerTransactionTest.h"
namespace android {

using android::hardware::graphics::common::V1_1::BufferUsage;

::testing::Environment* const binderEnv =
        ::testing::AddGlobalTestEnvironment(new BinderEnvironment());

class DisplayActiveConfigTest : public ::testing::Test {
protected:
    void SetUp() override {
        mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
        SurfaceComposerClient::getDisplayConfigs(mDisplayToken, &mDisplayconfigs);
        EXPECT_GT(mDisplayconfigs.size(), 0);

        // set display power to on to make sure config can be changed
        SurfaceComposerClient::setDisplayPowerMode(mDisplayToken, HWC_POWER_MODE_NORMAL);
    }

    sp<IBinder> mDisplayToken;
    Vector<DisplayInfo> mDisplayconfigs;
};

TEST_F(DisplayActiveConfigTest, allConfigsAllowed) {
    std::vector<int32_t> allowedConfigs;

    // Add all configs to the allowed configs
    for (int i = 0; i < mDisplayconfigs.size(); i++) {
        allowedConfigs.push_back(i);
    }

    status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs);
    EXPECT_EQ(res, NO_ERROR);

    std::vector<int32_t> outConfigs;
    res = SurfaceComposerClient::getAllowedDisplayConfigs(mDisplayToken, &outConfigs);
    EXPECT_EQ(res, NO_ERROR);
    EXPECT_EQ(allowedConfigs, outConfigs);
}

TEST_F(DisplayActiveConfigTest, changeAllowedConfig) {
    // we need at least 2 configs available for this test
    if (mDisplayconfigs.size() <= 1) return;

    int activeConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken);

    // We want to set the allowed config to everything but the active config
    std::vector<int32_t> allowedConfigs;
    for (int i = 0; i < mDisplayconfigs.size(); i++) {
        if (i != activeConfig) {
            allowedConfigs.push_back(i);
        }
    }

    status_t res = SurfaceComposerClient::setAllowedDisplayConfigs(mDisplayToken, allowedConfigs);
    EXPECT_EQ(res, NO_ERROR);

    // Allow some time for the config change
    std::this_thread::sleep_for(200ms);

    int newActiveConfig = SurfaceComposerClient::getActiveConfig(mDisplayToken);
    EXPECT_NE(activeConfig, newActiveConfig);

    // Make sure the new config is part of allowed config
    EXPECT_TRUE(std::find(allowedConfigs.begin(), allowedConfigs.end(), newActiveConfig) !=
                allowedConfigs.end());
}
} // namespace android
+872 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading