1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
/*
* Copyright 2018 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 <gtest/gtest.h>
#include <binder/ProcessState.h>
#include <gui/ISurfaceComposer.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <inttypes.h>
namespace android {
using Transaction = SurfaceComposerClient::Transaction;
static constexpr uint32_t INVALID_MASK = 0x10;
class DisplayedContentSamplingTest : public ::testing::Test {
protected:
void SetUp() {
mComposerClient = new SurfaceComposerClient;
ASSERT_EQ(OK, mComposerClient->initCheck());
mDisplayToken = mComposerClient->getInternalDisplayToken();
ASSERT_TRUE(mDisplayToken);
}
bool shouldSkipTest() {
ui::PixelFormat format;
ui::Dataspace dataspace;
status_t status =
mComposerClient->getDisplayedContentSamplingAttributes(mDisplayToken, &format,
&dataspace, &componentMask);
if (status == PERMISSION_DENIED) {
SUCCEED() << "permissions denial, skipping test";
return true;
}
if (status == INVALID_OPERATION) {
SUCCEED() << "optional function not supported, skipping test";
return true;
}
return false;
}
sp<SurfaceComposerClient> mComposerClient;
sp<IBinder> mDisplayToken;
uint8_t componentMask = 0;
};
TEST_F(DisplayedContentSamplingTest, GetDisplayedContentSamplingAttributesAreSane) {
// tradefed infrastructure does not support use of GTEST_SKIP
if (shouldSkipTest()) return;
ui::PixelFormat format;
ui::Dataspace dataspace;
status_t status =
mComposerClient->getDisplayedContentSamplingAttributes(mDisplayToken, &format,
&dataspace, &componentMask);
EXPECT_EQ(OK, status);
EXPECT_LE(componentMask, INVALID_MASK);
}
TEST_F(DisplayedContentSamplingTest, EnableWithInvalidMaskReturnsBadValue) {
if (shouldSkipTest()) return;
status_t status =
mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true, INVALID_MASK, 0);
EXPECT_EQ(BAD_VALUE, status);
}
TEST_F(DisplayedContentSamplingTest, EnableAndDisableSucceed) {
if (shouldSkipTest()) return;
status_t status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true,
componentMask, 10);
EXPECT_EQ(OK, status);
status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, false, componentMask,
0);
EXPECT_EQ(OK, status);
}
TEST_F(DisplayedContentSamplingTest, SelectivelyDisableComponentOk) {
if (shouldSkipTest()) return;
status_t status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, true,
componentMask, 0);
EXPECT_EQ(OK, status);
// Clear the lowest bit.
componentMask &= (componentMask - 1);
status = mComposerClient->setDisplayContentSamplingEnabled(mDisplayToken, false, componentMask,
0);
EXPECT_EQ(OK, status);
}
TEST_F(DisplayedContentSamplingTest, SampleCollectionCoherentWithSupportMask) {
if (shouldSkipTest()) return;
DisplayedFrameStats stats;
status_t status = mComposerClient->getDisplayedContentSample(mDisplayToken, 0, 0, &stats);
EXPECT_EQ(OK, status);
if (stats.numFrames <= 0) return;
if (componentMask & (0x1 << 0)) EXPECT_NE(0, stats.component_0_sample.size());
if (componentMask & (0x1 << 1)) EXPECT_NE(0, stats.component_1_sample.size());
if (componentMask & (0x1 << 2)) EXPECT_NE(0, stats.component_2_sample.size());
if (componentMask & (0x1 << 3)) EXPECT_NE(0, stats.component_3_sample.size());
}
} // namespace android
|