1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <composer-vts/2.1/TestCommandReader.h>
18
19 #include <gtest/gtest.h>
20
21 namespace android {
22 namespace hardware {
23 namespace graphics {
24 namespace composer {
25 namespace V2_1 {
26 namespace vts {
27
parse()28 void TestCommandReader::parse() {
29 mErrors.clear();
30 mCompositionChanges.clear();
31 while (!isEmpty()) {
32 int32_t command;
33 uint16_t length;
34 ASSERT_TRUE(beginCommand(&command, &length));
35
36 parseSingleCommand(command, length);
37
38 endCommand();
39 }
40 }
41
parseSingleCommand(int32_t commandRaw,uint16_t length)42 void TestCommandReader::parseSingleCommand(int32_t commandRaw, uint16_t length) {
43 IComposerClient::Command command = static_cast<IComposerClient::Command>(commandRaw);
44
45 switch (command) {
46 case IComposerClient::Command::SELECT_DISPLAY:
47 ASSERT_EQ(2, length);
48 read64(); // display
49 break;
50 case IComposerClient::Command::SET_ERROR: {
51 ASSERT_EQ(2, length);
52 auto loc = read();
53 auto err = readSigned();
54 std::pair<uint32_t, uint32_t> error(loc, err);
55 mErrors.push_back(error);
56 } break;
57 case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES:
58 ASSERT_EQ(0, length % 3);
59 for (uint16_t count = 0; count < length / 3; ++count) {
60 uint64_t layerId = read64();
61 uint32_t composition = read();
62
63 std::pair<uint64_t, uint32_t> compositionChange(layerId, composition);
64 mCompositionChanges.push_back(compositionChange);
65 }
66 break;
67 case IComposerClient::Command::SET_DISPLAY_REQUESTS:
68 ASSERT_EQ(1, length % 3);
69 read(); // displayRequests, ignored for now
70 for (uint16_t count = 0; count < (length - 1) / 3; ++count) {
71 read64(); // layer
72 // silently eat requests to clear the client target, since we won't be testing
73 // client composition anyway
74 ASSERT_EQ(1u, read());
75 }
76 break;
77 case IComposerClient::Command::SET_PRESENT_FENCE:
78 ASSERT_EQ(1, length);
79 close(readFence());
80 break;
81 case IComposerClient::Command::SET_RELEASE_FENCES:
82 ASSERT_EQ(0, length % 3);
83 for (uint16_t count = 0; count < length / 3; ++count) {
84 read64();
85 close(readFence());
86 }
87 break;
88 default:
89 GTEST_FAIL() << "unexpected return command " << std::hex << static_cast<int>(command);
90 break;
91 }
92 }
93
94 } // namespace vts
95 } // namespace V2_1
96 } // namespace composer
97 } // namespace graphics
98 } // namespace hardware
99 } // namespace android
100