From cce25d35d2ee5a80568eec4d504f65fa790473d4 Mon Sep 17 00:00:00 2001 From: Christopher Wiley Date: Thu, 18 Aug 2016 16:15:52 -0700 Subject: Add a simple all in one testing script Just run ./runtests.sh, and if you don't get obvious errors, you must be doing it right. Change-Id: Iaf88b160809a74a90020e54840bb8c4b2d10b133 --- docs/making-changes.md | 7 +------ runtests.sh | 41 +++++++++++++++++++++++++++++++++++++++++ tests/integration-test.py | 37 ++++++++++++------------------------- 3 files changed, 54 insertions(+), 31 deletions(-) create mode 100755 runtests.sh diff --git a/docs/making-changes.md b/docs/making-changes.md index f0e94d5..ac84b86 100644 --- a/docs/making-changes.md +++ b/docs/making-changes.md @@ -16,11 +16,6 @@ This codebase has both integration and unittests, all of which are expected to consistently pass against a device/emulator: ``` -$ mmma system/tools/aidl && \ - out/host/linux-x86/nativetest64/aidl_unittests/aidl_unittests && \ - adb remount && adb sync && \ - adb install -r `find out/ -name aidl_test_services.apk` && \ - (pushd system/tools/aidl/ && tests/integration-test.py) && \ - echo "All tests pass" +$ ./runtests.sh && echo "All tests pass" ``` diff --git a/runtests.sh b/runtests.sh new file mode 100755 index 0000000..05809f9 --- /dev/null +++ b/runtests.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +# 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. + +if [ -z $ANDROID_BUILD_TOP ]; then + echo "You need to source and lunch before you can use this script" + exit 1 +fi + +echo "Running tests" +set -e # fail early + +# NOTE We can't actually run these commands, since they rely on functions added +# by build/envsetup.sh to the bash shell environment. +echo "+ mmma -j32 $ANDROID_BUILD_TOP/system/tools/aidl" +make -j32 -C $ANDROID_BUILD_TOP -f build/core/main.mk \ + MODULES-IN-system-tools-aidl + +set -x # print commands + +${ANDROID_HOST_OUT}/nativetest64/aidl_unittests/aidl_unittests + +adb root +adb wait-for-device +adb remount +adb sync +adb install -r \ + ${ANDROID_PRODUCT_OUT}/system/app/aidl_test_services/aidl_test_services.apk +${ANDROID_BUILD_TOP}/system/tools/aidl/tests/integration-test.py diff --git a/tests/integration-test.py b/tests/integration-test.py index f189977..0079ba9 100755 --- a/tests/integration-test.py +++ b/tests/integration-test.py @@ -124,29 +124,17 @@ class AdbHost(object): return ShellResult(p.returncode, stdout, stderr) -def run_test(test_native, test_java, apk_path=None, refresh_binaries=False, - device_serial=None, verbose=False): +def run_test(host, test_native, test_java): """Body of the test. Args: + host: AdbHost object to run tests on test_native: True iff we should test native Binder clients. test_java: True iff we shoudl test Java Binder clients. - apk_path: Optional path to an APK to install via `adb install` - refresh_binaries: True iff we should `adb sync` new binaries to the - device. - device_serial: Optional string containing the serial number of the - device under test. - verbose: True iff we should enable verbose output during the test. """ print('Starting aidl integration testing...') - host = AdbHost(device_serial=device_serial, verbose=verbose) - if apk_path is not None: - host.adb('install -r %s' % apk_path) - if refresh_binaries: - host.adb('remount') - host.adb('sync') - host.run('setenforce 0') + # Kill any previous test context host.run('rm -f %s' % JAVA_LOG_FILE, ignore_status=True) host.run('pkill %s' % NATIVE_TEST_SERVICE, ignore_status=True) @@ -184,21 +172,20 @@ def run_test(test_native, test_java, apk_path=None, refresh_binaries=False, def main(): """Main entry point.""" parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument('--apk', dest='apk_path', type=str, default=None, - help='Path to an APK to install on the device.') - parser.add_argument('--refresh-bins', action='store_true', default=False, - help='Pass this flag to have the test run adb sync') - parser.add_argument('--serial', '-s', type=str, default=None, - help='Serial number of device to test against') parser.add_argument( '--test-filter', default=TEST_FILTER_ALL, choices=[TEST_FILTER_ALL, TEST_FILTER_JAVA, TEST_FILTER_NATIVE]) parser.add_argument('--verbose', '-v', action='store_true', default=False) args = parser.parse_args() - run_test(args.test_filter in (TEST_FILTER_ALL, TEST_FILTER_NATIVE), - args.test_filter in (TEST_FILTER_ALL, TEST_FILTER_JAVA), - apk_path=args.apk_path, refresh_binaries=args.refresh_bins, - device_serial=args.serial, verbose=args.verbose) + host = AdbHost(verbose=args.verbose) + try: + # Tragically, SELinux interferes with our testing + host.run('setenforce 0') + run_test(host, + args.test_filter in (TEST_FILTER_ALL, TEST_FILTER_NATIVE), + args.test_filter in (TEST_FILTER_ALL, TEST_FILTER_JAVA)) + finally: + host.run('setenforce 1') if __name__ == '__main__': -- cgit v1.2.3