def get_nacl_runner(bitsize, bin_dir=None, use_test_library=True, extra_library_paths=None, extra_envs=None): extra_library_paths = extra_library_paths or [] extra_envs = extra_envs or {} # We use the NACL_IRT_DEV_FILENAME interface for unit tests. args = ['env', 'NACL_DANGEROUS_ENABLE_FILE_ACCESS=1'] arch = 'x86_%d' % bitsize sel_ldr = get_nacl_tool('sel_ldr_%s' % arch) irt_core = get_nacl_irt_core(bitsize) if bin_dir: sel_ldr = os.path.join(bin_dir, sel_ldr) irt_core = os.path.join(bin_dir, irt_core) args.extend([sel_ldr, '-a', '-B', irt_core]) library_path = build_common.get_load_library_path() library_path_for_test = build_common.get_load_library_path_for_test() runnable_ld = os.path.join(library_path, 'runnable-ld.so') if use_test_library: library_path = ':'.join([library_path_for_test, library_path]) args.extend([ '-E', 'LD_LIBRARY_PATH=' + ':'.join([library_path] + extra_library_paths) ]) for key, value in extra_envs.iteritems(): args.extend(['-E', '%s=%s' % (key, value)]) args.append(runnable_ld) return args
def get_nacl_runner(bitsize, bin_dir=None, use_test_library=True, extra_library_paths=None, extra_envs=None): extra_library_paths = extra_library_paths or [] extra_envs = extra_envs or {} # We use the NACL_IRT_DEV_FILENAME interface for unit tests. args = ['env', 'NACL_DANGEROUS_ENABLE_FILE_ACCESS=1'] arch = 'x86_%d' % bitsize sel_ldr = get_nacl_tool('sel_ldr_%s' % arch) irt_core = get_nacl_irt_core(bitsize) if bin_dir: sel_ldr = os.path.join(bin_dir, sel_ldr) irt_core = os.path.join(bin_dir, irt_core) args.extend([sel_ldr, '-a', '-B', irt_core]) library_path = build_common.get_load_library_path() library_path_for_test = build_common.get_load_library_path_for_test() runnable_ld = os.path.join(library_path, 'runnable-ld.so') if use_test_library: library_path = ':'.join([library_path_for_test, library_path]) args.extend(['-E', 'LD_LIBRARY_PATH=' + ':'.join([library_path] + extra_library_paths)]) for key, value in extra_envs.iteritems(): args.extend(['-E', '%s=%s' % (key, value)]) args.append(runnable_ld) return args
def _get_runner_env_vars(use_test_library=True, extra_library_paths=None, extra_envs=None): extra_library_paths = extra_library_paths or [] extra_envs = extra_envs or {} load_library_paths = [] if use_test_library: load_library_paths.append(build_common.get_load_library_path_for_test()) load_library_paths.append(build_common.get_load_library_path()) envs = { 'LD_LIBRARY_PATH': ':'.join(load_library_paths + extra_library_paths) } if extra_envs: conflict_keys = envs.viewkeys() & extra_envs.viewkeys() assert not conflict_keys, ('The following keys are duplicated: %s' % sorted(conflict_keys)) envs.update(extra_envs) return envs
def _run_gdb_for_nacl(args, test_args): runnable_ld = args[-1] assert 'runnable-ld.so' in runnable_ld # Insert -g flag before -a to let sel_ldr wait for GDB. a_index = args.index('-a') assert 'sel_ldr' in args[a_index - 1] args.insert(a_index, '-g') args.extend(test_args) # The child process call setsid(2) to create a new session so that # sel_ldr will not die by Ctrl-C either. Note that ignoring SIGINT # does not work for sel_ldr, because sel_ldr will override the # setting. sel_ldr_proc = subprocess.Popen(args, stderr=subprocess.STDOUT, preexec_fn=os.setsid) gdb = toolchain.get_tool(build_options.OPTIONS.target(), 'gdb') irt = toolchain.get_nacl_irt_core(build_options.OPTIONS.get_target_bitsize()) # The Bionic loader only provides the base name of each loaded binary in L # for 32-bit platforms due to a compatibility issue. # ARC keeps the behavior and provides full path information for debugging # explicitly. See SEARCH_NAME() in mods/android/bionic/linker/linker.cpp. # DSOs are covered by build_common.get_load_library_path(), but full path # information for test main binary should be specified separately. # # Note GDB uses NaCl manifest for arc.nexe so we do not need the library # search paths for launch_chrome. solib_paths = [build_common.get_load_library_path_for_test(), build_common.get_load_library_path(), os.path.dirname(test_args[0])] args = [ gdb, '-ex', 'target remote :4014', '-ex', 'nacl-irt %s' % irt, # The Bionic does not pass a fullpath of a shared object to the # debugger. Fixing this issue by modifying the Bionic loader # will need a bunch of ARC MOD. We work-around the issue by # passing the path of shared objects here. '-ex', 'set solib-search-path %s' % ':'.join(solib_paths), '-ex', 'echo \n*** Type \'continue\' or \'c\' to start debugging ***\n\n', runnable_ld] subprocess.call(args) sel_ldr_proc.kill()
def _get_runner_env_vars(use_test_library=True, extra_library_paths=None, extra_envs=None): extra_library_paths = extra_library_paths or [] extra_envs = extra_envs or {} load_library_paths = [] if use_test_library: load_library_paths.append( build_common.get_load_library_path_for_test()) load_library_paths.append(build_common.get_load_library_path()) envs = { 'LD_LIBRARY_PATH': ':'.join(load_library_paths + extra_library_paths) } if extra_envs: conflict_keys = envs.viewkeys() & extra_envs.viewkeys() assert not conflict_keys, ('The following keys are duplicated: %s' % sorted(conflict_keys)) envs.update(extra_envs) return envs
def _generate_libposix_translation_for_test(): n = ninja_generator.SharedObjectNinjaGenerator( 'libposix_translation_for_test', dt_soname='libposix_translation.so', is_system_library=True, is_for_test=True) # libposix_translation_for_test is built using generated code in the out/ # directory. The logic we have to scan for NOTICES does not find one for this # generated code, and complains later. The libposix_translation.so code # normally inherits the project NOTICE from src/NOTICE, so we just explicitly # point to it here as the notice to use for this special version of the # library. n.add_notice_sources([staging.as_staging('src/NOTICE')]) gen_rule_name = 'gen_wrap_syscall_aliases_s' gen_script_path = os.path.join('src/common', gen_rule_name + '.py') n.rule(gen_rule_name, command='%s > $out.tmp && mv $out.tmp $out' % gen_script_path, description=gen_rule_name + ' $in') gen_out_path = os.path.join(build_common.get_build_dir(), 'posix_translation_gen_sources', 'wrap_syscall_aliases.S') gen_implicit_deps = python_deps.find_deps(gen_script_path) n.build(gen_out_path, gen_rule_name, implicit=gen_implicit_deps) # Following deps order is important. art_libc_supplement_for_test.so should # be placed before libc.so. if not open_source.is_open_source_repo(): # This is for ART unit tests which have not been opensourced. To not let # posix_translation depend on ART on arc_open, use is_open_source_repo(). n.add_library_deps('art_libc_supplement_for_test.so') n.add_library_deps('libc.so', 'libdl.so') n.build_default([gen_out_path], base_path=None).link() # /test/libposix_translation.so should be a symbolic link to # ../lib/libposix_translation_for_test.so. n = ninja_generator.NinjaGenerator('test_libposix_translation') orig_so = os.path.join( build_common.get_load_library_path(), 'libposix_translation_for_test.so') link_so = os.path.join( build_common.get_load_library_path_for_test(), 'libposix_translation.so') command = 'ln -sf %s %s' % ( os.path.join('../../lib/', os.path.basename(orig_so)), link_so) n.build(link_so, 'run_shell_command', implicit=orig_so, variables={'command': command})