vm_snapshot = kwargs['name[:snapshot]'].split(':') kwargs['name'] = vm_snapshot[0] kwargs['snapshot'] = vm_snapshot[1] if len(vm_snapshot) > 1 else None return kwargs @staticmethod def vm_init(path: str): utils.pend("initialise VM directory: %s" % path) try: os.mkdir(path) except OSError as e: utils.fail(e.strip()) exit(1) utils.ok() if __name__ == '__main__': # Parse command line arguments: args = VM.parse_args(sys.argv) utils.parse_build(args['build']) # Check environment: if not os.path.isdir(utils.CHEFROOT_VM): VM.vm_init(utils.CHEFROOT_VM) # Create VM and handle action: vm = VM(name=args.get('name', None)) exit(args['action'](vm, **args))
def assemble_qemu_cmd_line(args): qemu_cmd_line = [] # Debug: if args['gdb']: qemu_cmd_line.extend(['gdb', '--args']) if args['strace']: qemu_cmd_line.append('strace') # Qemu path: utils.parse_build(args['build']) arch, target, mode = utils.ARCH, utils.TARGET, utils.MODE qemu_path = os.path.join( utils.CHEFROOT_BUILD, '%s-%s-%s' % (arch, target, mode), 'qemu', '%s%s-softmmu' % (arch, ('', '-s2e')[args['mode'] == 'sym']), 'qemu-system-%s' % arch ) # Base command: qemu_cmd_line.append(qemu_path); # VM: vm = VM(args['VM']) if not os.path.exists(vm.path_raw): utils.fail('%s: VM does not exist' % vm.name) exit(1) # VM image: if args['mode'] == 'kvm': qemu_drive_options = 'if=virtio,format=raw' else: qemu_drive_options = 'cache=writeback,format=s2e' qemu_cmd_line.extend([ '-drive', 'file=%s,%s' % (vm.path_raw, qemu_drive_options) ]) # Snapshots: if args['snapshot']: if args['snapshot'] not in vm.snapshots: utils.fail("%s: no such snapshot" % args['snapshot']) qemu_cmd_line.extend(['-loadvm', args['snapshot']]) # General: CPU, memory, qemu monitor, VNC: qemu_cmd_line.extend([ # Non-Pentium instructions cause spurious concretizations '-cpu', 'pentium', '-m', args['memory'], ]) if args['headless']: qemu_cmd_line.extend([ '-vnc', ':%d' % args['vnc_display'], '-monitor', 'tcp::%d,server,nowait' % args['monitor_port'], ]) # Network: if args['network'] == 'none': qemu_cmd_line.extend(['-net', 'none']) else: # The only network device supported by S2E, IIRC qemu_cmd_line.extend(['-net', 'nic,model=pcnet']) if args['network'] == 'tap': qemu_cmd_line.extend(['-net', 'tap,ifname=%s' % TAP_INTERFACE]) else: qemu_cmd_line.extend(['-net', 'user']) if args['mode'] == 'sym' and (args['script'] or args['command']): qemu_cmd_line.extend([ '-redir', 'tcp:%d::4321' % args['command_port'] ]) # Mode-specific: KVM: if args['mode'] == 'kvm': qemu_cmd_line.extend(['-enable-kvm', '-smp', str(args['cores'])]) # Mode-specific: Symbolic: if args['mode'] == 'sym': qemu_cmd_line.extend([ '-s2e-config-file', args['config_file'], '-s2e-verbose' ]) qemu_cmd_line.extend(['-s2e-output-dir', args['exppath']]) # User-defined qemu options: if args['qemu_opt']: qemu_cmd_line.extend(args['qemu_opt']) return qemu_cmd_line