blob: fb09ebd6da2df56012743bd0acd420310c89bc6e [file] [log] [blame]
Enrico Granata15c4ec42017-02-24 14:13:05 -08001/*
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
17package com.android.car.vehiclehal.test;
18
Enrico Granata15c4ec42017-02-24 14:13:05 -080019import static com.android.car.vehiclehal.test.Utils.isVhalPropertyAvailable;
20import static com.android.car.vehiclehal.test.Utils.readVhalProperty;
Kaibbbd0d62019-03-25 15:47:27 -070021
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070022import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertNotNull;
24import static org.junit.Assume.assumeTrue;
Enrico Granata15c4ec42017-02-24 14:13:05 -080025
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070026import android.hardware.automotive.vehicle.V2_0.IVehicle;
Enrico Granata15c4ec42017-02-24 14:13:05 -080027import android.hardware.automotive.vehicle.V2_0.StatusCode;
28import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
Pavel Maltsev99e1a752017-08-24 15:15:05 -070029import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
Enrico Granata15c4ec42017-02-24 14:13:05 -080030import android.os.RemoteException;
31import android.util.Log;
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070032
Enrico Granata15c4ec42017-02-24 14:13:05 -080033import com.android.car.vehiclehal.VehiclePropValueBuilder;
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070034
Enrico Granata15c4ec42017-02-24 14:13:05 -080035import org.junit.Before;
36import org.junit.Test;
37
38/** Test retrieving the OBD2_FREEZE_FRAME property from VHAL */
39public class Obd2FreezeFrameTest {
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070040 private static final String TAG = Utils.concatTag(Obd2FreezeFrameTest.class);
Kaibbbd0d62019-03-25 15:47:27 -070041 private static final int DEFAULT_WAIT_TIMEOUT_MS = 5000;
Enrico Granata15c4ec42017-02-24 14:13:05 -080042 private IVehicle mVehicle = null;
43
44 @Before
45 public void setUp() throws Exception {
Kaibbbd0d62019-03-25 15:47:27 -070046 mVehicle = Utils.getVehicleWithTimeout(DEFAULT_WAIT_TIMEOUT_MS);
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070047 assumeTrue("Freeze frame not available, test-case ignored.", isFreezeFrameAvailable());
Enrico Granata15c4ec42017-02-24 14:13:05 -080048 }
49
50 @Test
51 public void testFreezeFrame() throws RemoteException {
Enrico Granata15c4ec42017-02-24 14:13:05 -080052 readVhalProperty(
53 mVehicle,
54 VehicleProperty.OBD2_FREEZE_FRAME_INFO,
55 (Integer status, VehiclePropValue value) -> {
56 assertEquals(StatusCode.OK, status.intValue());
57 assertNotNull("OBD2_FREEZE_FRAME_INFO is supported; should not be null", value);
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070058 Log.i(TAG, "dump of OBD2_FREEZE_FRAME_INFO:\n" + value);
Enrico Granata15c4ec42017-02-24 14:13:05 -080059 for(long timestamp: value.value.int64Values) {
60 Log.i(TAG, "timestamp: " + timestamp);
61 readVhalProperty(
62 mVehicle,
63 VehiclePropValueBuilder.newBuilder(VehicleProperty.OBD2_FREEZE_FRAME)
64 .setInt64Value(timestamp)
65 .build(),
66 (Integer frameStatus, VehiclePropValue freezeFrame) -> {
67 if (StatusCode.OK == frameStatus.intValue()) {
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070068 assertNotNull("OBD2_FREEZE_FRAME read OK; should not be null",
69 freezeFrame);
70 Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + freezeFrame);
Enrico Granata15c4ec42017-02-24 14:13:05 -080071 assertEquals(freezeFrame.timestamp, timestamp);
72 }
73 return true;
74 });
75 }
76 return true;
77 });
78 }
79
80 private boolean isFreezeFrameAvailable() throws RemoteException {
81 return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME) &&
82 isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME_INFO);
83 }
84}