Exemplo n.º 1
0
 def checker(space):
     a = proxy_for_type(ta, space, 'a')
     b = proxy_for_type(tb, space, 'b')
     if a != va:
         raise IgnoreAttempt('symbolic a not equal to literal a')
     if b != vb:
         raise IgnoreAttempt('symbolic b not equal to literal b')
     return eval(expr)
Exemplo n.º 2
0
 def checker(space):
     a = proxy_for_type(ta, space, 'a')
     b = proxy_for_type(tb, space, 'b')
     if a != va:
         raise IgnoreAttempt
     if b != vb:
         raise IgnoreAttempt
     return eval(expr)
Exemplo n.º 3
0
 def symbolic_checker(space: TrackingStateSpace) -> object:
     symbolic_args = {
         name: proxy_for_type(typ, space, name)
         for name, typ in typed_args.items()
     }
     for name in typed_args.keys():
         if literal_args[name] != symbolic_args[name]:
             raise IgnoreAttempt('symbolic a not equal to literal a')
     return eval(expr, symbolic_args)
 def symbolic_run(
     self,
     fn: Callable[[StateSpace, Dict[str, object]], object],
     typed_args: Dict[str, type],
 ) -> Tuple[object,  # return value
            Optional[Dict[str, object]],  # arguments after execution
            Optional[BaseException],  # exception thrown, if any
            StateSpace, ]:
     search_root = SinglePathNode(True)
     with COMPOSITE_TRACER, Patched():
         for itr in range(1, 200):
             debug("iteration", itr)
             space = StateSpace(time.monotonic() + 10.0,
                                1.0,
                                search_root=search_root)
             symbolic_args = {}
             try:
                 with StateSpaceContext(space):
                     symbolic_args = {
                         name: proxy_for_type(typ, name)
                         for name, typ in typed_args.items()
                     }
                     ret = fn(space, symbolic_args)
                     ret = (deep_realize(ret), symbolic_args, None, space)
                     space.check_deferred_assumptions()
                     return ret
             except IgnoreAttempt as e:
                 debug("ignore iteration attempt: ", str(e))
                 pass
             except BaseException as e:
                 debug(traceback.format_exc())
                 return (None, symbolic_args, e, space)
             top_analysis, space_exhausted = space.bubble_status(
                 CallAnalysis())
             if space_exhausted:
                 return (
                     None,
                     symbolic_args,
                     CrosshairInternal(f"exhausted after {itr} iterations"),
                     space,
                 )
     return (
         None,
         None,
         CrosshairInternal(
             "Unable to find a successful symbolic execution"),
         space,
     )
Exemplo n.º 5
0
 def symbolic_checker(space: TrackingStateSpace) -> object:
     symbolic_args = {
         name: proxy_for_type(typ, name)
         for name, typ in typed_args.items()
     }
     for name in typed_args.keys():
         literal, symbolic = literal_args[name], symbolic_args[name]
         if isinstance(literal, (set, dict)):
             # We need not only equality, but equal ordering, because some operations
             # like pop() are order-dependent:
             if len(literal) != len(symbolic):
                 raise IgnoreAttempt(
                     f'symbolic "{name}" not equal to literal "{name}"')
             if isinstance(literal, set):
                 literal, symbolic = list(literal), list(symbolic)
             else:
                 literal, symbolic = list(literal.items()), list(
                     symbolic.items())
         if literal != symbolic:
             raise IgnoreAttempt(
                 f'symbolic "{name}" not equal to literal "{name}"')
     return eval(expr, symbolic_args)
Exemplo n.º 6
0
def test_access_class_method_on_symbolic_type():
    with standalone_statespace as space:
        person = proxy_for_type(Type[Person], "p")
        person.a_class_method(42)  # Just check that this don't explode