blob: 0d6048d142ba41f1e9823a798889c14013307496 [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;
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070021import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertNotNull;
23import static org.junit.Assume.assumeTrue;
Enrico Granata15c4ec42017-02-24 14:13:05 -080024
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070025import android.hardware.automotive.vehicle.V2_0.IVehicle;
Enrico Granata15c4ec42017-02-24 14:13:05 -080026import android.hardware.automotive.vehicle.V2_0.StatusCode;
27import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
Pavel Maltsev99e1a752017-08-24 15:15:05 -070028import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
Enrico Granata15c4ec42017-02-24 14:13:05 -080029import android.os.RemoteException;
30import android.util.Log;
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070031
Enrico Granata15c4ec42017-02-24 14:13:05 -080032import com.android.car.vehiclehal.VehiclePropValueBuilder;
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070033
Enrico Granata15c4ec42017-02-24 14:13:05 -080034import org.junit.Before;
35import org.junit.Test;
36
37/** Test retrieving the OBD2_FREEZE_FRAME property from VHAL */
38public class Obd2FreezeFrameTest {
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070039 private static final String TAG = Utils.concatTag(Obd2FreezeFrameTest.class);
Enrico Granata15c4ec42017-02-24 14:13:05 -080040
41 private IVehicle mVehicle = null;
42
43 @Before
44 public void setUp() throws Exception {
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070045 mVehicle = Utils.getVehicle();
46 assumeTrue("Freeze frame not available, test-case ignored.", isFreezeFrameAvailable());
Enrico Granata15c4ec42017-02-24 14:13:05 -080047 }
48
49 @Test
50 public void testFreezeFrame() throws RemoteException {
Enrico Granata15c4ec42017-02-24 14:13:05 -080051 readVhalProperty(
52 mVehicle,
53 VehicleProperty.OBD2_FREEZE_FRAME_INFO,
54 (Integer status, VehiclePropValue value) -> {
55 assertEquals(StatusCode.OK, status.intValue());
56 assertNotNull("OBD2_FREEZE_FRAME_INFO is supported; should not be null", value);
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070057 Log.i(TAG, "dump of OBD2_FREEZE_FRAME_INFO:\n" + value);
Enrico Granata15c4ec42017-02-24 14:13:05 -080058 for(long timestamp: value.value.int64Values) {
59 Log.i(TAG, "timestamp: " + timestamp);
60 readVhalProperty(
61 mVehicle,
62 VehiclePropValueBuilder.newBuilder(VehicleProperty.OBD2_FREEZE_FRAME)
63 .setInt64Value(timestamp)
64 .build(),
65 (Integer frameStatus, VehiclePropValue freezeFrame) -> {
66 if (StatusCode.OK == frameStatus.intValue()) {
Pavel Maltsev82c20cd2017-04-11 12:38:17 -070067 assertNotNull("OBD2_FREEZE_FRAME read OK; should not be null",
68 freezeFrame);
69 Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + freezeFrame);
Enrico Granata15c4ec42017-02-24 14:13:05 -080070 assertEquals(freezeFrame.timestamp, timestamp);
71 }
72 return true;
73 });
74 }
75 return true;
76 });
77 }
78
79 private boolean isFreezeFrameAvailable() throws RemoteException {
80 return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME) &&
81 isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME_INFO);
82 }
83}