Exemplo n.º 1
0
    def _to_dot(self, list_rep):
        curr = self.curr_id
        if isinstance(list_rep, list) and len(list_rep) == 3:
            rep = list_rep[0]
            dot = "\"%s%d\" [ label=\"%s\" ];\n" % (rep, curr, rep)
            self.curr_id += 1

            for slot in range(1, 3):
                child = list_rep[slot]
                if child is None:
                    continue
                crep = child[0] if isinstance(child, list) else to_pysmt(child)
                crep = str(crep).replace('"', '\\\"')
                dot += "\"%s%d\" -> \"%s%d\" [ label=\"%d\" ];\n" \
                        %(rep, curr, crep, self.curr_id, slot%2)
                dot += self._to_dot(child)
            return dot
        elif list_rep is not None:
            list_rep = to_pysmt(list_rep)
            list_rep = str(list_rep).replace('"', '\\\"')
            temp = "\"%s%d\" [ label=\"%s\" ];\n" % (list_rep, curr, list_rep)
            self.curr_id += 1
            return temp
        else:
            return ""
Exemplo n.º 2
0
    def explore(self, funcs=[], lazy=True):
        original = self.engines[0]
        shadow = self.engines[1]
        r1, r2 = self._one_execution(funcs)
        if lazy:
            if not self.solver.get_py_value(Equals(to_pysmt(r1),
                                                   to_pysmt(r2))):
                logging.info("COUNTER! %s != %s", repr(r1), repr(r2))
                print("ORIG #Paths: %d" % len(original.path.generated_inputs))
                print("UPGR #Paths: %d" % len(shadow.path.generated_inputs))
                return self.engines[self.lead - 1].path.generated_inputs[-1]

        iterations = 1
        if self.max_iterations != 0 and iterations >= self.max_iterations:
            logging.debug("Maximum number of iterations reached, terminating")
            return (original.path, shadow.path)

        while not self.is_exploration_complete():
            selected = self.get_next_constraints()

            logging.debug("SELECTED CONSTRAINT: %s", selected)
            model = self.engines[self.lead].path.solve_constraint(selected)

            if not model:
                continue

            #TODO avoid executing things unnecesarily?
            r1, r2 = self._one_execution(funcs, selected)

            if lazy:
                if not self.solver.get_py_value(
                        Equals(to_pysmt(r1), to_pysmt(r2))):
                    logging.info("COUNTER! %s != %s", repr(r1), repr(r2))
                    print("ORIG #Paths: %d" %
                          len(original.path.generated_inputs))
                    print("UPGR #Paths: %d" %
                          len(shadow.path.generated_inputs))
                    return self.engines[self.lead -
                                        1].path.generated_inputs[-1]

            iterations += 1

            if self.max_iterations != 0 and iterations >= self.max_iterations:
                logging.debug(
                    "Maximum number of iterations reached, terminating")
                break

        return (original.path, shadow.path)
Exemplo n.º 3
0
 def __floordiv__(self, other):
     other = to_pysmt(other)
     if self.expr.get_type() != other.get_type() or self.expr.get_type(
     ) != INT:
         raise TypeError("CANNOT '//' %s and %s" %
                         (self.expr.get_type(), other.get_type()))
     return SymbolicInteger(self.expr // other)
Exemplo n.º 4
0
 def _to_summary(self, list_rep, unknown):
     if isinstance(list_rep, list) and len(list_rep) == 3:
         return Ite(list_rep[0], self._to_summary(list_rep[1], unknown),\
                     self._to_summary(list_rep[2], unknown))
     elif list_rep is not None:
         if isinstance(
                 list_rep, SymbolicObject
         ) or not is_instance_userdefined_and_newclass(list_rep):
             return match_smt_type(to_pysmt(list_rep), unknown.get_type())
         else:
             print(list_rep, type(list_rep))
             raise TypeError("Summaries don't support object returns")
     else:
         return unknown
Exemplo n.º 5
0
 def __mul__(self, other):
     other = to_pysmt(other)
     if self.expr.get_type() != other.get_type():
         raise TypeError("CANNOT '*' %s and %s" %
                         (self.expr.get_type(), other.get_type()))
     return SymbolicInteger(self.expr * other)