• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package android.car.hiddenapitest;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.junit.Assume.assumeTrue;
22 
23 import android.car.Car;
24 import android.car.diagnostic.CarDiagnosticEvent;
25 import android.car.diagnostic.CarDiagnosticManager;
26 import android.car.extendedapitest.testbase.CarApiTestBase;
27 
28 import androidx.test.filters.MediumTest;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 
33 @MediumTest
34 public final class CarDiagnosticManagerTest extends CarApiTestBase {
35 
36     private static final String TAG = CarDiagnosticManagerTest.class.getSimpleName();
37 
38     private CarDiagnosticManager mCarDiagnosticManager;
39 
40     @Before
setUp()41     public void setUp() throws Exception {
42         Car car = getCar();
43         assumeTrue(car.isFeatureEnabled(Car.DIAGNOSTIC_SERVICE));
44         mCarDiagnosticManager = (CarDiagnosticManager) car.getCarManager(Car.DIAGNOSTIC_SERVICE);
45         assertThat(mCarDiagnosticManager).isNotNull();
46     }
47 
48     /**
49      * Test that we can read live frame data over the diagnostic manager
50      *
51      * @throws Exception
52      */
53     @Test
testLiveFrame()54     public void testLiveFrame() throws Exception {
55         CarDiagnosticEvent liveFrame = mCarDiagnosticManager.getLatestLiveFrame();
56         if (null != liveFrame) {
57             assertThat(liveFrame.isLiveFrame()).isTrue();
58             assertThat(liveFrame.isEmptyFrame()).isFalse();
59         }
60     }
61 
62     /**
63      * Test that we can read well-formed freeze frame data over the diagnostic manager
64      *
65      * @throws Exception
66      */
67     @Test
testFreezeFrames()68     public void testFreezeFrames() throws Exception {
69         long[] timestamps = mCarDiagnosticManager.getFreezeFrameTimestamps();
70         if (null != timestamps) {
71             for (long timestamp : timestamps) {
72                 CarDiagnosticEvent freezeFrame = mCarDiagnosticManager.getFreezeFrame(timestamp);
73                 assertThat(freezeFrame).isNotNull();
74                 assertThat(freezeFrame.timestamp).isEqualTo(timestamp);
75                 assertThat(freezeFrame.isFreezeFrame()).isTrue();
76                 assertThat(freezeFrame.isEmptyFrame()).isFalse();
77                 assertThat(freezeFrame.dtc).isNotEmpty();
78             }
79         }
80     }
81 }
82