• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 package android.car.extendedapitest;
17 
18 import static android.hardware.automotive.vehicle.TestVendorProperty.ECHO_REVERSE_BYTES;
19 
20 import static com.android.compatibility.common.util.SystemUtil.runShellCommand;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import static org.junit.Assume.assumeTrue;
25 
26 import android.app.UiAutomation;
27 import android.car.extendedapitest.testbase.CarApiTestBase;
28 
29 import androidx.test.platform.app.InstrumentationRegistry;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 
35 import java.io.IOException;
36 
37 public final class VehicleHalLargeParcelableTest extends CarApiTestBase {
38     // TODO(b/225401892): Change this to a VTS test once ECHO_REVERSE_BYTES is defined as a system
39     // property.
40     private UiAutomation mUiAutomation;
41 
42     @Before
setUp()43     public void setUp() {
44         mUiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
45         mUiAutomation.adoptShellPermissionIdentity(
46                 android.car.Car.PERMISSION_CAR_DIAGNOSTIC_READ_ALL);
47     }
48 
49     @After
tearDown()50     public void tearDown() {
51         mUiAutomation.dropShellPermissionIdentity();
52     }
53 
54     @Test
testEchoReverseBytesSmallData()55     public void testEchoReverseBytesSmallData() throws Exception {
56         // 1k data should be sent through direct payload.
57         echoReverseBytes(1024);
58     }
59 
60     @Test
testEchoReverseBytesLargeData()61     public void testEchoReverseBytesLargeData() throws Exception {
62         // 16k data should be sent through shared memory.
63         echoReverseBytes(16 * 1024);
64     }
65 
echoReverseBytes(int size)66     void echoReverseBytes(int size) throws IOException {
67         String result = runShellCommand(mUiAutomation, "cmd car_service test-echo-reverse-bytes "
68                 + ECHO_REVERSE_BYTES + " " + size);
69         assumeTrue("ECHO_REVERSE_BYTES is not supported", !result.contains("Test Skipped"));
70         assertThat(result).contains("Test Succeeded");
71     }
72 }
73