diff options
author | Enrico Granata <egranata@google.com> | 2017-02-24 14:13:05 -0800 |
---|---|---|
committer | Enrico Granata <egranata@google.com> | 2017-02-24 14:13:05 -0800 |
commit | 15c4ec4a4735440f36847dd24e0d602b66edfd94 (patch) | |
tree | ee3b86b7d1673c12bc77795e0c72d638a562a707 /tests/vehiclehal_test | |
parent | 15ba610af04a4b517863c8f93dd79e229fe4ab8c (diff) | |
download | Car-15c4ec4a4735440f36847dd24e0d602b66edfd94.tar.gz |
Add a test case for reading freeze frame data from Vehicle HAL.
Test: runtest -x packages/services/Car/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2FreezeFrameTest.java
Bug: 34279245
Change-Id: Iaaef24e9c1fa627a3283b46f9226606b227c732b
Diffstat (limited to 'tests/vehiclehal_test')
3 files changed, 133 insertions, 40 deletions
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2FreezeFrameTest.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2FreezeFrameTest.java new file mode 100644 index 0000000000..63f00a80b4 --- /dev/null +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2FreezeFrameTest.java @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.car.vehiclehal.test; + +import static com.android.car.vehiclehal.test.Utils.dumpVehiclePropValue; +import static com.android.car.vehiclehal.test.Utils.isVhalPropertyAvailable; +import static com.android.car.vehiclehal.test.Utils.readVhalProperty; +import static com.android.car.vehiclehal.test.Utils.tryWithDeadline; +import static org.junit.Assert.*; + +import android.annotation.Nullable; +import android.hardware.automotive.vehicle.V2_0.StatusCode; +import android.hardware.automotive.vehicle.V2_0.VehiclePropValue; +import android.hardware.automotive.vehicle.V2_1.IVehicle; +import android.hardware.automotive.vehicle.V2_1.VehicleProperty; +import android.os.RemoteException; +import android.util.Log; +import com.android.car.vehiclehal.VehiclePropValueBuilder; +import java.util.Objects; +import org.junit.Before; +import org.junit.Test; + +/** Test retrieving the OBD2_FREEZE_FRAME property from VHAL */ +public class Obd2FreezeFrameTest { + private static final String TAG = Obd2FreezeFrameTest.class.getSimpleName(); + private static final String VEHICLE_SERVICE_NAME = "Vehicle"; + private static final long WAIT_FOR_VEHICLE_HAL_TIMEOUT_MS = 10_000; + + private IVehicle mVehicle = null; + + @Before + public void setUp() throws Exception { + mVehicle = Objects.requireNonNull(getVehicle(WAIT_FOR_VEHICLE_HAL_TIMEOUT_MS)); + } + + @Nullable + private IVehicle getVehicle(long waitMilliseconds) { + return tryWithDeadline( + waitMilliseconds, + () -> { + try { + return IVehicle.getService(VEHICLE_SERVICE_NAME); + } catch (RemoteException e) { + Log.w( + TAG, + "attempt to get IVehicle service " + + VEHICLE_SERVICE_NAME + + " caused RemoteException: ", + e); + return null; + } + }); + } + + @Test + public void testFreezeFrame() throws RemoteException { + if (!isFreezeFrameAvailable()) { + Log.i(TAG, "freeze frame not available; returning - our job here is done"); + return; + } + readVhalProperty( + mVehicle, + VehicleProperty.OBD2_FREEZE_FRAME_INFO, + (Integer status, VehiclePropValue value) -> { + assertEquals(StatusCode.OK, status.intValue()); + assertNotNull("OBD2_FREEZE_FRAME_INFO is supported; should not be null", value); + Log.i(TAG, "dump of OBD2_FREEZE_FRAME_INFO:\n" + dumpVehiclePropValue(value)); + for(long timestamp: value.value.int64Values) { + Log.i(TAG, "timestamp: " + timestamp); + readVhalProperty( + mVehicle, + VehiclePropValueBuilder.newBuilder(VehicleProperty.OBD2_FREEZE_FRAME) + .setInt64Value(timestamp) + .build(), + (Integer frameStatus, VehiclePropValue freezeFrame) -> { + if (StatusCode.OK == frameStatus.intValue()) { + assertNotNull("OBD2_FREEZE_FRAME read OK; should not be null", freezeFrame); + Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + dumpVehiclePropValue(freezeFrame)); + assertEquals(freezeFrame.timestamp, timestamp); + } + return true; + }); + } + return true; + }); + } + + private boolean isFreezeFrameAvailable() throws RemoteException { + return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME) && + isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME_INFO); + } +} diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2LiveFrameTest.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2LiveFrameTest.java index 4cdb403f17..c304fa54ba 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2LiveFrameTest.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2LiveFrameTest.java @@ -78,28 +78,7 @@ public class Obd2LiveFrameTest { }); } - @Test - public void testFreezeFrame() throws RemoteException { - if (!isFreezeFrameAvailable()) { - Log.i(TAG, "freeze frame not available; returning - our job here is done"); - return; - } - readVhalProperty( - mVehicle, - VehicleProperty.OBD2_FREEZE_FRAME, - (Integer status, VehiclePropValue value) -> { - assertEquals(StatusCode.OK, status.intValue()); - assertNotNull("OBD2_FREEZE_FRAME is supported; should not be null", value); - Log.i(TAG, "dump of OBD2_FREEZE_FRAME:\n" + dumpVehiclePropValue(value)); - return true; - }); - } - private boolean isLiveFrameAvailable() throws RemoteException { return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_LIVE_FRAME); } - - private boolean isFreezeFrameAvailable() throws RemoteException { - return isVhalPropertyAvailable(mVehicle, VehicleProperty.OBD2_FREEZE_FRAME); - } } diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java index c205fcc709..67c5c2d6e1 100644 --- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java +++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java @@ -84,9 +84,31 @@ final class Utils { } static VehiclePropValue readVhalProperty( - IVehicle vehicle, - int propertyId, - java.util.function.BiFunction<Integer, VehiclePropValue, Boolean> f) { + IVehicle vehicle, + VehiclePropValue request, + java.util.function.BiFunction<Integer, VehiclePropValue, Boolean> f) { + vehicle = Objects.requireNonNull(vehicle); + request = Objects.requireNonNull(request); + VehiclePropValue vpv[] = new VehiclePropValue[] {null}; + try { + vehicle.get( + request, + (int status, VehiclePropValue propValue) -> { + if (f.apply(status, propValue)) { + vpv[0] = propValue; + } + }); + } catch (RemoteException e) { + Log.w(TAG, "attempt to read VHAL property " + + dumpVehiclePropValue(request) + " caused RemoteException: ", e); + } + return vpv[0]; + } + + static VehiclePropValue readVhalProperty( + IVehicle vehicle, + int propertyId, + java.util.function.BiFunction<Integer, VehiclePropValue, Boolean> f) { return readVhalProperty(vehicle, propertyId, 0, f); } @@ -95,22 +117,8 @@ final class Utils { int propertyId, int areaId, java.util.function.BiFunction<Integer, VehiclePropValue, Boolean> f) { - vehicle = Objects.requireNonNull(vehicle); VehiclePropValue request = - VehiclePropValueBuilder.newBuilder(propertyId).setAreaId(areaId).build(); - VehiclePropValue vpv[] = new VehiclePropValue[] {null}; - try { - vehicle.get( - request, - (int status, VehiclePropValue propValue) -> { - if (f.apply(status, propValue)) { - vpv[0] = propValue; - } - }); - } catch (RemoteException e) { - Log.w(TAG, "attempt to read VHAL property 0x" + Integer.toHexString(propertyId) - + " from area " + areaId + " caused RemoteException: ", e); - } - return vpv[0]; + VehiclePropValueBuilder.newBuilder(propertyId).setAreaId(areaId).build(); + return readVhalProperty(vehicle, request, f); } } |