def test_strsignal(self): self.assertIn("Interrupt", signal.strsignal(signal.SIGINT)) self.assertIn("Terminated", signal.strsignal(signal.SIGTERM)) self.assertIn("Hangup", signal.strsignal(signal.SIGHUP))
def update_event(self, inp=-1): self.set_output_val(0, signal.strsignal(self.input(0)))
def exit_gracefully(self, signum, frame): logging.debug("received '{}' signal".format(signal.strsignal(signum))) self.kill_now = True
def signal_handler(sig, frame): raise Exception(signal.strsignal(sig))
def handle(sig, frame): LOG.info("Received Signal: %s '%s'.", sig, signal.strsignal(sig)) raise SystemExit
def _handler(signum: int): sig = signal.strsignal(signum) or signum print(f'Got signal {sig}, will handle it now') time.sleep(1)
def quit(self, *args: Any, **kwargs: Any) -> None: signal_number = kwargs['signal_number'] signal_name = signal.strsignal(signal_number) if hasattr(signal, 'strsignal') else signal_number # type: ignore print('Received signal {0}; quiting'.format(signal_name)) os._exit(0)
def signal_handler(sig, frame): print("got signal: {}\n".format(signal.strsignal(sig))) global STOP_THREADS STOP_THREADS = True
def on_signal(self, signum, frame): desc = signal.strsignal(signum) self.stdout.write(f"{desc}, finishing...\n") self.shutdown = True
def test_dir(dir): num_tested = 0 num_passed = 0 fail_list = [] pass_list = [] files = os.listdir(dir) for file in tqdm(files): new_path = os.path.join(dir, file) if os.path.isdir(new_path) and args.recursively: result = test_dir(new_path) num_tested += result["num_tested"] num_passed += result["num_passed"] fail_list.extend(result["failed"]) pass_list.extend(result["passed"]) elif file.split('.')[-1] == 'sy': num_tested += 1 prefix = file.split('.')[0] try: compiler_output = subprocess.run( [args.compiler_path, new_path, "-d", "-o", "tmp.s"], capture_output=True, timeout=15) # compiler error if compiler_output.returncode != 0: logger.error(f"{new_path} encountered a compiler error") with open( format_compiler_output_file_name( new_path, 'stdout'), "w") as f: f.write(compiler_output.stdout.decode('utf-8')) fail_list.append({ "file": new_path, "reason": "compile_error", "return_code": compiler_output.returncode }) continue link_output = subprocess.run([ 'gcc', 'tmp.s', args.linked_library_path, '-march=armv7-a', "-o", "tmp" ], capture_output=True) # compiler error if link_output.returncode != 0: logger.error(f"{new_path} encountered a linker error") with open( format_linker_output_file_name(new_path, 'stdout'), "w") as f: f.write(link_output.stdout.decode('utf-8')) with open( format_compiler_output_file_name( new_path, 'stdout'), "w") as f: f.write(compiler_output.stdout.decode('utf-8')) with open( format_linker_output_file_name(new_path, 'stderr'), "w") as f: f.write(link_output.stderr.decode('utf-8')) fail_list.append({ "file": file, "reason": "link_error", "return_code": link_output.returncode }) continue except subprocess.TimeoutExpired as t: logger.error( f"{prefix} compiler time out!(longer than {t.timeout} seconds)" ) stdout = t.stdout if stdout != None: str_stdout = stdout.decode("utf-8") else: str_stdout = "" with open(format_compiler_output_file_name(new_path, 'stdout'), "wb") as f: f.write(stdout) fail_list.append({ "file": new_path, "reason": "compiler_timeout", }) continue try: if os.path.exists(os.path.join(dir, f"{prefix}.in")): f = open(os.path.join(dir, f"{prefix}.in"), 'r') process = subprocess.run(["./tmp"], stdin=f, capture_output=True, timeout=args.timeout) else: process = subprocess.run(["./tmp"], capture_output=True, timeout=args.timeout) return_code = process.returncode % 256 my_output = process.stdout.decode("utf-8").replace("\r", "") my_output = my_output.strip() limited_output = my_output[0:max_stdout] if len(my_output) > max_stdout: limited_output += "...(stripped)" if return_code < 0: sig = -return_code sig_def = signal.strsignal(sig) logger.error( f"{new_path} raised a runtime error with signal {sig} ({sig_def})" ) with open( format_compiler_output_file_name( new_path, 'stdout'), "w") as f: f.write(compiler_output.stdout.decode('utf-8')) dump_stdout(new_path, process.stdout) fail_list.append({ "file": new_path, "reason": "runtime_error", "got": limited_output, "error": sig_def }) else: with open(os.path.join(dir, f"{prefix}.out"), 'r') as f: std_output = f.read().replace("\r", "").strip() my_output_lines = [ x.strip() for x in my_output.splitlines() if x.strip() != '' ] std_output_lines = [ x.strip() for x in std_output.splitlines() if x.strip() != '' ] real_std_output = '\n'.join(std_output_lines) std_ret = int(std_output_lines.pop()) % 256 dump_stdout(new_path, process.stdout) if my_output_lines != std_output_lines: logger.error( f"mismatched output for {new_path}: \nexpected: {real_std_output}\ngot {my_output}" ) with open( format_compiler_output_file_name( new_path, 'stdout'), "w") as f: f.write(compiler_output.stdout.decode('utf-8')) fail_list.append({ "file": file, "reason": "wrong_output", "expected": real_std_output, "got": limited_output }) elif return_code != std_ret: logger.error( f"mismatched return code for {new_path}: \nexpected: {std_ret}\ngot {return_code}" ) with open( format_compiler_output_file_name( new_path, 'stdout'), "w") as f: f.write(compiler_output.stdout.decode('utf-8')) dump_stdout(new_path, process.stdout) fail_list.append({ "file": file, "reason": "wrong_return_code", "expected": std_ret, "got": return_code }) else: logger.info(f"Successfully passed {prefix}") pass_list.append(new_path) num_passed += 1 f.close() except subprocess.TimeoutExpired as t: logger.error( f"{prefix} time out!(longer than {t.timeout} seconds)") stdout = t.stdout if stdout != None: str_stdout = stdout.decode("utf-8") if len(str_stdout) > max_stdout: str_stdout = str_stdout[0:max_stdout] + "..." else: str_stdout = "" fail_list.append({ "file": new_path, "reason": "timeout", "got": str_stdout }) logger.info(f"passed {num_passed} of {num_tested} tests") if len(fail_list) > 0: logger.error(f"Failed tests: {fail_list}") return { "num_tested": num_tested, "num_passed": num_passed, "num_failed": num_tested - num_passed, "passed": pass_list, "failed": fail_list }