Merge "Prepare for removal of legacy-test from default targets"
diff --git a/tests/vehiclehal_test/Android.mk b/tests/vehiclehal_test/Android.mk
new file mode 100644
index 0000000..20dd3c7
--- /dev/null
+++ b/tests/vehiclehal_test/Android.mk
@@ -0,0 +1,40 @@
+# 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.
+#
+#
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := VehicleHALTest
+
+LOCAL_CERTIFICATE := platform
+
+LOCAL_MODULE_TAGS := tests
+
+# When built explicitly put it in the data partition
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+LOCAL_STATIC_JAVA_LIBRARIES += vehicle-hal-support-lib \
+ android-support-test \
+ android.hardware.vehicle@2.0-java-static
+
+LOCAL_JAVA_LIBRARIES := android.car android.test.runner
+
+include $(BUILD_PACKAGE)
diff --git a/tests/vehiclehal_test/AndroidManifest.xml b/tests/vehiclehal_test/AndroidManifest.xml
new file mode 100644
index 0000000..765d099
--- /dev/null
+++ b/tests/vehiclehal_test/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.car.vehiclehal.test"
+ android:sharedUserId="android.uid.system" >
+
+ <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.car.vehiclehal.test"
+ android:label="Tests for Vehicle HAL APIs"/>
+
+ <application android:label="VehicleHALTest">
+ <uses-library android:name="android.test.runner" />
+ </application>
+</manifest>
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
new file mode 100644
index 0000000..7770cf8
--- /dev/null
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Obd2LiveFrameTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.vehicle.V2_0.IVehicle;
+import android.hardware.vehicle.V2_0.StatusCode;
+import android.hardware.vehicle.V2_0.VehiclePropValue;
+import android.hardware.vehicle.V2_0.VehicleProperty;
+import android.os.RemoteException;
+import android.util.Log;
+import java.util.Objects;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Test retrieving the OBD2_LIVE_FRAME property from VHAL */
+public class Obd2LiveFrameTest {
+ private static final String TAG = Obd2LiveFrameTest.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 testLiveFrame() throws RemoteException {
+ if (!isLiveFrameAvailable()) {
+ Log.i(TAG, "live frame not available; returning - our job here is done");
+ return;
+ }
+ readVhalProperty(
+ mVehicle,
+ VehicleProperty.OBD2_LIVE_FRAME,
+ (Integer status, VehiclePropValue value) -> {
+ assertEquals(StatusCode.OK, status.intValue());
+ assertNotNull("OBD2_LIVE_FRAME is supported; should not be null", value);
+ Log.i(TAG, "dump of OBD2_LIVE_FRAME:\n" + dumpVehiclePropValue(value));
+ return true;
+ });
+ }
+
+ @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
new file mode 100644
index 0000000..3e79ce8
--- /dev/null
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/Utils.java
@@ -0,0 +1,116 @@
+/*
+ * 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 android.os.SystemClock.elapsedRealtime;
+
+import android.annotation.Nullable;
+import android.hardware.vehicle.V2_0.IVehicle;
+import android.hardware.vehicle.V2_0.VehiclePropConfig;
+import android.hardware.vehicle.V2_0.VehiclePropValue;
+import android.os.RemoteException;
+import android.util.Log;
+import com.android.car.vehiclehal.VehiclePropValueBuilder;
+import java.util.Objects;
+
+final class Utils {
+ private Utils() {}
+
+ private static final String TAG = Utils.class.getSimpleName();
+
+ @Nullable
+ static <T> T tryWithDeadline(long waitMilliseconds, java.util.function.Supplier<T> f) {
+ f = Objects.requireNonNull(f);
+ T object = f.get();
+ long start = elapsedRealtime();
+ while (object == null && (start + waitMilliseconds) > elapsedRealtime()) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Sleep was interrupted", e);
+ }
+
+ object = f.get();
+ }
+ return object;
+ }
+
+ static String dumpVehiclePropValue(VehiclePropValue vpv) {
+ vpv = Objects.requireNonNull(vpv);
+ return "prop = "
+ + vpv.prop
+ + '\n'
+ + "areaId = "
+ + vpv.areaId
+ + '\n'
+ + "timestamp = "
+ + vpv.timestamp
+ + '\n'
+ + "int32Values = "
+ + vpv.value.int32Values
+ + '\n'
+ + "floatValues = "
+ + vpv.value.floatValues
+ + '\n'
+ + "int64Values ="
+ + vpv.value.int64Values
+ + '\n'
+ + "bytes = "
+ + vpv.value.bytes
+ + '\n'
+ + "string = "
+ + vpv.value.stringValue
+ + '\n';
+ }
+
+ static boolean isVhalPropertyAvailable(IVehicle vehicle, int prop) throws RemoteException {
+ return vehicle.getAllPropConfigs()
+ .stream()
+ .anyMatch((VehiclePropConfig config) -> config.prop == prop);
+ }
+
+ static VehiclePropValue readVhalProperty(
+ IVehicle vehicle,
+ int propertyId,
+ java.util.function.BiFunction<Integer, VehiclePropValue, Boolean> f) {
+ return readVhalProperty(vehicle, propertyId, 0, f);
+ }
+
+ static VehiclePropValue readVhalProperty(
+ IVehicle vehicle,
+ 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];
+ }
+}
diff --git a/tools/bootanalyze/bootanalyze.py b/tools/bootanalyze/bootanalyze.py
index 5670cc6..eee5ff8 100755
--- a/tools/bootanalyze/bootanalyze.py
+++ b/tools/bootanalyze/bootanalyze.py
@@ -278,7 +278,7 @@
print '\n* - event time was obtained from dmesg log\n'
- if events[LOGCAT_BOOT_COMPLETE] > error_time:
+ if events[LOGCAT_BOOT_COMPLETE] > error_time and not args.ignore:
now = datetime.now()
bugreport_file = "bugreport-bootuptoolong-%s_%s.zip" % (now.strftime("%Y-%m-%d-%H-%M-%S"), \
str(events[LOGCAT_BOOT_COMPLETE]))