diff --git a/ndk/testing/__init__.py b/ndk/testing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ndk/testing/standalone_toolchain.py b/ndk/testing/standalone_toolchain.py new file mode 100644 index 00000000..fc47ff5e --- /dev/null +++ b/ndk/testing/standalone_toolchain.py @@ -0,0 +1,78 @@ +# +# Copyright (C) 2015 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 logging +import os +import shutil +import subprocess +import tempfile + +import build.lib.build_support + + +def logger(): + return logging.getLogger(__name__) + + +def call_output(cmd, *args, **kwargs): + logger().info('COMMAND: ' + ' '.join(cmd)) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, *args, **kwargs) + out, _ = proc.communicate() + return proc.returncode, out + + +def make_standalone_toolchain(arch, api, extra_args, install_dir): + ndk_dir = os.environ['NDK'] + make_standalone_toolchain_path = os.path.join( + ndk_dir, 'build/tools/make_standalone_toolchain.py') + + cmd = [make_standalone_toolchain_path, '--force', + '--install-dir=' + install_dir, '--arch=' + arch, + '--api={}'.format(api)] + extra_args + + rc, out = call_output(cmd) + return rc == 0, out + + +def test_standalone_toolchain(arch, toolchain, install_dir, test_source): + if toolchain == '4.9': + triple = build.lib.build_support.arch_to_triple(arch) + # x86 toolchain names are dumb: http://b/25800583 + if arch == 'x86': + triple = 'i686-linux-android' + compiler_name = triple + '-g++' + elif toolchain == 'clang': + compiler_name = 'clang++' + + compiler = os.path.join(install_dir, 'bin', compiler_name) + cmd = [compiler, test_source, '-Wl,--no-undefined', '-Wl,--fatal-warnings'] + rc, out = call_output(cmd) + return rc == 0, out + + +def run_test(abi, api, toolchain, test_source, extra_args): + arch = build.lib.build_support.abi_to_arch(abi) + + install_dir = tempfile.mkdtemp() + try: + success, out = make_standalone_toolchain( + arch, api, extra_args, install_dir) + if not success: + return success, out + return test_standalone_toolchain( + arch, toolchain, install_dir, test_source) + finally: + shutil.rmtree(install_dir) diff --git a/tests/build/standalone_toolchain/test.py b/tests/build/standalone_toolchain/test.py index 54a208b7..f7a43b27 100644 --- a/tests/build/standalone_toolchain/test.py +++ b/tests/build/standalone_toolchain/test.py @@ -1,5 +1,5 @@ # -# Copyright (C) 2015 The Android Open Source Project +# 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. @@ -13,65 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging -import os -import shutil -import subprocess -import tempfile +import ndk.testing.standalone_toolchain -import build.lib.build_support - -def logger(): - return logging.getLogger(__name__) - - -def call_output(cmd, *args, **kwargs): - logger().info('COMMAND: ' + ' '.join(cmd)) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, *args, **kwargs) - out, _ = proc.communicate() - return proc.returncode, out - - -def make_standalone_toolchain(arch, api, install_dir): - ndk_dir = os.environ['NDK'] - make_standalone_toolchain_path = os.path.join( - ndk_dir, 'build/tools/make_standalone_toolchain.py') - - cmd = [make_standalone_toolchain_path, '--force', - '--install-dir=' + install_dir, '--arch=' + arch, - '--api={}'.format(api), '--stl=libc++'] - - rc, out = call_output(cmd) - return rc == 0, out - - -def test_standalone_toolchain(arch, toolchain, install_dir): - if toolchain == '4.9': - triple = build.lib.build_support.arch_to_triple(arch) - # x86 toolchain names are dumb: http://b/25800583 - if arch == 'x86': - triple = 'i686-linux-android' - compiler_name = triple + '-g++' - elif toolchain == 'clang': - compiler_name = 'clang++' - - compiler = os.path.join(install_dir, 'bin', compiler_name) - test_source = 'foo.cpp' - cmd = [compiler, test_source, '-Wl,--no-undefined', '-Wl,--fatal-warnings'] - rc, out = call_output(cmd) - return rc == 0, out - - -def run_test(abi, platform, toolchain, _build_flags): - arch = build.lib.build_support.abi_to_arch(abi) - - install_dir = tempfile.mkdtemp() - try: - success, out = make_standalone_toolchain(arch, platform, install_dir) - if not success: - return success, out - return test_standalone_toolchain(arch, toolchain, install_dir) - finally: - shutil.rmtree(install_dir) +def run_test(abi, api, toolchain, _build_flags): + return ndk.testing.standalone_toolchain.run_test( + abi, api, toolchain, 'foo.cpp', ['--stl=libc++']) diff --git a/tests/build/standalone_toolchain_deprecated_headers/test.py b/tests/build/standalone_toolchain_deprecated_headers/test.py index b803169b..c35494cc 100644 --- a/tests/build/standalone_toolchain_deprecated_headers/test.py +++ b/tests/build/standalone_toolchain_deprecated_headers/test.py @@ -1,5 +1,5 @@ # -# Copyright (C) 2015 The Android Open Source Project +# 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. @@ -13,65 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import logging -import os -import shutil -import subprocess -import tempfile +import ndk.testing.standalone_toolchain -import build.lib.build_support - -def logger(): - return logging.getLogger(__name__) - - -def call_output(cmd, *args, **kwargs): - logger().info('COMMAND: ' + ' '.join(cmd)) - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, *args, **kwargs) - out, _ = proc.communicate() - return proc.returncode, out - - -def make_standalone_toolchain(arch, api, install_dir): - ndk_dir = os.environ['NDK'] - make_standalone_toolchain_path = os.path.join( - ndk_dir, 'build/tools/make_standalone_toolchain.py') - - cmd = [make_standalone_toolchain_path, '--force', - '--install-dir=' + install_dir, '--arch=' + arch, - '--api={}'.format(api), '--stl=libc++', '--deprecated-headers'] - - rc, out = call_output(cmd) - return rc == 0, out - - -def test_standalone_toolchain(arch, toolchain, install_dir): - if toolchain == '4.9': - triple = build.lib.build_support.arch_to_triple(arch) - # x86 toolchain names are dumb: http://b/25800583 - if arch == 'x86': - triple = 'i686-linux-android' - compiler_name = triple + '-g++' - elif toolchain == 'clang': - compiler_name = 'clang++' - - compiler = os.path.join(install_dir, 'bin', compiler_name) - test_source = 'foo.cpp' - cmd = [compiler, test_source, '-Wl,--no-undefined', '-Wl,--fatal-warnings'] - rc, out = call_output(cmd) - return rc == 0, out - - -def run_test(abi, platform, toolchain, _build_flags): - arch = build.lib.build_support.abi_to_arch(abi) - - install_dir = tempfile.mkdtemp() - try: - success, out = make_standalone_toolchain(arch, platform, install_dir) - if not success: - return success, out - return test_standalone_toolchain(arch, toolchain, install_dir) - finally: - shutil.rmtree(install_dir) +def run_test(abi, api, toolchain, _build_flags): + return ndk.testing.standalone_toolchain.run_test( + abi, api, toolchain, 'foo.cpp', + ['--stl=libc++', '--deprecated-headers'])