diff options
| author | Steven Moreland <smoreland@google.com> | 2020-09-09 23:40:40 +0000 |
|---|---|---|
| committer | Steven Moreland <smoreland@google.com> | 2020-09-10 00:54:42 +0000 |
| commit | aae8bd4fa8d1f5f4a3281ad1638d279aa47bb7aa (patch) | |
| tree | 0566e0a70e25fb4614dcf70e372d942d82b7cdbb | |
| parent | 18450469589040303fdb033872421b5714eed77a (diff) | |
| download | platform_system_tools_hidl-aae8bd4fa8d1f5f4a3281ad1638d279aa47bb7aa.tar.gz platform_system_tools_hidl-aae8bd4fa8d1f5f4a3281ad1638d279aa47bb7aa.tar.bz2 platform_system_tools_hidl-aae8bd4fa8d1f5f4a3281ad1638d279aa47bb7aa.zip | |
hidl_test: on atest infrastructure
In preparation for adding this back to VTS.
Bug: 127714188
Test: atest -v hidl_test
Change-Id: I20c99d4666e2f9897825f43a496d61e7ec563568
| -rw-r--r-- | TEST_MAPPING | 3 | ||||
| -rw-r--r-- | test/hidl_test/Android.bp | 33 | ||||
| -rw-r--r-- | test/hidl_test/Android.mk | 43 | ||||
| -rw-r--r-- | test/hidl_test/AndroidTest.xml | 34 | ||||
| -rwxr-xr-x | test/hidl_test/hidl_test | 9 | ||||
| -rw-r--r-- | test/hidl_test/hidl_test.py | 74 | ||||
| -rw-r--r-- | test/hidl_test/hidl_test.xml | 40 | ||||
| -rw-r--r-- | test/hidl_test/hidl_test_helper | 152 |
8 files changed, 143 insertions, 245 deletions
diff --git a/TEST_MAPPING b/TEST_MAPPING index c758679ae..15fe17579 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,6 +1,9 @@ { "presubmit": [ { + "name": "hidl_test" + }, + { "name": "hidl-gen-host_test", "host": true }, diff --git a/test/hidl_test/Android.bp b/test/hidl_test/Android.bp index 25e841cb4..6fd08b028 100644 --- a/test/hidl_test/Android.bp +++ b/test/hidl_test/Android.bp @@ -1,5 +1,17 @@ +python_test_host { + name: "hidl_test", + main: "hidl_test.py", + srcs: ["hidl_test.py"], + test_config: "hidl_test.xml", + target_required: [ + "hidl_test_client", + "hidl_test_servers", + ], + test_suites: ["general-tests"], +} + cc_defaults { - name: "hidl_test_client-defaults", + name: "hidl_test-defaults", defaults: ["hidl-gen-defaults"], shared_libs: [ @@ -52,11 +64,22 @@ cc_defaults { ], group_static_libs: true, + + compile_multilib: "both", + multilib: { + lib32: { + suffix: "32", + }, + lib64: { + suffix: "64", + }, + }, + test_suites: ["device-tests"], } cc_test { name: "hidl_test_client", - defaults: ["hidl_test_client-defaults"], + defaults: ["hidl_test-defaults"], srcs: [ "hidl_test_client.cpp", @@ -71,11 +94,7 @@ cc_test { cc_test { name: "hidl_test_servers", - defaults: ["hidl_test_client-defaults"], + defaults: ["hidl_test-defaults"], srcs: ["hidl_test_servers.cpp"], gtest: false, } - -vts_config { - name: "VtsHidlUnitTests", -} diff --git a/test/hidl_test/Android.mk b/test/hidl_test/Android.mk deleted file mode 100644 index b5fdd5eb6..000000000 --- a/test/hidl_test/Android.mk +++ /dev/null @@ -1,43 +0,0 @@ -# -# 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_MODULE := hidl_test_helper -LOCAL_MODULE_CLASS := NATIVE_TESTS -LOCAL_SRC_FILES := hidl_test_helper - -LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest64 - -include $(BUILD_PREBUILT) - -include $(CLEAR_VARS) -LOCAL_MODULE := hidl_test -LOCAL_MODULE_CLASS := NATIVE_TESTS -LOCAL_SRC_FILES := hidl_test - -LOCAL_MODULE_PATH := $(TARGET_OUT_DATA)/nativetest64 - -LOCAL_REQUIRED_MODULES := \ - hidl_test_client \ - hidl_test_helper \ - hidl_test_servers - -ifneq ($(TARGET_2ND_ARCH),) -LOCAL_REQUIRED_MODULES += hidl_test_servers$(TARGET_2ND_ARCH_MODULE_SUFFIX) -LOCAL_REQUIRED_MODULES += hidl_test_client$(TARGET_2ND_ARCH_MODULE_SUFFIX) -endif - -include $(BUILD_PREBUILT) diff --git a/test/hidl_test/AndroidTest.xml b/test/hidl_test/AndroidTest.xml deleted file mode 100644 index 663394275..000000000 --- a/test/hidl_test/AndroidTest.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- Copyright (C) 2016 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. ---> -<configuration description="Config for VTS HIDL unit tests"> - <option name="config-descriptor:metadata" key="plan" value="vts-library" /> - <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher"> - <option name="push-group" value="HostDrivenTest.push" /> - <option name="cleanup" value="true" /> - <option name="push" value="DATA/nativetest/hidl_test_servers/hidl_test_servers->/data/nativetest/hidl_test_servers/hidl_test_servers" /> - <option name="push" value="DATA/nativetest64/hidl_test_servers/hidl_test_servers->/data/nativetest64/hidl_test_servers/hidl_test_servers" /> - <option name="push" value="DATA/nativetest/hidl_test_client/hidl_test_client->/data/nativetest/hidl_test_client/hidl_test_client" /> - <option name="push" value="DATA/nativetest64/hidl_test_client/hidl_test_client->/data/nativetest64/hidl_test_client/hidl_test_client" /> - <option name="push" value="DATA/nativetest64/hidl_test_helper->/data/nativetest64/hidl_test_helper" /> - </target_preparer> - <multi_target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer" /> - <test class="com.android.tradefed.testtype.VtsMultiDeviceTest"> - <option name="test-module-name" value="VtsHidlUnitTests" /> - <option name="binary-test-type" value="binary_test" /> - <option name="binary-test-source" value="DATA/nativetest64/hidl_test->/data/nativetest64/hidl_test" /> - <option name="test-timeout" value="1m" /> - </test> -</configuration> diff --git a/test/hidl_test/hidl_test b/test/hidl_test/hidl_test deleted file mode 100755 index 53f4828c6..000000000 --- a/test/hidl_test/hidl_test +++ /dev/null @@ -1,9 +0,0 @@ -source /data/nativetest64/hidl_test_helper - -run_all_tests \ - "/data/nativetest/hidl_test_servers/hidl_test_servers" \ - "/data/nativetest64/hidl_test_servers/hidl_test_servers" \ - "/data/nativetest/hidl_test_client/hidl_test_client" \ - "/data/nativetest64/hidl_test_client/hidl_test_client" \ - "hidl_test" \ - "$@" diff --git a/test/hidl_test/hidl_test.py b/test/hidl_test/hidl_test.py new file mode 100644 index 000000000..4964380d2 --- /dev/null +++ b/test/hidl_test/hidl_test.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 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. +# + +import subprocess +import unittest + +def run_cmd(cmd, ignore_error=False): + print("Running command:", cmd) + p = subprocess.Popen(cmd, shell=True) + p.communicate() + if not ignore_error and p.returncode: + raise subprocess.CalledProcessError(p.returncode, cmd) + return p.returncode + +class TestHidl(unittest.TestCase): + pass + +def make_test(client, server): + def test(self): + try: + run_cmd("adb shell killall %s >/dev/null 2>&1" % client, ignore_error=True) + run_cmd("adb shell killall %s >/dev/null 2>&1" % server, ignore_error=True) + run_cmd("adb shell \"( %s ) </dev/null >/dev/null 2>&1 &\"" % server) + run_cmd("adb shell %s" % client) + finally: + run_cmd("adb shell killall %s >/dev/null 2>&1" % client, ignore_error=True) + run_cmd("adb shell killall %s >/dev/null 2>&1" % server, ignore_error=True) + return test + +def has_binary(binary): + return 0 == run_cmd("adb shell ls %s >/dev/null" % binary, ignore_error=True) + +if __name__ == '__main__': + clients = [] + servers = [] + + if has_binary("/data/nativetest/hidl_test_client/hidl_test_client"): + clients += ["/data/nativetest/hidl_test_client/hidl_test_client"] + servers += ["/data/nativetest/hidl_test_servers/hidl_test_servers"] + + if has_binary("/data/nativetest64/hidl_test_client/hidl_test_client"): + clients += ["/data/nativetest64/hidl_test_client/hidl_test_client"] + servers += ["/data/nativetest64/hidl_test_servers/hidl_test_servers"] + + assert len(clients) > 0 + assert len(servers) > 0 + + def short_name(binary): + if "64" in binary: + return "64" + return "32" + + for client in clients: + for server in servers: + test_name = 'test_%s_to_%s' % (short_name(client), short_name(server)) + test = make_test(client, server) + setattr(TestHidl, test_name, test) + + suite = unittest.TestLoader().loadTestsFromTestCase(TestHidl) + unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/test/hidl_test/hidl_test.xml b/test/hidl_test/hidl_test.xml new file mode 100644 index 000000000..586adc43b --- /dev/null +++ b/test/hidl_test/hidl_test.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2020 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. +--> +<configuration description="Runs HIDL on-device integration tests."> + <option name="test-suite-tag" value="apct" /> + <option name="test-suite-tag" value="apct-native" /> + + <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer"/> + + <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer"> + <!-- We would like to abort, but currently there is not a simple way to specify installation of both bitnesses of targets. --> + <option name="abort-on-push-failure" value="false"/> + + <option name="push" value="hidl_test_client32->/data/nativetest/hidl_test_client/hidl_test_client" /> + <option name="push" value="hidl_test_client64->/data/nativetest64/hidl_test_client/hidl_test_client" /> + + <option name="push" value="hidl_test_servers32->/data/nativetest/hidl_test_servers/hidl_test_servers" /> + <option name="push" value="hidl_test_servers64->/data/nativetest64/hidl_test_servers/hidl_test_servers" /> + + <option name="cleanup" value="true" /> + </target_preparer> + + <test class="com.android.tradefed.testtype.python.PythonBinaryHostTest" > + <option name="par-file-name" value="hidl_test" /> + <option name="test-timeout" value="2m" /> + </test> +</configuration> + diff --git a/test/hidl_test/hidl_test_helper b/test/hidl_test/hidl_test_helper deleted file mode 100644 index 8329dbca9..000000000 --- a/test/hidl_test/hidl_test_helper +++ /dev/null @@ -1,152 +0,0 @@ -function usage() { - echo "runs $TEST_NAME" - echo "\t -h help" - echo "\t -c [CLIENT64_SERVER64 | CLIENT32_SERVER32 | CLIENT64_SERVER32 | CLIENT32_SERVER64] configures whether to run 32-bit or 64-bit versions of the servers and client" - echo "\t -x [/ld/library/path32] set the LD_LIBRARY_PATH for servers32 and client32" - echo "\t -y [/ld/library/path64] set the LD_LIBRARY_PATH for servers64 and client64" -} - -failed_test_cases=() -ran_test_cases=0 - -function run_test() { - if [ $1 -eq 32 ]; then - CLIENT_PATH=$CLIENT_PATH32 - LD_LIB_PATH_CLIENT=$LD_LIB_PATH32 - else - CLIENT_PATH=$CLIENT_PATH64 - LD_LIB_PATH_CLIENT=$LD_LIB_PATH64 - fi - - if [ $2 -eq 32 ]; then - SERVER_PATH=$SERVER_PATH32 - LD_LIB_PATH_SERVER=$LD_LIB_PATH32 - else - SERVER_PATH=$SERVER_PATH64 - LD_LIB_PATH_SERVER=$LD_LIB_PATH64 - fi - - if [ ! -f $SERVER_PATH ] || [ ! -f $CLIENT_PATH ]; then - echo "Not running $CLIENT_PATH with $SERVER_PATH since one doesn't exist" - return - fi - - echo "Running $1-bit client with $2-bit servers" - echo "$LD_LIB_PATH_SERVER=$LD_LIB_PATH_SERVER" - LD_LIBRARY_PATH=$LD_LIB_PATH_SERVER:$LD_LIBRARY_PATH $SERVER_PATH & - SERVER_PID=$! - LD_LIBRARY_PATH=$LD_LIB_PATH_CLIENT:$LD_LIBRARY_PATH $CLIENT_PATH - if [ $? -ne 0 ]; then - failed_test_cases+=("$1-bit client with $2-bit servers") - fi - kill $SERVER_PID - ran_test_cases=1 -} - -function check_env() { - if [ -z ${TEST_NAME+x} ]; then - echo "TEST_NAME is unset"; - exit 1 - fi - - if [ -z ${CLIENT_PATH32+x} ]; then - echo "CLIENT_PATH32 is unset"; - exit 1 - fi - - if [ -z ${CLIENT_PATH64+x} ]; then - echo "CLIENT_PATH64 is unset"; - exit 1 - fi - - if [ -z ${SERVER_PATH32+x} ]; then - echo "SERVER_PATH32 is unset"; - exit 1 - fi - - if [ -z ${SERVER_PATH64+x} ]; then - echo "SERVER_PATH64 is unset"; - exit 1 - fi -} - -#usage: run_all_tests server_path32 server_path64 client_path32 client_path64 test_name [-h/-c config/-x lib32/-y ldlib64] -function run_all_tests() { - SERVER_PATH32=$1 - SERVER_PATH64=$2 - CLIENT_PATH32=$3 - CLIENT_PATH64=$4 - TEST_NAME=$5 - check_env - shift 5 - - while getopts hc:x:y: opt; - do - case $opt in - h) - usage - exit 0 - ;; - c) - case $OPTARG in - CLIENT64_SERVER64) - run_test 64 64 - ;; - CLIENT32_SERVER32) - run_test 32 32 - ;; - CLIENT64_SERVER32) - run_test 64 32 - ;; - CLIENT32_SERVER64) - run_test 32 64 - ;; - *) - echo "Error: unknown config value \"$OPTARG\"" - exit 1 - ;; - esac - exit 0 - ;; - x) - LD_LIB_PATH32=$OPTARG - ;; - y) - LD_LIB_PATH64=$OPTARG - ;; - *) - echo "Error: unknown param \"$opt\"" - usage - exit 1 - ;; - esac - done - - for i in 32 64 - do - for j in 32 64 - do - run_test $i $j - done - done - - if [ $ran_test_cases -ne 1 ]; then - failed_test_cases+=("No tests ran") - fi - - count_failed_tests=${#failed_test_cases[@]} - echo "*********************************************************" - echo " $TEST_NAME Final Summary:\n" - if [ $count_failed_tests -gt 0 ]; then - echo " $TEST_NAME failed for the following cases:\n\t" - for each in "${failed_test_cases[@]}" - do - echo "\t$each" - done - else - echo " $TEST_NAME passed for all cases!" - fi - echo "*********************************************************" - - exit ${#failed_test_cases[@]} -} |
