Use VHAL debug interface.
Instead of using special properites, use VHAL's debug interface
to send debug commands.
Test: atest VehicleHalTest
Bug: 193565753
Change-Id: Ia0065071c469d833e227933a6753b978571e9258
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java
index 24ee1ff..8a9c85f 100644
--- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/E2eCarTestBase.java
@@ -16,7 +16,6 @@
package com.android.car.vehiclehal.test;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeTrue;
import android.car.Car;
import android.car.hardware.CarPropertyValue;
@@ -24,7 +23,6 @@
import android.content.Context;
import android.content.ServiceConnection;
import android.hardware.automotive.vehicle.V2_0.IVehicle;
-import android.hardware.automotive.vehicle.V2_0.StatusCode;
import android.os.ConditionVariable;
import android.os.FileUtils;
import android.os.IBinder;
@@ -32,8 +30,6 @@
import androidx.test.InstrumentationRegistry;
-import com.google.android.collect.Lists;
-
import org.json.JSONException;
import org.junit.After;
import org.junit.Before;
@@ -57,9 +53,6 @@
@Before
public void connectToVehicleHal() throws Exception {
mVehicle = Utils.getVehicleWithTimeout(DEFAULT_WAIT_TIMEOUT_MS);
- mVehicle.getPropConfigs(
- Lists.newArrayList(VhalEventGenerator.GENERATE_FAKE_DATA_CONTROLLING_PROPERTY),
- (status, propConfigs) -> assumeTrue(status == StatusCode.OK));
}
@Before
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/JsonVhalEventGenerator.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/JsonVhalEventGenerator.java
index 4560b8c..84e6886 100644
--- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/JsonVhalEventGenerator.java
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/JsonVhalEventGenerator.java
@@ -18,18 +18,15 @@
import static org.junit.Assert.assertEquals;
import android.hardware.automotive.vehicle.V2_0.IVehicle;
-import android.hardware.automotive.vehicle.V2_0.StatusCode;
-import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
-import android.os.RemoteException;
-
-import com.android.car.vehiclehal.VehiclePropValueBuilder;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
class JsonVhalEventGenerator implements VhalEventGenerator {
// Exactly one iteration is required for JSON-based end-to-end test
- private static final int NUM_OF_ITERATION = 1;
+ private static final String NUM_OF_ITERATION = "1";
private IVehicle mVehicle;
private File mFile;
@@ -47,22 +44,27 @@
}
@Override
- public void start() throws RemoteException {
- VehiclePropValue request =
- VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
- .addIntValue(CMD_START_JSON, NUM_OF_ITERATION)
- .setStringValue(mFile.getAbsolutePath())
- .build();
- assertEquals(StatusCode.OK, mVehicle.set(request));
+ public void start() throws Exception {
+ ArrayList<String> options = new ArrayList<String>(Arrays.asList(
+ "--debughal", "--genfakedata", "--startjson", mFile.getAbsolutePath(),
+ NUM_OF_ITERATION));
+
+ NativePipeHelper pipe = new NativePipeHelper();
+ pipe.create();
+ mVehicle.debug(pipe.getNativeHandle(), options);
+ assertEquals("", pipe.getOutput());
+ pipe.close();
}
@Override
- public void stop() throws RemoteException {
- VehiclePropValue request =
- VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
- .addIntValue(CMD_STOP_JSON)
- .setStringValue(mFile.getAbsolutePath())
- .build();
- assertEquals(StatusCode.OK, mVehicle.set(request));
+ public void stop() throws Exception {
+ ArrayList<String> options = new ArrayList<String>(Arrays.asList(
+ "--debughal", "--genfakedata", "--stopjson",
+ mFile.getAbsolutePath()));
+ NativePipeHelper pipe = new NativePipeHelper();
+ pipe.create();
+ mVehicle.debug(pipe.getNativeHandle(), options);
+ assertEquals("", pipe.getOutput());
+ pipe.close();
}
}
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/LinearVhalEventGenerator.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/LinearVhalEventGenerator.java
index 856e1fc..8588ac4 100644
--- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/LinearVhalEventGenerator.java
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/LinearVhalEventGenerator.java
@@ -18,13 +18,10 @@
import static org.junit.Assert.assertEquals;
import android.hardware.automotive.vehicle.V2_0.IVehicle;
-import android.hardware.automotive.vehicle.V2_0.StatusCode;
-import android.hardware.automotive.vehicle.V2_0.VehiclePropValue;
-import android.os.RemoteException;
-
-import com.android.car.vehiclehal.VehiclePropValueBuilder;
import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
class LinearVhalEventGenerator implements VhalEventGenerator {
@@ -76,22 +73,29 @@
}
@Override
- public void start() throws RemoteException {
- VehiclePropValue request =
- VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
- .addIntValue(CMD_START_LINEAR, mProp)
- .setInt64Value(mInterval.toNanos())
- .addFloatValue(mInitialValue, mDispersion, mIncrement)
- .build();
- assertEquals(StatusCode.OK, mVehicle.set(request));
+ public void start() throws Exception {
+ ArrayList<String> options = new ArrayList<String>(Arrays.asList(
+ "--debughal", "--genfakedata", "--startlinear", String.format("%d", mProp),
+ String.format("%f", mInitialValue), String.format("%f", mInitialValue),
+ String.format("%f", mDispersion), String.format("%f", mIncrement),
+ String.format("%d", mInterval.toNanos())));
+
+ NativePipeHelper pipe = new NativePipeHelper();
+ pipe.create();
+ mVehicle.debug(pipe.getNativeHandle(), options);
+ assertEquals("", pipe.getOutput());
+ pipe.close();
}
@Override
- public void stop() throws RemoteException {
- VehiclePropValue request =
- VehiclePropValueBuilder.newBuilder(GENERATE_FAKE_DATA_CONTROLLING_PROPERTY)
- .addIntValue(CMD_STOP_LINEAR, mProp)
- .build();
- assertEquals(StatusCode.OK, mVehicle.set(request));
+ public void stop() throws Exception {
+ ArrayList<String> options = new ArrayList<String>(Arrays.asList(
+ "--debughal", "--genfakedata", "--stoplinear",
+ String.format("%d", mProp)));
+ NativePipeHelper pipe = new NativePipeHelper();
+ pipe.create();
+ mVehicle.debug(pipe.getNativeHandle(), options);
+ assertEquals("", pipe.getOutput());
+ pipe.close();
}
}
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/NativePipeHelper.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/NativePipeHelper.java
new file mode 100644
index 0000000..c19be3c
--- /dev/null
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/NativePipeHelper.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2021 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 android.os.NativeHandle;
+import android.os.ParcelFileDescriptor;
+
+import java.io.IOException;
+
+// A helper class to create a native pipe used in debug functions.
+final class NativePipeHelper {
+ // The maximum size of the output buffer during the test.
+ private static final int BUFFER_SIZE = 10_240;
+
+ private ParcelFileDescriptor mWriter;
+ private ParcelFileDescriptor.AutoCloseInputStream mReadStream;
+
+ public void create() throws IOException {
+ ParcelFileDescriptor[] pipe;
+ pipe = ParcelFileDescriptor.createPipe();
+ ParcelFileDescriptor reader = new ParcelFileDescriptor(pipe[0]);
+ mReadStream = new ParcelFileDescriptor.AutoCloseInputStream(reader);
+ mWriter = new ParcelFileDescriptor(pipe[1]);
+ }
+
+ public NativeHandle getNativeHandle() {
+ return new NativeHandle(mWriter.getFileDescriptor(), false);
+ }
+
+ public String getOutput() throws IOException {
+ if (mReadStream.available() == 0) {
+ return "";
+ }
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int size = mReadStream.read(buffer);
+ return new String(buffer, 0, size);
+ }
+
+ public void close() throws IOException {
+ mWriter.close();
+ mReadStream.close();
+ }
+}
diff --git a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventGenerator.java b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventGenerator.java
index b71bf6c..a429302 100644
--- a/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventGenerator.java
+++ b/tests/vehiclehal_test/src/com/android/car/vehiclehal/test/VhalEventGenerator.java
@@ -15,25 +15,8 @@
*/
package com.android.car.vehiclehal.test;
-import android.hardware.automotive.vehicle.V2_0.VehicleArea;
-import android.hardware.automotive.vehicle.V2_0.VehiclePropertyGroup;
-import android.hardware.automotive.vehicle.V2_0.VehiclePropertyType;
-import android.os.RemoteException;
-
interface VhalEventGenerator {
- /**
- * The following property controls VHAL to start/stop linear fake data generation process.
- * It must match kGenerateFakeDataControllingProperty that is defined in default VHAL
- * implementation:
- *
- * hardware/interfaces/automotive/vehicle/2.0/default/impl/vhal_v2_0/DefaultConfig.h
- */
- int GENERATE_FAKE_DATA_CONTROLLING_PROPERTY = 0x0666
- | VehiclePropertyGroup.VENDOR
- | VehicleArea.GLOBAL
- | VehiclePropertyType.MIXED;
-
// Command bits sent via GENERATE_FAKE_DATA_CONTROLLING_PROPERTY to control fake data generation
int CMD_START_LINEAR = 0; // Start linear fake data generation
int CMD_STOP_LINEAR = 1; // Stop linear fake data generation
@@ -44,15 +27,15 @@
* Asynchronous call to tell VHAL to start fake event generation. VHAL will start generating
* data after this call
*
- * @throws RemoteException
+ * @throws Exception
*/
- void start() throws RemoteException;
+ void start() throws Exception;
/**
* Synchronous call to tell VHAL to stop fake event generation. VHAL should always stopped
* generating data after this call.
*
- * @throws RemoteException
+ * @throws Exception
*/
- void stop() throws RemoteException;
+ void stop() throws Exception;
}