def getExtraMakeArgs(self): """ Helper function to return extra argumentsfor the make system. This method is meant to be overridden by platform specific builders. """ args = dict() if configuration.dsymutil: args['DSYMUTIL'] = configuration.dsymutil if configuration.apple_sdk and 'internal' in configuration.apple_sdk: sdk_root = lldbutil.get_xcode_sdk_root(configuration.apple_sdk) if sdk_root: private_frameworks = os.path.join(sdk_root, 'System', 'Library', 'PrivateFrameworks') args['FRAMEWORK_INCLUDES'] = '-F{}'.format(private_frameworks) operating_system, env = get_os_and_env() if operating_system and operating_system != "macosx": builder_dir = os.path.dirname(os.path.abspath(__file__)) test_dir = os.path.dirname(builder_dir) if env == "simulator": entitlements_file = 'entitlements-simulator.plist' else: entitlements_file = 'entitlements.plist' entitlements = os.path.join(test_dir, 'make', entitlements_file) args['CODESIGN'] = 'codesign --entitlements {}'.format( entitlements) else: args['CODESIGN'] = 'codesign' # Return extra args as a formatted string. return ['{}={}'.format(key, value) for key, value in args.items()]
def run_with(self, arch, os, vers, env, expected_load_command): env_list = [env] if env else [] triple = '-'.join([arch, 'apple', os + vers] + env_list) sdk = lldbutil.get_xcode_sdk(os, env) version_min = '' if not vers: vers = lldbutil.get_xcode_sdk_version(sdk) if env == 'simulator': version_min = '-m{}-simulator-version-min={}'.format(os, vers) elif os == 'macosx': version_min = '-m{}-version-min={}'.format(os, vers) sdk_root = lldbutil.get_xcode_sdk_root(sdk) clang = lldbutil.get_xcode_clang(sdk) self.build( dictionary={ 'ARCH': arch, 'CC': clang, 'ARCH_CFLAGS': '-target {} {}'.format(triple, version_min), 'SDKROOT': sdk_root }) self.check_load_commands(expected_load_command) log = self.getBuildArtifact('packets.log') self.expect("log enable gdb-remote packets -f "+log) lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("hello.c")) triple_re = '-'.join([arch, 'apple', os + vers+'.*'] + env_list) self.expect('image list -b -t', patterns=['a\.out '+triple_re]) self.check_debugserver(log, os+env, vers)
def check_simulator_ostype(self, sdk, platform_name, arch=platform.machine()): cmd = ['xcrun', 'simctl', 'list', '-j', 'devices'] self.trace(' '.join(cmd)) sim_devices_str = subprocess.check_output(cmd).decode("utf-8") sim_devices = json.loads(sim_devices_str)['devices'] # Find an available simulator for the requested platform deviceUDID = None deviceRuntime = None for simulator in sim_devices: if isinstance(simulator, dict): runtime = simulator['name'] devices = simulator['devices'] else: runtime = simulator devices = sim_devices[simulator] if not platform_name in runtime.lower(): continue for device in devices: if 'availability' in device and device[ 'availability'] != '(available)': continue if 'isAvailable' in device and device['isAvailable'] != True: continue if deviceRuntime and runtime < deviceRuntime: continue deviceUDID = device['udid'] deviceRuntime = runtime # Stop searching in this runtime break # Launch the process using simctl self.assertIsNotNone(deviceUDID) exe_name = 'test_simulator_platform_{}'.format(platform_name) sdkroot = lldbutil.get_xcode_sdk_root(sdk) vers = lldbutil.get_xcode_sdk_version(sdk) clang = lldbutil.get_xcode_clang(sdk) # Older versions of watchOS (<7.0) only support i386 if platform_name == 'watchos': from distutils.version import LooseVersion if LooseVersion(vers) < LooseVersion("7.0"): arch = 'i386' triple = '-'.join([arch, 'apple', platform_name + vers, 'simulator']) version_min = '-m{}-simulator-version-min={}'.format( platform_name, vers) self.build( dictionary={ 'EXE': exe_name, 'CC': clang, 'SDKROOT': sdkroot.strip(), 'ARCH': arch, 'ARCH_CFLAGS': '-target {} {}'.format(triple, version_min), }) exe_path = self.getBuildArtifact(exe_name) cmd = [ 'xcrun', 'simctl', 'spawn', '-s', deviceUDID, exe_path, 'print-pid', 'sleep:10' ] self.trace(' '.join(cmd)) sim_launcher = subprocess.Popen(cmd, stderr=subprocess.PIPE) # Get the PID from the process output pid = None # Read the first READ_LINES to try to find the PID. for _ in range(0, self.READ_LINES): stderr = sim_launcher.stderr.readline().decode("utf-8") if not stderr: continue match = re.match(r"PID: (.*)", stderr) if match: pid = int(match.group(1)) break # Make sure we found the PID. self.assertIsNotNone(pid) # Launch debug monitor attaching to the simulated process server = self.connect_to_debug_monitor(attach_pid=pid) # Setup packet sequences self.do_handshake() self.add_process_info_collection_packets() self.test_sequence.add_log_lines([ "read packet: " + "$jGetLoadedDynamicLibrariesInfos:{\"fetch_all_solibs\" : true}]#ce", { "direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": { 1: "dylib_info_raw" } } ], True) # Run the stream context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Gather process info response process_info = self.parse_process_info_response(context) self.assertIsNotNone(process_info) # Check that ostype is correct self.assertEquals(process_info['ostype'], platform_name + 'simulator') # Now for dylibs dylib_info_raw = context.get("dylib_info_raw") dylib_info = json.loads(self.decode_gdbremote_binary(dylib_info_raw)) images = dylib_info['images'] image_info = None for image in images: if image['pathname'] != exe_path: continue image_info = image break self.assertIsNotNone(image_info) self.assertEquals(image['min_version_os_name'], platform_name + 'simulator')
def check_simulator_ostype(self, sdk, platform, arch='x86_64'): sim_devices_str = subprocess.check_output( ['xcrun', 'simctl', 'list', '-j', 'devices']).decode("utf-8") sim_devices = json.loads(sim_devices_str)['devices'] # Find an available simulator for the requested platform deviceUDID = None deviceRuntime = None for simulator in sim_devices: if isinstance(simulator, dict): runtime = simulator['name'] devices = simulator['devices'] else: runtime = simulator devices = sim_devices[simulator] if not platform in runtime.lower(): continue for device in devices: if 'availability' in device and device[ 'availability'] != '(available)': continue if 'isAvailable' in device and device['isAvailable'] != True: continue if deviceRuntime and runtime < deviceRuntime: continue deviceUDID = device['udid'] deviceRuntime = runtime # Stop searching in this runtime break # Launch the process using simctl self.assertIsNotNone(deviceUDID) exe_name = 'test_simulator_platform_{}'.format(platform) sdkroot = lldbutil.get_xcode_sdk_root(sdk) self.build(dictionary={ 'EXE': exe_name, 'SDKROOT': sdkroot.strip(), 'ARCH': arch }) exe_path = self.getBuildArtifact(exe_name) sim_launcher = subprocess.Popen([ 'xcrun', 'simctl', 'spawn', '-s', deviceUDID, exe_path, 'print-pid', 'sleep:10' ], stderr=subprocess.PIPE) # Get the PID from the process output pid = None while not pid: stderr = sim_launcher.stderr.readline().decode("utf-8") if stderr == '': continue m = re.match(r"PID: (.*)", stderr) self.assertIsNotNone(m) pid = int(m.group(1)) # Launch debug monitor attaching to the simulated process self.init_debugserver_test() server = self.connect_to_debug_monitor(attach_pid=pid) # Setup packet sequences self.add_no_ack_remote_stream() self.add_process_info_collection_packets() self.test_sequence.add_log_lines([ "read packet: " + "$jGetLoadedDynamicLibrariesInfos:{\"fetch_all_solibs\" : true}]#ce", { "direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": { 1: "dylib_info_raw" } } ], True) # Run the stream context = self.expect_gdbremote_sequence() self.assertIsNotNone(context) # Gather process info response process_info = self.parse_process_info_response(context) self.assertIsNotNone(process_info) # Check that ostype is correct self.assertEquals(process_info['ostype'], platform + 'simulator') # Now for dylibs dylib_info_raw = context.get("dylib_info_raw") dylib_info = json.loads(self.decode_gdbremote_binary(dylib_info_raw)) images = dylib_info['images'] image_info = None for image in images: if image['pathname'] != exe_path: continue image_info = image break self.assertIsNotNone(image_info) self.assertEquals(image['min_version_os_name'], platform + 'simulator')