def summarize_execution( fn: Callable, args: Sequence[object] = (), kwargs: Mapping[str, object] = None, detach_path: bool = True, ) -> ExecutionResult: if not kwargs: kwargs = {} ret = None exc = None try: symbolic_ret = fn(*args, **kwargs) if detach_path: context_statespace().detach_path() _ret = realize(symbolic_ret) # TODO, this covers up potential issues with return types. Handle differently? # summarize iterators as the values they produce: if hasattr(_ret, "__next__"): ret = list(_ret) else: ret = _ret except BaseException as e: if isinstance(e, (UnexploredPath, IgnoreAttempt)): raise if in_debug(): debug("hit exception:", type(e), e, test_stack(e.__traceback__)) exc = e if detach_path: context_statespace().detach_path() args = tuple(realize(a) for a in args) kwargs = {k: realize(v) for (k, v) in kwargs.items()} return ExecutionResult(ret, exc, args, kwargs)
def find_model_value(self, expr: z3.ExprRef) -> object: with NoTracing(): while True: if self.search_position.is_stem(): self.search_position = self.search_position.grow_into( ModelValueNode(self._random, expr, self.solver)) node = self.search_position.simplify() assert isinstance(node, ModelValueNode) (chosen, next_node) = node.choose(favor_true=True) self.choices_made.append(node) self.search_position = next_node if chosen: self.solver.add(expr == node.condition_value) ret = model_value_to_python(node.condition_value) if in_debug(): debug("SMT realized symbolic:", expr, "==", repr(ret)) debug("Realized at", test_stack()) return ret else: self.solver.add(expr != node.condition_value)
def find_model_value(self, expr: z3.ExprRef) -> object: with self.framework(): while True: if self.search_position.is_stem(): self.search_position = self.search_position.grow_into( ModelValueNode(self._random, expr, self.solver)) node = self.search_position.simplify() assert isinstance(node, ModelValueNode) (chosen, next_node) = node.choose(favor_true=True) self.choices_made.append(node) self.search_position = next_node if chosen: self.solver.add(expr == node.condition_value) if in_debug(): debug('SMT realized symbolic:', expr == node.condition_value) debug('Realized at', tiny_stack()) return model_value_to_python(node.condition_value) else: self.solver.add(expr != node.condition_value)
def summarize_execution( fn: Callable, args: Sequence[object] = (), kwargs: Mapping[str, object] = None) -> ExecutionResult: if not kwargs: kwargs = {} ret = None exc = None try: _ret = realize(fn(*args, **kwargs)) # summarize iterators as the values they produce: if hasattr(_ret, "__next__"): ret = list(_ret) else: ret = _ret except BaseException as e: if isinstance(e, (UnexploredPath, IgnoreAttempt)): raise if in_debug(): debug(type(e), e, test_stack(e.__traceback__)) exc = e args = tuple(realize(a) for a in args) kwargs = {k: realize(v) for (k, v) in kwargs.items()} return ExecutionResult(ret, exc, args, kwargs)