def execute_step(self, step): action, value = step if action == 'init': self.size = value mpipe.write(self.proc, (func_init_e, self.size)) assert mpipe.read(self.proc) == [0] elif action == 'acquire': mpipe.write(self.proc, (func_acquire_e, 0)) id_ = mpipe.read(self.proc)[0] if len(self.acquired) > self.size - 1: assert id_ == -1 if id_ != -1: self.acquired.add(id_) elif action == 'release': if value in self.acquired: mpipe.write(self.proc, (func_release_e, value)) assert mpipe.read(self.proc) == [0] self.acquired.remove(value) else: try: mpipe.write(self.proc, (func_release_e, value)) assert mpipe.read(self.proc) == [0] except Exception: self.reinit() else: assert False, "Test binary has to assert" else: assert False, "Unknown step"
def teardown(self): if self.etest_ready: self.dead.close() self.dead = None ret = 1 proc = self.proc echo = self.echo try: try: self.check_messages() mpipe.write(proc, (func_cleanup_e, 0)) ret = mpipe.read(proc)[0] finally: mpipe.close(proc) finally: try: if self.echo_ready: close(echo) finally: self.proc = None self.echo = None assert ret == 0 if self.echo_ready: assert echo.returncode == 0 assert proc.returncode == 0
def send_message(): mpipe.write( self.proc, (func_send_message_e, value[0], value[1], int(self.echo_ready)) ) msg_id, ret = mpipe.read(self.proc) assert msg_id not in self.open_messages assert ret == 0 self.open_messages.add(msg_id)
def execute_step(self, step): action, value = step if action == 'init': self.size = value mpipe.write( self.proc, (func_init_e, self.size) ) assert mpipe.read(self.proc) == [0] elif action == 'acquire': mpipe.write( self.proc, (func_acquire_e, 0) ) id_ = mpipe.read(self.proc)[0] if len(self.acquired) > self.size - 1: assert id_ == -1 if id_ != -1: self.acquired.add(id_) elif action == 'release': if value in self.acquired: mpipe.write( self.proc, (func_release_e, value) ) assert mpipe.read(self.proc) == [0] self.acquired.remove(value) else: try: mpipe.write( self.proc, (func_release_e, value) ) assert mpipe.read(self.proc) == [0] except Exception: self.reinit() else: assert False, "Test binary has to assert" else: assert False, "Unknown step"
def execute_step(self, step): def send_message(): mpipe.write( self.proc, (func_send_message_e, value[0], value[1], int(self.echo_ready)) ) msg_id, ret = mpipe.read(self.proc) assert msg_id not in self.open_messages assert ret == 0 self.open_messages.add(msg_id) action, value = step if action == 'init_etest': self.enc = str(value[0]) self.shutdown = str(value[1]) self.synchronous = str(value[2]) self.fast = value[3] self.init_etest() elif action == 'init_echo': self.init_echo() elif action == 'fuzz_main_port': self.fuzz_main_port(value) elif action == '42': mpipe.write(self.proc, (func_42_e, )) if not self.fast: time.sleep(value) assert mpipe.read(self.proc) == [42] elif action == 'send_message': if not self.echo_ready: self.timeout_open = True send_message() elif action == 'send_message_bad_port': self.timeout_open = True send_message() elif action == 'check_messages': self.check_messages() elif action == 'shutdown_conns': mpipe.write(self.proc, (func_shutdown_conns_e, value)) assert mpipe.read(self.proc) == [0] else: assert False, "Unknown step"
def teardown(self): if self.initialized: mpipe.write(self.proc, (func_cleanup_e, 0)) assert mpipe.read(self.proc) == [0] mpipe.close(self.proc) self.proc = None # Hypothesis seems to keep GSM objects
def check_messages(self): mpipe.write(self.proc, (func_check_messages_e, )) ret = mpipe.read(self.proc) self.open_messages -= set(ret) assert not self.open_messages self.timeout_open = False