Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 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 com.android.car.vehiclehal.test; |
| 18 | |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 19 | import static com.android.car.vehiclehal.test.Utils.isVhalPropertyAvailable; |
| 20 | import static com.android.car.vehiclehal.test.Utils.readVhalProperty; |
Kai | bbbd0d6 | 2019-03-25 15:47:27 -0700 | [diff] [blame] | 21 | |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 22 | import static org.junit.Assert.assertEquals; |
| 23 | import static org.junit.Assert.assertNotNull; |
| 24 | import static org.junit.Assume.assumeTrue; |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 25 | |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 26 | import android.hardware.automotive.vehicle.V2_0.IVehicle; |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 27 | import android.hardware.automotive.vehicle.V2_0.StatusCode; |
| 28 | import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; |
Pavel Maltsev | 99e1a75 | 2017-08-24 15:15:05 -0700 | [diff] [blame] | 29 | import android.hardware.automotive.vehicle.V2_0.VehicleProperty; |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 30 | import android.os.RemoteException; |
| 31 | import android.util.Log; |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 32 | |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 33 | import com.android.car.vehiclehal.VehiclePropValueBuilder; |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 34 | |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 35 | import org.junit.Before; |
| 36 | import org.junit.Test; |
| 37 | |
| 38 | /** Test retrieving the OBD2_FREEZE_FRAME property from VHAL */ |
| 39 | public class Obd2FreezeFrameTest { |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 40 | private static final String TAG = Utils.concatTag(Obd2FreezeFrameTest.class); |
Kai | bbbd0d6 | 2019-03-25 15:47:27 -0700 | [diff] [blame] | 41 | private static final int DEFAULT_WAIT_TIMEOUT_MS = 5000; |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 42 | private IVehicle mVehicle = null; |
| 43 | |
| 44 | @Before |
| 45 | public void setUp() throws Exception { |
Kai | bbbd0d6 | 2019-03-25 15:47:27 -0700 | [diff] [blame] | 46 | mVehicle = Utils.getVehicleWithTimeout(DEFAULT_WAIT_TIMEOUT_MS); |
Pavel Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 47 | assumeTrue("Freeze frame not available, test-case ignored.", isFreezeFrameAvailable()); |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void testFreezeFrame() throws RemoteException { |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 52 | 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 Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 58 | Log.i(TAG, "dump of OBD2_FREEZE_FRAME_INFO:\n" + value); |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 59 | 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 Maltsev | 82c20cd | 2017-04-11 12:38:17 -0700 | [diff] [blame] | 68 | assertNotNull("OBD2_FREEZE_FRAME read OK; should not be null", |
| 69 | freezeFrame); |
| 70 | Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + freezeFrame); |
Enrico Granata | 15c4ec4 | 2017-02-24 14:13:05 -0800 | [diff] [blame] | 71 | 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 | } |