Пример #1
0
def get_intersection_from_observations(function_name, obs_id_list, inst_point=None):
    if inst_point == None:
        inst_point = observation(obs_id_list[0]).instrumentation_point

    # checking if all the observations are made at the same point
    for id in obs_id_list:
        obs = observation(id)
        if obs.instrumentation_point != inst_point:
            raise ValueError('the observations must have the same instrumentation point')

    f = function(fully_qualified_name=function_name)
    subchain_text = get_parametric_path(obs_id_list, inst_point)
    #    print(subchain_text)
    subchain_dict = json.loads(subchain_text)
    #    pprint(subchain_dict)

    seq = subchain_dict["intersection_condition_sequence"]
    scfg = f.get_graph()
    ipoint = instrumentation_point(inst_point)

    intersection_path = edges_from_condition_sequence(
        scfg,
        map(deserialise_condition, seq[1:]),
        ipoint.reaching_path_length
    )
    return intersection_path
Пример #2
0
def list_functions():
    str = urllib2.urlopen(get_server() + 'client/list_functions/').read()
    if str == "None":
        raise ValueError('no functions')
        return
    f_dict = json.loads(str)
    f_list = []
    for f in f_dict:
        f_class = function(f["id"], f["fully_qualified_name"], f["property"])
        f_list.append(f_class)
    return f_list
Пример #3
0
def list_functions():
    """
    Get a list of all existing functions from the server.
    """
    connection = get_connection()
    result = connection.request('client/function/')
    if result == "None":
        raise ValueError('No functions currently exist.')
    f_dict = json.loads(result)
    f_list = []
    for f in f_dict:
        f_obj = function(f["id"], f["fully_qualified_name"])
        f_list.append(f_obj)
    return f_list
Пример #4
0
    def to_paths(self, scfg):
        """
        Based on the relevant Symbolic Control-Flow Graph for the current collection of observations,
        reconstruct the paths up to each observation through the Symbolic Control-Flow Graph and return a
        ``PathCollection``.
        """

        connection = get_connection()

        # get the scfg of the function

        function_obj = function(
            function_call(
                verdict(
                    self._observations[0].verdict
                ).function_call
            ).function
        )

        function_name = function_obj.fully_qualified_name

        # get the path length of the instrumentation point of this
        # set of observations (assuming we deal with a single instrumentation point)

        reaching_path_length = instrumentation_point(
            self._observations[0].instrumentation_point
        ).reaching_path_length

        condition_sequences = []
        for observation in self._observations:
            result_dictionary = json.loads(
                connection.request("client/get_path_condition_sequence/%i/" % observation.id)
            )
            condition_sequence = result_dictionary["path_subchain"]

            #condition_sequence = map(deserialise_condition, condition_sequence)
            condition_sequences.append(condition_sequence)

        paths = []

        for condition_sequence in condition_sequences:
            reconstructed_path = edges_from_condition_sequence(scfg, condition_sequence, reaching_path_length)
            paths.append(reconstructed_path)

        return PathCollection(paths, scfg, function_name)
Пример #5
0
def get_paths_from_observations(function_name, obs_id_list, inst_point=None):
    """
    returns a list of paths taken before each of the given observations
    """

    if inst_point == None:
        inst_point = observation(obs_id_list[0]).instrumentation_point

    # checking if all the observations are made at the same point
    for id in obs_id_list:
        obs = observation(id)
        if obs.instrumentation_point != inst_point:
            raise ValueError('the observations must have the same instrumentation point')

    f = function(fully_qualified_name=function_name)
    subchain_text = get_parametric_path(obs_id_list, inst_point)
    subchain_dict = json.loads(subchain_text)

    paths = []
    seq = subchain_dict["intersection_condition_sequence"]

    for id in obs_id_list:

        subchain = []
        ind = 0

        while ind < len(seq):
            if seq[ind] == "parameter":
                cond = ((subchain_dict["parameter_maps"])["0"])[str(obs_id_list.index(id))]
                for cond_elem in cond:
                    #                    print(cond_elem)
                    subchain.append(deserialise_condition(cond_elem))
            else:
                subchain.append(seq[ind])
            ind += 1

        subchain = subchain[1:]
        scfg = f.get_graph()
        ipoint = instrumentation_point(inst_point)
        path = edges_from_condition_sequence(scfg, subchain, ipoint.reaching_path_length)
        paths.append(path)

    return paths
Пример #6
0
def get_intersection_from_observations(function_name, obs_id_list, inst_point):

    f = function(fully_qualified_name=function_name)
    subchain_text = get_parametric_path(obs_id_list, inst_point)
    print(subchain_text)
    subchain_dict = json.loads(subchain_text)
    pprint(subchain_dict)

    paths = []
    seq = subchain_dict["intersection_condition_sequence"]
    scfg = f.get_graph()
    ipoint = instrumentation_point(inst_point)

    intersection_path = edges_from_condition_sequence(
        scfg, map(deserialise_condition, seq[1:]), ipoint.reaching_path_length)
    print(
        "intersection with condition sequence \n%s\n path length %i is\n %s" %
        (str(seq[1:]), ipoint.reaching_path_length, str(intersection_path)))
    edit_code(intersection_path)
    print("------------------------------------------------")
    print(seq)
    return intersection_path
Пример #7
0
def get_paths_from_observations(function_name, obs_id_list, inst_point):
    """
    returns a list of paths taken before each of the given observations
    """

    f = function(fully_qualified_name=function_name)
    subchain_text = get_parametric_path(obs_id_list, inst_point)
    subchain_dict = json.loads(subchain_text)
    #pprint(subchain_dict)

    paths = []
    seq = subchain_dict["intersection_condition_sequence"]

    for id in obs_id_list:

        subchain = []
        ind = 0

        while ind < len(seq):
            if seq[ind] == "parameter":
                cond = ((subchain_dict["parameter_maps"])["0"])[str(
                    obs_id_list.index(id))]
                for cond_elem in cond:
                    print(cond_elem)
                    subchain.append(deserialise_condition(cond_elem))
            else:
                subchain.append(seq[ind])
            ind += 1

        subchain = subchain[1:]
        scfg = f.get_graph()
        ipoint = instrumentation_point(inst_point)
        path = edges_from_condition_sequence(scfg, subchain,
                                             ipoint.reaching_path_length)
        paths.append(path)

    return paths