def run(environ): exe_file = ft.download(environ, 'exe_file', 'exe', add_to_cache=True) os.chmod(exe_file, 0700) in_file = ft.download(environ, 'in_file', 'in', add_to_cache=True) env = os.environ.copy() for key, default in _options: value = environ.get('exec_' + key.lower(), default) env[key] = value with get_sandbox('vcpu_exec-sandbox') as sandbox: retcode, output = execute( [os.path.join(sandbox.path, 'pin-supervisor/supervisor-bin/', 'supervisor'), '-f', '3', '--', './exe', noquote('<'), 'in', noquote('3>'), 'supervisor_result', noquote('>'), 'out'], env=env) result_file = open('supervisor_result') status_line = result_file.readline().strip().split() environ['result_string'] = result_file.readline().strip() result_file.close() try: for num, key in enumerate((None, 'result_code', 'time_used', 'exectime_used', 'mem_used', 'num_syscalls')): if key: environ[key] = int(status_line[num]) result_code = _supervisor_result_to_code(environ['result_code']) except Exception, e: result_code = 'SE' for i in ('time_used', 'exectime_used', 'mem_used', 'num_syscalls'): environ.setdefault(i, 0) environ['result_string'] = str(e)
def run(environ, no_sandbox=False): ft.download(environ, 'out_file', 'out', skip_if_exists=True) ft.download(environ, 'hint_file', 'hint', add_to_cache=True) if environ.get('chk_file'): sandbox = NullSandbox() ft.download(environ, 'in_file', 'in', skip_if_exists=True, add_to_cache=True) ft.download(environ, 'chk_file', 'chk', add_to_cache=True) os.chmod('chk', 0700) cmd = ['./chk', 'in', 'out', 'hint', noquote('2>'), '/dev/null'] elif no_sandbox: sandbox = NullSandbox() cmd = ['diff', '-b', '-q', 'out', 'hint', noquote('>'), '/dev/null', noquote('2>&1'), noquote('&&'), 'echo', 'OK'] else: sandbox = get_sandbox('exec-sandbox') cmd = [os.path.join(sandbox.path, 'bin', 'compare'), 'hint', 'out', noquote('2>'), '/dev/null'] with sandbox: retcode, output = execute(cmd, ignore_errors=True, split_lines=True) while len(output) < 3: output.append('') if output[0] == 'OK': environ['result_code'] = 'OK' if output[1]: environ['result_string'] = output[1] environ['result_percentage'] = float(output[2] or 100) else: environ['result_code'] = 'WA' environ['result_string'] = output[1] environ['result_percentage'] = 0 return environ