1# -*- python -*- 2# Copyright (c) 2012 The Native Client Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import os 7 8Import('env') 9 10if 'TRUSTED_ENV' not in env: 11 Return() 12 13if env.UnderWindowsCoverage(): 14 Return() 15 16if env.Bit('build_arm') or env.Bit('build_mips32'): 17 if env.UsingEmulator(): 18 # nacl-gdb is built with ARM support but not MIPS support. 19 if env.Bit('build_mips32'): 20 Return() 21 nacl_x86_toolchain_dir = env.GetToolchainDir(target_arch='x86', 22 is_pnacl=False, 23 lib_name='glibc') 24 nacl_gdb_path = os.path.join(nacl_x86_toolchain_dir, 'bin', 'i686-nacl-gdb') 25 env.Replace(GDB=nacl_gdb_path) 26 else: 27 # Use the system's ARM/MIPS GDB because the NaCl toolchain does not 28 # include a copy of GDB built to run on ARM/MIPS. 29 env.Replace(GDB='gdb') 30 # Unlike nacl-gdb, the system version of GDB does not support the 31 # "nacl-irt" command. 32 if env.Bit('tests_use_irt'): 33 Return() 34 35# Disable finalization (which would strip debug metadata), but allow 36# the sandbox translator where it makes sense. 37if not env.SetNonStableBitcodeIfAllowed(allow_sb_translator=True): 38 Return() 39 40# We need -O0 to make stepping predictable and read local variables/function 41# arguments that may otherwise be optimized out. 42env.Append(CCFLAGS=['-O0', '-g', '-fno-omit-frame-pointer']) 43# We need to disable PNaCl's link time optimizations so that functions 44# do not get inlined, so that we can set breakpoints on these 45# functions. Also make translation optimizaton level -O0. 46if env.Bit('bitcode'): 47 env.Append(LINKFLAGS=['-O0']) 48 env.Append(TRANSLATEFLAGS=['-O0']) 49 # TODO(jfb) ARM bots test the local GDB, which isn't as recent as 50 # nacl-gdb. The move to LLVM 3.5 broke line info reading on some of 51 # the ARM bots, and using DWARF 3 "fixes" this issue. 52 if env.Bit('build_arm'): 53 env.Append(CCFLAGS=['-gdwarf-3']) 54 55sel_ldr_command = env.AddBootstrap(env.GetSelLdr(), ['-v']) 56if env.GetEmulator(): 57 # Run sel_ldr through qemu-arm. Add "-Q" to disable the platform 58 # qualification tests because they fail under qemu-arm. 59 sel_ldr_command = [env.GetEmulator()] + sel_ldr_command + ['-Q'] 60 61test_args = ['--gdb', env['GDB'], 62 '--output_dir', env.subst('${TARGET_ROOT}/test_results')] 63if env.Bit('tests_use_irt'): 64 test_args += ['--irt', env.GetIrtNexe()] 65if not env.Bit('nacl_static_link'): 66 test_args += ['--ld_so', env.File('${NACL_SDK_LIB}/runnable-ld.so'), 67 '--library_path', env['NACL_SDK_LIB']] 68test_args += ['--'] + sel_ldr_command 69 70extra_deps = [env.File('gdb_test.py')] 71 72test_suites = ['medium_tests', 'gdb_tests'] 73 74gdb_test_guest = env.ComponentProgram( 75 'gdb_test_guest', 'gdb_test_guest.c', 76 EXTRA_LIBS=['${NONIRT_LIBS}']) 77gdb_test_guest = env.GetTranslatedNexe(gdb_test_guest) 78 79# GDB treats multithreaded programs specially. Provide distinct nexe for 80# multithreaded tests to isolate multiple threads-specific issues. 81gdb_test_guest_thread = env.ComponentProgram( 82 'gdb_test_guest_thread', 'gdb_test_guest_thread.c', 83 EXTRA_LIBS=['${PTHREAD_LIBS}', '${NONIRT_LIBS}']) 84gdb_test_guest_thread = env.GetTranslatedNexe(gdb_test_guest_thread) 85 86 87# TempFileArguments: gdb_test_guest-based tests below accept a 88# temporary file argument, and we encapsulate this here for brevity / 89# to avoid code duplication. 90def TempFileArguments(): 91 temp_path = env.MakeEmptyFile(prefix='nacl_gdb_test_') 92 return ','.join(['-f', temp_path]) 93 94 95def AddGdbTest(name, is_broken=False, is_thread_test=False): 96 if is_thread_test: 97 script_args = ['--nexe', gdb_test_guest_thread] 98 else: 99 script_args = ['--nexe', gdb_test_guest, 100 '--nexe_args', TempFileArguments()] 101 node = env.CommandTest('%s.out' % name, 102 extra_deps=extra_deps, 103 command=(['${PYTHON}', env.File('%s.py' % name)] 104 + script_args 105 + test_args), 106 # Don't run the host Python through qemu-arm. 107 direct_emulation=False) 108 env.TestBindsFixedTcpPort(node) 109 env.AddNodeToTestSuite(node, test_suites, 'run_gdb_%s_test' % name, 110 is_broken=(is_broken or env.Bit('no_gdb_tests') or 111 # TODO(mcgrathr): Currently these tests 112 # do not work with the new glibc. 113 (env.Bit('nacl_glibc') and 114 env.Bit('build_arm')))) 115 116 117AddGdbTest('complete') 118AddGdbTest('detach') 119AddGdbTest('disconnect') 120 121using_clang = env.Bit('bitcode') or env.Bit('nacl_clang') 122 123# https://code.google.com/p/nativeclient/issues/detail?id=4059 124AddGdbTest('invalid_memory', 125 is_broken = (using_clang and not env.UsingEmulator())) 126AddGdbTest('kill') 127# TODO(crbug.com/1101347): This fails on ARM bots. 128AddGdbTest('remote_get', is_broken=env.Bit('build_arm') and not env.UsingEmulator()) 129 130# Single-stepping does work reliably with ARM and MIPS in qemu due to the code 131# cache not being flushable. 132AddGdbTest('stepi_after_break', is_broken=env.UsingEmulator()) 133 134# This fails on ARM+PNaCl. The set_global_var function appears to be 135# getting the wrong argument value (68K vs 1), so the value of 136# global_var doesn't match the expected value. 137# TODO(mseaborn): Investigate and enable this test. 138# http://code.google.com/p/nativeclient/issues/detail?id=3252 139# This test also fails with arm-nacl-clang: 140# https://code.google.com/p/nativeclient/issues/detail?id=4059 141AddGdbTest('print_symbol', 142 is_broken=((using_clang and env.Bit('build_arm')) 143 or env.UsingEmulator())) 144 145# This fails on ARM+PNaCl because it gets an 146# unexpected value for a function argument from 147# the stack backtrace. 148# TODO(mseaborn): Investigate and enable this test. 149# http://code.google.com/p/nativeclient/issues/detail?id=3252 150AddGdbTest('stack_trace', 151 is_broken=using_clang and env.Bit('build_arm')) 152 153# This fails on ARM+nacl-clang 154# https://code.google.com/p/nativeclient/issues/detail?id=4059 155AddGdbTest('step_from_func_start', 156 is_broken=(env.UsingEmulator() or 157 (env.Bit('nacl_clang') and env.Bit('build_arm')))) 158 159# This fails on MIPS, since GDB for MIPS executes inferior calls on stack 160# (call dummy location in MIPS GDB is set as ON_STACK method). Since the stack 161# is not executable under NaCl, this makes inferior call impossible to execute. 162AddGdbTest('call_from_gdb', is_broken=env.Bit('build_mips32')) 163 164# This fails on ARM/MIPS+PNaCl because it is reading 165# local_var before it has been initialised. 166# TODO(mseaborn): Investigate and enable this test. 167# http://code.google.com/p/nativeclient/issues/detail?id=3252 168# This test also fails with arm-nacl-clang: 169# https://code.google.com/p/nativeclient/issues/detail?id=4059 170AddGdbTest('change_variable', 171 is_broken=((using_clang and env.Bit('build_arm')) or 172 env.Bit('build_mips32') or 173 env.UsingEmulator())) 174 175if not env.Bit('nacl_static_link'): 176 AddGdbTest('execute_nacl_manifest_twice') 177 178# This test hangs under qemu-arm because thread suspension doesn't 179# work on qemu-arm. 180AddGdbTest('break_continue_thread', is_thread_test=True, 181 is_broken=env.UsingEmulator()) 182 183AddGdbTest('syscall_thread', is_thread_test=True) 184 185# We don't run this test on non-x86 architectures or PNaCl since it 186# contains inline assembly. 187if env.Bit('build_x86') and not env.Bit('bitcode'): 188 AddGdbTest('mmap') 189