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