Loading automotive/vehicle/TEST_MAPPING +6 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,12 @@ { "name": "VehicleHalVehicleUtilsTest" }, { "name": "VehiclePropertyAnnotationCppTest" }, { "name": "VehiclePropertyAnnotationJavaTest" }, { "name": "FakeVehicleHardwareTest" }, Loading automotive/vehicle/aidl/aidl_test/Android.bp +23 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ package { cc_test { name: "VehicleHalAidlHidlCompatibilityTest", srcs: ["*.cpp"], srcs: ["AidlHidlCompatibilityTest.cpp"], shared_libs: [ "libbinder_ndk", "libhidlbase", Loading @@ -35,3 +35,25 @@ cc_test { test_suites: ["device-tests"], vendor: true, } cc_test { name: "VehiclePropertyAnnotationCppTest", srcs: ["VehiclePropertyAnnotationCppTest.cpp"], header_libs: ["IVehicleGeneratedHeaders"], defaults: ["VehicleHalInterfaceDefaults"], test_suites: ["general-tests"], } android_test { name: "VehiclePropertyAnnotationJavaTest", srcs: [ "VehiclePropertyAnnotationJavaTest.java", ":IVehicleGeneratedJavaFiles", ], static_libs: [ "android.hardware.automotive.vehicle-V2-java", "androidx.test.runner", "truth-prebuilt", ], test_suites: ["general-tests"], } automotive/vehicle/aidl/aidl_test/AndroidManifest.xml 0 → 100644 +26 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 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="android.hardware.automotive.vehicle" > <application/> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" android:targetPackage="android.hardware.automotive.vehicle" android:label="test to verify VHAL annotation"/> </manifest> No newline at end of file automotive/vehicle/aidl/aidl_test/VehiclePropertyAnnotationCppTest.cpp 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 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. */ #include <AccessForVehicleProperty.h> #include <ChangeModeForVehicleProperty.h> #include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h> #include <gtest/gtest.h> #include <unordered_set> namespace aidl_vehicle = ::aidl::android::hardware::automotive::vehicle; using aidl_vehicle::AccessForVehicleProperty; using aidl_vehicle::ChangeModeForVehicleProperty; using aidl_vehicle::VehicleProperty; namespace { template<class T> bool doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty, T> annotationMap) { for (const VehicleProperty& v : ::ndk::enum_range<VehicleProperty>()) { std::string name = aidl_vehicle::toString(v); if (name == "INVALID") { continue; } if (annotationMap.find(v) == annotationMap.end()) { return false; } } return true; } } // namespace TEST(VehiclePropertyAnnotationCppTest, testChangeMode) { ASSERT_TRUE(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty)) << "Outdated annotation-generated AIDL files. Please run " << "generate_annotation_enums.py to update."; } TEST(VehiclePropertyAnnotationCppTest, testAccess) { ASSERT_TRUE(doesAnnotationMapContainsAllProps(AccessForVehicleProperty)) << "Outdated annotation-generated AIDL files. Please run " << "generate_annotation_enums.py to update."; } automotive/vehicle/aidl/aidl_test/VehiclePropertyAnnotationJavaTest.java 0 → 100644 +60 −0 Original line number Diff line number Diff line package android.hardware.automotive.vehicle; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.fail; import androidx.test.filters.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Map; @RunWith(JUnit4.class) public class VehiclePropertyAnnotationJavaTest { private boolean doesAnnotationMapContainsAllProps(Map<Integer, Integer> annotationMap) { for (Field field : VehicleProperty.class.getDeclaredFields()) { int modifiers = field.getModifiers(); try { if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && Modifier.isPublic(modifiers) && field.getType().equals(int.class)) { int propId = field.getInt(/* obj= */ null); if (propId == VehicleProperty.INVALID) { // Skip INVALID_PROP. continue; } if (annotationMap.get(propId) == null) { return false; } } } catch (IllegalAccessException e) { throw new IllegalStateException( "Cannot access a member for VehicleProperty.class", e); } } return true; } @Test @SmallTest public void testChangeMode() { assertWithMessage("Outdated annotation-generated AIDL files. Please run " + "generate_annotation_enums.py to update.") .that(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty.values)) .isTrue(); } @Test @SmallTest public void testAccess() { assertWithMessage("Outdated annotation-generated AIDL files. Please run " + "generate_annotation_enums.py to update.") .that(doesAnnotationMapContainsAllProps(AccessForVehicleProperty.values)) .isTrue(); } } No newline at end of file Loading
automotive/vehicle/TEST_MAPPING +6 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,12 @@ { "name": "VehicleHalVehicleUtilsTest" }, { "name": "VehiclePropertyAnnotationCppTest" }, { "name": "VehiclePropertyAnnotationJavaTest" }, { "name": "FakeVehicleHardwareTest" }, Loading
automotive/vehicle/aidl/aidl_test/Android.bp +23 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ package { cc_test { name: "VehicleHalAidlHidlCompatibilityTest", srcs: ["*.cpp"], srcs: ["AidlHidlCompatibilityTest.cpp"], shared_libs: [ "libbinder_ndk", "libhidlbase", Loading @@ -35,3 +35,25 @@ cc_test { test_suites: ["device-tests"], vendor: true, } cc_test { name: "VehiclePropertyAnnotationCppTest", srcs: ["VehiclePropertyAnnotationCppTest.cpp"], header_libs: ["IVehicleGeneratedHeaders"], defaults: ["VehicleHalInterfaceDefaults"], test_suites: ["general-tests"], } android_test { name: "VehiclePropertyAnnotationJavaTest", srcs: [ "VehiclePropertyAnnotationJavaTest.java", ":IVehicleGeneratedJavaFiles", ], static_libs: [ "android.hardware.automotive.vehicle-V2-java", "androidx.test.runner", "truth-prebuilt", ], test_suites: ["general-tests"], }
automotive/vehicle/aidl/aidl_test/AndroidManifest.xml 0 → 100644 +26 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 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="android.hardware.automotive.vehicle" > <application/> <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" android:targetPackage="android.hardware.automotive.vehicle" android:label="test to verify VHAL annotation"/> </manifest> No newline at end of file
automotive/vehicle/aidl/aidl_test/VehiclePropertyAnnotationCppTest.cpp 0 → 100644 +56 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 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. */ #include <AccessForVehicleProperty.h> #include <ChangeModeForVehicleProperty.h> #include <aidl/android/hardware/automotive/vehicle/VehicleProperty.h> #include <gtest/gtest.h> #include <unordered_set> namespace aidl_vehicle = ::aidl::android::hardware::automotive::vehicle; using aidl_vehicle::AccessForVehicleProperty; using aidl_vehicle::ChangeModeForVehicleProperty; using aidl_vehicle::VehicleProperty; namespace { template<class T> bool doesAnnotationMapContainsAllProps(std::unordered_map<VehicleProperty, T> annotationMap) { for (const VehicleProperty& v : ::ndk::enum_range<VehicleProperty>()) { std::string name = aidl_vehicle::toString(v); if (name == "INVALID") { continue; } if (annotationMap.find(v) == annotationMap.end()) { return false; } } return true; } } // namespace TEST(VehiclePropertyAnnotationCppTest, testChangeMode) { ASSERT_TRUE(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty)) << "Outdated annotation-generated AIDL files. Please run " << "generate_annotation_enums.py to update."; } TEST(VehiclePropertyAnnotationCppTest, testAccess) { ASSERT_TRUE(doesAnnotationMapContainsAllProps(AccessForVehicleProperty)) << "Outdated annotation-generated AIDL files. Please run " << "generate_annotation_enums.py to update."; }
automotive/vehicle/aidl/aidl_test/VehiclePropertyAnnotationJavaTest.java 0 → 100644 +60 −0 Original line number Diff line number Diff line package android.hardware.automotive.vehicle; import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.fail; import androidx.test.filters.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Map; @RunWith(JUnit4.class) public class VehiclePropertyAnnotationJavaTest { private boolean doesAnnotationMapContainsAllProps(Map<Integer, Integer> annotationMap) { for (Field field : VehicleProperty.class.getDeclaredFields()) { int modifiers = field.getModifiers(); try { if (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && Modifier.isPublic(modifiers) && field.getType().equals(int.class)) { int propId = field.getInt(/* obj= */ null); if (propId == VehicleProperty.INVALID) { // Skip INVALID_PROP. continue; } if (annotationMap.get(propId) == null) { return false; } } } catch (IllegalAccessException e) { throw new IllegalStateException( "Cannot access a member for VehicleProperty.class", e); } } return true; } @Test @SmallTest public void testChangeMode() { assertWithMessage("Outdated annotation-generated AIDL files. Please run " + "generate_annotation_enums.py to update.") .that(doesAnnotationMapContainsAllProps(ChangeModeForVehicleProperty.values)) .isTrue(); } @Test @SmallTest public void testAccess() { assertWithMessage("Outdated annotation-generated AIDL files. Please run " + "generate_annotation_enums.py to update.") .that(doesAnnotationMapContainsAllProps(AccessForVehicleProperty.values)) .isTrue(); } } No newline at end of file