summaryrefslogtreecommitdiff
path: root/hostsidetests/hdmicec/src/android/hdmicec/cts/common/HdmiCecSystemInformationTest.java
blob: 06c6e7ca8f3bc080bcade63d02068901dd101e5c (plain)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
 * 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.
 */

package android.hdmicec.cts.common;

import static android.hdmicec.cts.HdmiCecConstants.TIMEOUT_SAFETY_MS;

import static com.google.common.truth.Truth.assertThat;

import android.hdmicec.cts.BaseHdmiCecCtsTest;
import android.hdmicec.cts.CecMessage;
import android.hdmicec.cts.CecOperand;
import android.hdmicec.cts.HdmiCecConstants;
import android.hdmicec.cts.LogicalAddress;

import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.util.RunUtil;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;

import java.util.Arrays;
import java.util.List;

/** HDMI CEC system information tests (Section 11.2.6) */
@RunWith(DeviceJUnit4ClassRunner.class)
public final class HdmiCecSystemInformationTest extends BaseHdmiCecCtsTest {

    @Rule
    public RuleChain ruleChain =
            RuleChain
                    .outerRule(CecRules.requiresCec(this))
                    .around(CecRules.requiresLeanback(this))
                    .around(CecRules.requiresPhysicalDevice(this))
                    .around(hdmiCecClient);

    /**
     * Tests 11.2.6-2, 10.1.1.1-1
     *
     * <p>Tests that the device sends a {@code <Report Physical Address>} in response to a {@code
     * <Give Physical Address>}
     */
    @Test
    public void cect_11_2_6_2_GivePhysicalAddress() throws Exception {
        List<LogicalAddress> testDevices =
                Arrays.asList(
                        LogicalAddress.TV,
                        LogicalAddress.RECORDER_1,
                        LogicalAddress.TUNER_1,
                        LogicalAddress.PLAYBACK_1,
                        LogicalAddress.AUDIO_SYSTEM,
                        LogicalAddress.BROADCAST);
        for (LogicalAddress testDevice : testDevices) {
            if (hasLogicalAddress(testDevice)) {
                /* Skip the DUT logical address */
                continue;
            }
            hdmiCecClient.sendCecMessage(testDevice, CecOperand.GIVE_PHYSICAL_ADDRESS);
            String message = hdmiCecClient.checkExpectedOutput(CecOperand.REPORT_PHYSICAL_ADDRESS);
            /* Check that the physical address taken is valid. */
            CecMessage.assertPhysicalAddressValid(message, getDumpsysPhysicalAddress());
            int receivedParams = CecMessage.getParams(message);
            assertThat(hasDeviceType(receivedParams & 0xFF)).isTrue();
        }
    }

    /**
     * Tests {@code <Report Features>}
     *
     * <p>Tests that the device reports the correct information in {@code <Report Features>} in
     * response to a {@code <Give Features>} message.
     */
    @Test
    public void cect_reportFeatures_deviceTypeContainedInAllDeviceTypes() throws Exception {
        setCec20();
        List<LogicalAddress> testDevices =
                Arrays.asList(
                        LogicalAddress.TV,
                        LogicalAddress.RECORDER_1,
                        LogicalAddress.TUNER_1,
                        LogicalAddress.PLAYBACK_1,
                        LogicalAddress.AUDIO_SYSTEM,
                        LogicalAddress.BROADCAST);
        for (LogicalAddress testDevice : testDevices) {
            if (hasLogicalAddress(testDevice)) {
                /* Skip the DUT logical address */
                continue;
            }
            hdmiCecClient.sendCecMessage(testDevice, CecOperand.GIVE_FEATURES);
            String message = hdmiCecClient.checkExpectedOutput(CecOperand.REPORT_FEATURES);
            int receivedParams = CecMessage.getParams(message, 2, 4);

            int deviceType = 0;
            for (LogicalAddress address : mDutLogicalAddresses) {
                switch (address.getDeviceType()) {
                    case HdmiCecConstants.CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
                        deviceType |= 1 << 4;
                        break;
                    case HdmiCecConstants.CEC_DEVICE_TYPE_TV:
                        deviceType |= 1 << 7;
                        break;
                    case HdmiCecConstants.CEC_DEVICE_TYPE_AUDIO_SYSTEM:
                        deviceType |= 1 << 3;
                        break;
                    case HdmiCecConstants.CEC_DEVICE_TYPE_RECORDER:
                        deviceType |= 1 << 6;
                        break;
                    case HdmiCecConstants.CEC_DEVICE_TYPE_TUNER:
                        deviceType |= 1 << 5;
                        break;
                    case HdmiCecConstants.CEC_DEVICE_TYPE_RESERVED:
                        break;
                }
            }

            assertThat(receivedParams & deviceType).isNotEqualTo(1);
        }
    }

    /**
     * Test 11.2.6-6
     * Tests that the device sends a {@code <CEC Version>} in response to a {@code <Get CEC
     * Version>}
     */
    @Test
    public void cect_11_2_6_6_GiveCecVersion() throws Exception {
        int cecVersion = HdmiCecConstants.CEC_VERSION_1_4;

        hdmiCecClient.sendCecMessage(hdmiCecClient.getSelfDevice(), CecOperand.GET_CEC_VERSION);
        String message =
                hdmiCecClient.checkExpectedOutput(
                        hdmiCecClient.getSelfDevice(), CecOperand.CEC_VERSION);
        assertThat(CecMessage.getParams(message)).isEqualTo(cecVersion);
    }

    /**
     * Test HF4-2-12
     * Tests that the device sends a {@code <CEC Version>} with correct version argument in
     * response to a {@code <Get CEC Version>} message.
     *
     * Also verifies that the CEC version reported in {@code <Report Features>} matches the CEC
     * version reported in {@code <CEC Version>}.
     */
    @Test
    public void cect_hf4_2_12_GiveCecVersion() throws Exception {
        int cecVersion = HdmiCecConstants.CEC_VERSION_2_0;
        setCec20();

        hdmiCecClient.sendCecMessage(hdmiCecClient.getSelfDevice(), CecOperand.GET_CEC_VERSION);
        String reportCecVersion = hdmiCecClient.checkExpectedOutput(hdmiCecClient.getSelfDevice(),
                CecOperand.CEC_VERSION);
        assertThat(CecMessage.getParams(reportCecVersion)).isEqualTo(cecVersion);

        RunUtil.getDefault().sleep(TIMEOUT_SAFETY_MS);

        hdmiCecClient.sendCecMessage(hdmiCecClient.getSelfDevice(), CecOperand.GIVE_FEATURES);
        String reportFeatures = hdmiCecClient.checkExpectedOutput(LogicalAddress.BROADCAST,
                CecOperand.REPORT_FEATURES);
        assertThat(CecMessage.getParams(reportFeatures, 2)).isEqualTo(cecVersion);
    }

    /**
     * Tests that the device sends a {@code <CEC Version>} in response to a {@code <Get CEC
     * Version>} in standby
     */
    @Test
    public void cectGiveCecVersionInStandby() throws Exception {
        ITestDevice device = getDevice();
        try {
            sendDeviceToSleepAndValidate();
            hdmiCecClient.sendCecMessage(hdmiCecClient.getSelfDevice(), CecOperand.GET_CEC_VERSION);
            String message =
                    hdmiCecClient.checkExpectedOutputOrFeatureAbort(
                            hdmiCecClient.getSelfDevice(),
                            CecOperand.CEC_VERSION,
                            CecOperand.GET_CEC_VERSION,
                            HdmiCecConstants.ABORT_NOT_IN_CORRECT_MODE);
            assertThat(CecMessage.getParams(message))
                    .isIn(
                            Arrays.asList(
                                    HdmiCecConstants.CEC_VERSION_2_0,
                                    HdmiCecConstants.CEC_VERSION_1_4));
        } finally {
            wakeUpDevice();
        }
    }

    /**
     * Test HF4-2-16 (CEC 2.0)
     *
     * <p>Tests that the DUT responds to a {@code <Give Device Vendor Id>} with a {@code <Device
     * Vendor ID>} message or a {@code <Feature Abort>[Unrecognized Opcode]}
     */
    @Test
    public void cect_hf_4_2_16_GiveDeviceVendorId() throws Exception {
        ITestDevice device = getDevice();
        setCec20();
        hdmiCecClient.sendCecMessage(
                hdmiCecClient.getSelfDevice(), CecOperand.GIVE_DEVICE_VENDOR_ID);
        String message =
                hdmiCecClient.checkExpectedOutputOrFeatureAbort(
                        LogicalAddress.BROADCAST,
                        CecOperand.DEVICE_VENDOR_ID,
                        CecOperand.GIVE_DEVICE_VENDOR_ID,
                        HdmiCecConstants.ABORT_UNRECOGNIZED_MODE);
        if (CecMessage.getOperand(message) == CecOperand.GIVE_DEVICE_VENDOR_ID) {
            assertThat(CecMessage.getParams(message))
                    .isNotEqualTo(HdmiCecConstants.INVALID_VENDOR_ID);
        }
    }

    /**
     * Test HF4-2-17 (CEC 2.0)
     *
     * <p>Tests that the DUT responds to a {@code <Vendor Command with Id>} that has an incorrect or
     * unrecognised Vendor ID with a {@code <Feature Abort>} message with an appropriate reason.
     */
    @Test
    public void cect_hf_4_2_17_VendorCommandWithIncorrectId() throws Exception {
        ITestDevice device = getDevice();
        setCec20();
        long vendorId = 0xBADDAD;
        String vendorCommandParams =
                CecMessage.formatParams(vendorId, 6) + CecMessage.formatParams("01DBF7E498");
        String featureAbortRefused =
                CecOperand.VENDOR_COMMAND_WITH_ID.toString()
                        + String.format("%02d", HdmiCecConstants.ABORT_REFUSED);
        String featureAbortUnrecognised =
                CecOperand.VENDOR_COMMAND_WITH_ID.toString()
                        + String.format("%02d", HdmiCecConstants.ABORT_UNRECOGNIZED_MODE);

        hdmiCecClient.sendCecMessage(
                hdmiCecClient.getSelfDevice(), CecOperand.GIVE_DEVICE_VENDOR_ID);

        String message =
                hdmiCecClient.checkExpectedOutput(
                        LogicalAddress.BROADCAST, CecOperand.DEVICE_VENDOR_ID);
        if (CecMessage.getParams(message) == vendorId) {
            // Device has the same vendor ID used in test, change it.
            vendorId += 1;
        }
        LogicalAddress cecClientDevice = hdmiCecClient.getSelfDevice();
        hdmiCecClient.sendCecMessage(
                cecClientDevice,
                LogicalAddress.BROADCAST,
                CecOperand.DEVICE_VENDOR_ID,
                CecMessage.formatParams(vendorId, 6));
        hdmiCecClient.sendCecMessage(
                cecClientDevice, CecOperand.VENDOR_COMMAND_WITH_ID, vendorCommandParams);
        message = hdmiCecClient.checkExpectedOutput(cecClientDevice, CecOperand.FEATURE_ABORT);
        if (!CecMessage.getParamsAsString(message).equals(featureAbortRefused)
                && !CecMessage.getParamsAsString(message).equals(featureAbortUnrecognised)) {
            throw new Exception("Feature Abort reason is not REFUSED(0x04) or UNRECOGNIZED(0x00)");
        }
    }
}