1# -*- Python -*-
2#
3# Copyright (C) 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18# Configuration file for the 'lit' test runner in Android libbcc
19# This file is common to both host and target side tests
20
21import os
22
23# Used to determine the absolute path of a tool. If env_var is set, it
24# overrides the default behaviour of searching PATH for binary_name
25def inferTool(lit, binary_name, env_var, PATH):
26    # Determine which tool to use.
27    tool = os.getenv(env_var)
28
29    # If the user set the overriding environment variable, use it
30    if tool and os.path.isfile(tool):
31        return tool
32
33    # Otherwise look in the path.
34    tool = lit.util.which(binary_name, PATH)
35
36    if not tool:
37        lit.fatal("couldn't find " + binary_name + " program in " + PATH + " \
38                  , try setting " + env_var + " in your environment")
39
40    return os.path.abspath(tool)
41
42# Get the base build directory for the android source tree from environment.
43config.build_top = os.getenv('ANDROID_BUILD_TOP')
44
45config.base_build_path = os.path.join(config.build_top, 'out', 'host',
46  'linux-x86')
47
48# testFormat: The test format to use to interpret tests.
49config.test_format = lit.formats.ShTest()
50
51# Tool used to verify debugger output against expected output in source
52config.filecheck = inferTool(lit, 'FileCheck', 'FILECHECK', \
53  os.path.join(config.base_build_path, 'bin'))
54
55# Invokes GDB and captures output
56config.test_bcc_debuginfo = inferTool(lit, 'test_bcc_debuginfo.pl', \
57  'TEST_JIT_DEBUGINFO', os.path.join(config.build_top, 'frameworks', \
58  'compile', 'libbcc', 'tests', 'debuginfo'))
59
60# GDB
61config.gdb = inferTool(lit, 'arm-linux-androideabi-gdb', 'GDB',
62  config.environment['PATH'])
63
64# GDB python plugin
65config.gdb_plugin = inferTool(lit, 'android-commands.py',
66  'ANDROID_GDB_PLUGIN', os.path.join(config.build_top, 'frameworks',
67    'compile', 'libbcc', 'gdb_plugin'))
68config.gdb_plugin_directory = os.path.dirname(config.gdb_plugin)
69
70# Script interpreters that are not python
71config.perl = inferTool(lit, 'perl', 'PERL', config.environment['PATH'])
72config.sh = inferTool(lit, 'bash', 'BASH', config.environment['PATH'])
73
74# Tools that are specific to running host-side debugger integration tests:
75config.clang = inferTool(lit, 'clang', 'CLANG',
76  os.path.join(config.base_build_path, 'bin')).replace('\\', '/')
77config.bcc_driver = inferTool(lit, 'bcc', 'BCC_DRIVER',
78  os.path.join(config.base_build_path, 'obj', 'EXECUTABLES', \
79    'bcc_intermediates')).replace('\\', '/')
80
81# Tools that are specific to running target-side debugger integration tests:
82config.build_test_apk = inferTool(lit, 'build_test_apk.sh',
83  'BUILD_TEST_APK',
84  os.path.join(config.build_top, 'frameworks', 'compile', 'libbcc',
85    'tests', 'debuginfo'))
86
87#
88## Apply common substitutions
89#
90config.substitutions.append( ('%Test_jit_debuginfo', config.perl \
91                                + ' ' + config.test_bcc_debuginfo \
92                                + ' ' + config.filecheck + ' ' ) )
93
94#
95## Print common configuration
96#
97if not lit.quiet:
98    lit.note('using bash: %r' % config.sh)
99    lit.note('using perl: %r' % config.perl)
100    lit.note('using verification script: %r' % config.test_bcc_debuginfo)
101    lit.note('using FileCheck: %r' % config.filecheck)
102    lit.note('using GDB: %r' % config.gdb)
103