Exemple #1
0
def gen_patch1v():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    fid_lst = []
    for i in fid_lc:
        if i not in [62, 97, 104, 119]:
            test_fun = inter_funcs[i]
            print test_fun
            var_num = bf.get_var_num(test_fun)
            name = "localize_res_files/" + test_fun[0] + ".pkl"
            rfp = lambda x: rf_f(i, x)
            temp_lst = bf.load_pickle(name)
            print len(temp_lst[-2][0])
            print len(temp_lst[0])
            print len(temp_lst[0][-1][-1])
            try:
                temp_lst = bf.load_pickle(name)
                if var_num == 1:
                    print temp_lst
                    # print test_fun
                    for j in temp_lst[0]:
                        ori_bound = j[0]
                        type = j[1]
                        print generate_1v_patch(j[-1], ori_bound, type, rfp)
                    #     print len(j[3])
                    #     if len(j[3]) > 10:
                    #         for idj in j[3][0:10]:
                    #             print idj
                    #     else:
                    #         for idj in j[3]:
                    #             print idj
                fid_lst.append(i)
            except IOError:
                continue
    print fid_lst
def cal_exceptions():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    eva_bound_lst = bf.load_pickle("eva_bound_lst.plk")
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    cal_num = 0
    name_lst = []
    for fid in range(0, len(inter_funcs)):
        # fid = 14
        flag = 0
        test_fun = inter_funcs[fid]
        fun_pu, stat_fun = load_pure_fun(test_fun[0])
        i = sum_lst[fid]
        print test_fun
        fpe_lst = []
        for j in range(0, len(i[2]), 2):
            bt = i[2][j]
            res_lst = i[2][j + 1]
            if bt == 3:
                fpe_lst.append(res_lst[0][0] + res_lst[0][1] + res_lst[0][2])
        count = 0
        rf = lambda x: rf_f(fid, x)
        new_bounds = []
        # new_bounds.append(fid)
        # new_bounds.append(test_fun[0])
        var_num = bf.get_var_num(test_fun)
        print eva_bound_lst[fid]
        for i in eva_bound_lst[fid][2:]:
            print i
            ret_vals = i[0][1]
            num_excp = i[0][0]
            bt = get_bound_type(ret_vals, num_excp)
            bound = i[1]
            inp_lst = []
            loc_inps = []
            # print bound
            if (bt == 3) & (fid != 97):
                inp_lst = FPexcption_detector_whole(fun_pu, stat_fun, bound)
                inp_lst = inp_lst + fpe_lst[count]
                count = count + 1
                for ti in inp_lst:
                    res_p = fun_pu(*ti)
                    res_rf = float(rf(ti))
                    ty_f = classifer(res_p.val, res_rf, stat_fun())
                    if ty_f != 0:
                        loc_inps.append(ti)
                        flag = 1
        if flag == 1:
            name_lst.append([fid, test_fun[1]])
            cal_num = cal_num + 1
    print cal_num
    print cal_num
    for nai in name_lst:
        print nai
Exemple #3
0
def plot_compare_timeoverhead():
    be_res_list = []
    af_res_list = []
    name = 'papergraph/time_overhead_whole'
    bbpf_time_l = bf.load_pickle(
        "/home/yixin/PycharmProjects/ARFPE/arfpe/papergraph/time_before_repair.pkl"
    )
    abpf_time_l = bf.load_pickle(
        "/home/yixin/PycharmProjects/ARFPE/arfpe/papergraph/time_after_repair.pkl"
    )
    z1, y1 = process_cumulative_dis_time(bbpf_time_l, abpf_time_l)
    be_res_list.append(z1)
    af_res_list.append(y1)

    count = 0
    color_type = ['k--', 'k-']
    tool_name = ['']
    # fig = plt.figure(figsize=(14, 12))
    ax = plt.subplot(111)
    # print be_res_list
    # print af_res_list
    for i, j in zip(be_res_list, af_res_list):
        ax.plot(i, j, color_type[count])
        count = count + 1
    ylabels = [r'0\%']
    for i in np.arange(0, 105, 20):
        ylabels.append(str(i) + "\%")
    ax.set_yticks(np.arange(0, 1.1, 0.2), ylabels)
    for tick in ax.xaxis.get_major_ticks():
        tick.label.set_fontsize(12)
        # ax.set_xticks(np.arange(0.5, 1.3, 0.1))
    # ax.set_xticklabels(['0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2'], fontsize=12)
    # plt.yticks(np.arange(0, 1.1, 0.2), ylabel)
    # plt.ylabel('% of benchmarks',fontsize=16)
    ax.set_yticklabels(ylabels, fontsize=12)
    ax.set_ylabel(r'\% of benchmarks', fontsize=16)
    # plt.xlabel('Time overhead ratio: Repair program/origin program',fontsize=20)
    ax.legend(loc=4, prop={'size': 14})
    ax.grid(True)
    # plt.ylim([0,1.1])
    plt.savefig(name + ".pdf", format="pdf")
    plt.show()


# plot_compare_timeoverhead()
Exemple #4
0
def gen_boudary_test4allfuncs():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    count = 0
    for i in inter_funcs:
        print i
        print count
        count = count + 1
        # gen_boudary_test_function(i)
        # gen_divzero_test_function(i)
        gen_pure_test_function(i)
Exemple #5
0
def find_file4func(fun_name):
    # gsl_26_calls store depends analysis results produced by produce_call_dps function in proprecess
    calls_lst = bf.load_pickle('gsl_26_calls')
    file_list = []
    count = 0
    for i in calls_lst:
        if fun_name == i[0]:
            file_list = i[2]
            break
    return file_list[0]
Exemple #6
0
def plot_local_res():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    for i in range(0, len(inter_funcs)):
        if i not in [62, 97, 104, 119]:
            test_fun = inter_funcs[i]
            var_num = bf.get_var_num(test_fun)
            name = "plot_bounds_res/" + test_fun[0] + ".pkl"
            name2 = "localize_res_files/" + test_fun[0] + ".pkl"
            try:
                print test_fun
                temp_lst = bf.load_pickle(name)
                temp_lst2 = bf.load_pickle(name2)
                if var_num == 1:
                    plot_1func_domain(temp_lst)
                else:
                    plot_2vfunc_domain(temp_lst)
            except IOError:
                continue
Exemple #7
0
def get_repairing_time():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    time_lst = []
    repair_time = []
    for i in fid_lc:
        test_fun = inter_funcs[i]
        print test_fun
        var_num = bf.get_var_num(test_fun)
        name2 = "final_res_files/" + test_fun[0] + ".pkl"
        name3 = "localize_res_files/" + test_fun[0] + ".pkl"
        name4 = "repair_res_files/" + test_fun[0] + ".pkl"
        det_res = bf.load_pickle(name2)
        loc_res = bf.load_pickle(name3)
        rep_res = bf.load_pickle(name4)
        for ri in rep_res[0:-1]:
            print ri[-1]
        temp_t = det_res[-1] + [loc_res[-1] , rep_res[-1]]
        # print temp_t
        time_lst.append(temp_t)
    sum_time_lst = []
    count = 0
    for i in time_lst:
        sum_time = 0
        for j in i:
            sum_time = sum_time + j
        sum_time_lst.append(sum_time)
        # if sum_time > 1000:
        print sum_time
        print inter_funcs[fid_lc[count]]
        count = count + 1
    print np.max(sum_time_lst)
    print np.min(sum_time_lst)
    count = 0
    for i in sum_time_lst:
        if i < 1000:
            count = count + 1
    print count
    print count-len(sum_time_lst)
    tot_time = 0
    for i in sum_time_lst:
        tot_time = i + tot_time
    print tot_time
Exemple #8
0
def repair4all():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    for i in fid_lc:
        test_fun = inter_funcs[i]
        print test_fun
        var_num = bf.get_var_num(test_fun)
        name = "localize_res_files/" + test_fun[0] + ".pkl"
        name2 = "repair_res_files/" + test_fun[0] + ".pkl"
        rfp = lambda x: rf_f(i, x)
        fun_pu, stat_fun = load_pure_fun(test_fun[0])
        temp_lst = bf.load_pickle(name)
        st_time = time.time()
        repair_lst = []
        if var_num == 2:
            for j in temp_lst[0]:
                print j[0]
                print j[1]
                print len(j[-1])
                if len(j[-1]) >= 2:
                    repair_code = generate_2v_patch(4)
                    repair_lst.append([j[0], j[-1], repair_code])
                else:
                    typ_j = classify_bound(j[-1][0], rfp, fun_pu, stat_fun)
                    repair_code = generate_2v_patch(typ_j)
                    repair_lst.append([j[0], j[-1], repair_code])
        else:
            for j in temp_lst[0]:
                if len(j[-1]) >= 2:
                    repair_code = generate_2v_patch(4)
                    repair_lst.append([j[0], j[-1], repair_code])
                else:
                    typ_j = classify_bound(j[-1][0], rfp, fun_pu, stat_fun)
                    repair_code = generate_1v_patch(j[-1][0], j[0], typ_j, rfp)
                    print "repair_code"
                    print repair_code
                    repair_lst.append([j[0], j[-1], repair_code])
        et = time.time() - st_time
        repair_lst.append(et)
        bf.pickle_fun(name2, repair_lst)
Exemple #9
0
def load_local_res():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    for i in range(0, len(inter_funcs)):
        if i not in [62, 97, 104, 119]:
            test_fun = inter_funcs[i]
            name = "localize_res_files/" + test_fun[0] + ".pkl"
            try:
                temp_lst = bf.load_pickle(name)
                print test_fun
                # print len(temp_lst)
                # print len(temp_lst[0])
                print i
                for j in temp_lst[0]:
                    print len(j[3])
                    if len(j[3]) > 10:
                        for idj in j[3][0:10]:
                            print idj
                    else:
                        for idj in j[3]:
                            print idj
            except IOError:
                continue
Exemple #10
0
def gen_patch():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    fid_lst = []
    for i in range(0, len(inter_funcs)):
        if i not in [62, 97, 104, 119]:
            test_fun = inter_funcs[i]
            var_num = bf.get_var_num(test_fun)
            name = "localize_res_files/" + test_fun[0] + ".pkl"
            try:
                temp_lst = bf.load_pickle(name)
                if var_num == 1:
                    for j in temp_lst[0]:
                        print len(j[3])
                        if len(j[3]) > 10:
                            for idj in j[3][0:10]:
                                print idj
                        else:
                            for idj in j[3]:
                                print idj
                    fid_lst.append(i)
            except IOError:
                continue
    print len(fid_lst)
Exemple #11
0
def get_detecting_time():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    time_lst = []
    repair_time = []
    for i in fid_de:
        test_fun = inter_funcs[i]
        # print test_fun
        var_num = bf.get_var_num(test_fun)
        name2 = "final_res_files/" + test_fun[0] + ".pkl"
        det_res = bf.load_pickle(name2)
        # print det_res[-1]
        time_lst.append(det_res[-1])
    sum_time_lst = []
    count = 0
    for i in time_lst:
        sum_time = 0
        for j in i:
            sum_time = sum_time + j
        sum_time_lst.append(sum_time)
        if sum_time > 1000:
            print sum_time
            # print inter_funcs[fid_lc[count]]
        count = count + 1

    print np.max(sum_time_lst)
    print np.min(sum_time_lst)
    count = 0
    for i in sum_time_lst:
        if i < 1000:
            count = count + 1
    print count
    print count-len(sum_time_lst)
    tot_time = 0
    for i in sum_time_lst:
        tot_time = i + tot_time
    print tot_time
Exemple #12
0
def load_fun_debug(fun_name):
    inter_funcs = bf.load_pickle('fun_index.pkl')
    ### [fun_name, [[var_typ,var_name]..]]
    test_fun = found_funbyName(fun_name, inter_funcs)
    lib_ld = ctypes.CDLL('../benchmark/driver_funcs/boudary_analysis/' +
                         test_fun[0] + '/libgslbc.so')
    lib_fun = lib_ld.gslfdr
    lib_w = ctypes.c_double.in_dll(lib_ld, "w")
    lib_idx = ctypes.c_int.in_dll(lib_ld, "idx")
    lib_ld.gslfdr.restype = ctypes.c_double
    vartyp_lst = []
    for i in test_fun[1]:
        if i[0] == 'double':
            vartyp_lst.append(ctypes.c_double)
        if i[0] == 'int':
            vartyp_lst.append(ctypes.c_int)
    lib_ld.gslfdr.argtypes = vartyp_lst
    return lib_fun, [lib_w, lib_idx]
Exemple #13
0
def patch_size_evaluation():
    patch_sz_lst = []
    repair_res = []
    cout = 0
    for i in fid_lc:
        test_fun = inter_funcs[i]
        print test_fun
        size_file = os.path.getsize('patches/patch_of_' + test_fun[0] + ".c")
        name2 = "repair_res_files/" + test_fun[0] + ".pkl"
        rep_res = bf.load_pickle(name2)
        sum_len = 0
        for ri in rep_res[0:-1]:
            sum_len = sum_len + len(ri[-2])
        tp_st = size_file / 1024.0
        if tp_st < 1.0:
            cout = cout + 1
        patch_sz_lst.append(size_file / 1024.0)
        repair_res.append(sum_len)
    print cout
    export2excel(patch_sz_lst, repair_res)
Exemple #14
0
def run_time_evaluation():
    name = "papergraph/time_before_repair.pkl"
    time_lst = []
    for i in fid_lc:
        test_fun = inter_funcs[i]
        print test_fun
        name2 = "repair_res_files/" + test_fun[0] + ".pkl"
        repair_res = bf.load_pickle(name2)
        # print repair_res
        # print repair_res[0]
        fun_pu, stat_fun = load_pure_fun(test_fun[0])
        inps_lst = get_points(repair_res[0:-1], fun_pu)
        print "generate points"
        st = time.time()
        for inp in inps_lst:
            fun_pu(*inp)
        et = time.time() - st
        time_lst.append(et)
        print et
    bf.pickle_fun(name, time_lst)
    return 0
Exemple #15
0
def load_fpnan_fun(fun_name):
    inter_funcs = bf.load_pickle('fun_index.pkl')
    ### [fun_name, [[var_typ,var_name]..]]
    test_fun = found_funbyName(fun_name, inter_funcs)
    lib_ld = ctypes.CDLL('../benchmark/driver_funcs/nan_dect/' + test_fun[0] +
                         '/libgslbc.so')
    lib_fun = lib_ld.gslfdr
    lib_ini = lib_ld.ini_idx
    lib_ini()
    lib_w = ctypes.c_double.in_dll(lib_ld, "w")
    lib_cidx = ctypes.c_int.in_dll(lib_ld, "cidx")
    lib_stflag = ctypes.c_int.in_dll(lib_ld, "stflag")
    lib_sumins = ctypes.c_int.in_dll(lib_ld, "sum_ins")
    lib_idx = ctypes.POINTER(ctypes.c_int).in_dll(lib_ld, "idx")
    lib_ld.gslfdr.restype = ctypes.c_double
    vartyp_lst = []
    for i in test_fun[1]:
        if i[0] == 'double':
            vartyp_lst.append(ctypes.c_double)
        if i[0] == 'int':
            vartyp_lst.append(ctypes.c_int)
    lib_ld.gslfdr.argtypes = vartyp_lst
    return lib_fun, [lib_w, lib_cidx, lib_idx, lib_stflag, lib_sumins]
Exemple #16
0
def load_pure_fun(fun_name):
    inter_funcs = bf.load_pickle('fun_index.pkl')
    ### [fun_name, [[var_typ,var_name]..]]
    test_fun = found_funbyName(fun_name, inter_funcs)
    # print os.path.dirname(__file__)
    lib_ld = ctypes.CDLL('../benchmark/driver_funcs/pure_exe/' + test_fun[0] +
                         '/libgslbc.so')
    lib_fun = lib_ld.gslfdr
    lib_stat = lib_ld.get_status

    class gsl_sf_result(ctypes.Structure):
        _fields_ = [('val', ctypes.c_double), ('err', ctypes.c_double)]

    # lib_idx = ctypes.POINTER(ctypes.c_int).in_dll(lib_ld, "idx")
    lib_ld.gslfdr.restype = gsl_sf_result
    lib_ld.get_status.restype = ctypes.c_int
    vartyp_lst = []
    for i in test_fun[1]:
        if i[0] == 'double':
            vartyp_lst.append(ctypes.c_double)
        if i[0] == 'int':
            vartyp_lst.append(ctypes.c_int)
    lib_ld.gslfdr.argtypes = vartyp_lst
    return lib_fun, lib_stat
Exemple #17
0
import basic_func as bf
from gen_drivfunc import load_pure_fun
import os
import numpy as np
import itertools
import random
import time
import matplotlib
import matplotlib.pyplot as plt
import xlrd
import xlwt
from xlutils.copy import copy

inter_funcs = bf.load_pickle('fun_index.pkl')
sum_lst = bf.load_pickle("detect_res_lst.pkl")
fid_lst = []

fid_lc = [
    2, 3, 5, 10, 26, 34, 35, 36, 37, 39, 40, 41, 42, 45, 46, 47, 48, 49, 50,
    51, 52, 53, 59, 63, 66, 67, 69, 70, 73, 74, 75, 80, 84, 85, 92, 100, 101,
    102, 108, 118, 128, 132, 147
]

# for i in [40]:
#     test_fun = inter_funcs[i]
#     print test_fun
#     var_num = bf.get_var_num(test_fun)
#     name = "localize_res_files/" + test_fun[0] + ".pkl"
#     fun_pu, stat_fun = load_pure_fun(test_fun[0])
#     res = fun_pu(-1e100)
#     print res.val
Exemple #18
0
    print "int axs = find_id_" + name + "(" + var_name + ");"
    idx = 1
    for rep_lst in repair_lst[:-1]:
        print "if(axs==" + repr(idx) + "){"
        print " if(find_bd_" + name + '_' + str(idx) + "(" + var_name + ")){"
        for rep_str in rep_lst[2]:
            print "    " + rep_str
        print " }"
        print "}"
        idx = idx + 1
    sys.stdout = orig_stdout
    f.close()



inter_funcs = bf.load_pickle('fun_index.pkl')
for i in fid_lc:
    test_fun = inter_funcs[i]
    print test_fun
    var_num = bf.get_var_num(test_fun)
    name = "localize_res_files/" + test_fun[0] + ".pkl"
    name2 = "repair_res_files/" + test_fun[0] + ".pkl"
    repair_res = bf.load_pickle(name2)
    print len(repair_res)
    print repair_res

    if var_num == 1:
        var_name = test_fun[1][0][1]
        convertToC_1v(repair_res, test_fun[0],var_name)
    else:
        var_name = test_fun[1][0][1] + "," + test_fun[1][1][1]
Exemple #19
0
def localize_exceptions():
    inter_funcs = bf.load_pickle('fun_index.pkl')
    eva_bound_lst = bf.load_pickle("eva_bound_lst.plk")
    sum_lst = bf.load_pickle("detect_res_lst.pkl")
    for fid in range(74, 75):
        # fid = 14
        test_fun = inter_funcs[fid]
        fun_pu, stat_fun = load_pure_fun(test_fun[0])
        i = sum_lst[fid]
        print test_fun
        fpe_lst = []
        for j in range(0, len(i[2]), 2):
            bt = i[2][j]
            res_lst = i[2][j + 1]
            if bt == 3:
                fpe_lst.append(res_lst[0][0] + res_lst[0][1] + res_lst[0][2])
        count = 0
        rf = lambda x: rf_f(fid, x)
        new_bounds = []
        # new_bounds.append(fid)
        # new_bounds.append(test_fun[0])
        var_num = bf.get_var_num(test_fun)
        print eva_bound_lst[fid]
        for i in eva_bound_lst[fid][2:]:
            print i
            ret_vals = i[0][1]
            num_excp = i[0][0]
            bt = get_bound_type(ret_vals, num_excp)
            bound = i[1]
            inp_lst = []
            loc_inps = []
            # print bound
            if (bt == 3) & (fid != 97):
                inp_lst = FPexcption_detector_whole(fun_pu, stat_fun, bound)
                inp_lst = inp_lst + fpe_lst[count]
                count = count + 1
                for ti in inp_lst:
                    res_p = fun_pu(*ti)
                    res_rf = float(rf(ti))
                    ty_f = classifer(res_p.val, res_rf, stat_fun())
                    if ty_f != 0:
                        loc_inps.append(ti)
                if loc_inps == []:
                    new_bounds.append([(0, [-1]), bound])
                else:
                    new_bounds.append(i)
                    if var_num == 1:
                        loc_bound_lst = localize_inbound(
                            bound, fun_pu, stat_fun, loc_inps)
                        print "loc_bound_lst"
                        print bound
                        print loc_bound_lst
                        for lcb in loc_bound_lst:
                            new_bounds.append([(0, [-2]), lcb])
                    else:
                        loc_bound_lst = localize_inbound2v(
                            bound, fun_pu, stat_fun, loc_inps)
                        print "loc_bound_lst"
                        # print loc_bound_lst
                        print len(loc_bound_lst)
                        for lcb in loc_bound_lst:
                            new_bounds.append([(0, [-2]), lcb])
            else:
                new_bounds.append(i)
        if var_num == 1:
            plot_1func_domain(new_bounds)
        if var_num == 2:
            plot_2vfunc_domain(new_bounds)
        print new_bounds