Skip to content

Commit

Permalink
Factor out common standalone toolchain test code.
Browse files Browse the repository at this point in the history
Test: ./validate.py --filter standalone_toolchain*
Bug: android/ndk#310
Change-Id: Ie65713b0cbad177b1531ebf355e6df9baafab458
  • Loading branch information
DanAlbert committed Mar 7, 2017
1 parent cbaa479 commit 69b99f3
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 122 deletions.
Empty file added ndk/testing/__init__.py
Empty file.
78 changes: 78 additions & 0 deletions ndk/testing/standalone_toolchain.py
Original file line number Diff line number Diff line change
@@ -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)
66 changes: 5 additions & 61 deletions tests/build/standalone_toolchain/test.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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++'])
67 changes: 6 additions & 61 deletions tests/build/standalone_toolchain_deprecated_headers/test.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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'])

0 comments on commit 69b99f3

Please sign in to comment.