Ejemplo n.º 1
0
def patch_generate(ori_bound, name, ori_filename):
    name = name.strip()
    fun_name = name + "_e"
    pwd = os.getcwd()
    print fun_name
    x_l = get_varible_name(fun_name, pwd + "/fun_index.xls")
    x = x_l[0]
    print "Generate patch"
    ori_filename = ori_filename + "/"
    orig_stdout = sys.stdout
    filename = "../benchmarks/GSL_function/" + name + '_patch.txt'
    f = open(filename, 'w')
    sys.stdout = f
    print "#include \"patch_of_" + name + ".c\""
    print "if((" + x + "<=" + repr(ori_bound[1]) + ")&&(" + x + ">=" + repr(
        ori_bound[0]) + ")){"
    print " result->val = accuracy_improve_patch_of_" + name + "(" + x + ");"
    print " result->err = GSL_DBL_EPSILON * fabs(result->val);"
    print " return GSL_SUCCESS;"
    print "}"
    sys.stdout = orig_stdout
    f.close()
    f = open(filename, "r")
    contents = f.readlines()
    f.close()
    insert_fname, insert_line = search_line_num4f(fun_name,
                                                  pwd + "/fun_index.xls")
    patch_name = name + "_patch.c"
    cp_cmd = "cp -f " + "../benchmarks/GSL_function/specfunc4patch/" + insert_fname + " " + ori_filename + "patch/" + patch_name
    print pwd
    print cp_cmd
    os.system(cp_cmd)
    f = open(ori_filename + "patch/" + patch_name, "r")
    new_contents = f.readlines()
    f.close()
    for j in range(1, len(contents)):
        new_contents.insert(insert_line, " " + contents[j])
        insert_line = insert_line + 1
    new_contents.insert(25, contents[0])
    f = open(ori_filename + "patch/" + patch_name, "w")
    new_contents = "".join(new_contents)
    f.write(new_contents)
    f.close()
    gen_path_cmd = "diff -Naur " + "../benchmarks/GSL_function/specfunc4patch/" + insert_fname + " " + ori_filename + "patch/" + patch_name + "> " + ori_filename + "patch/" + "patch_of_" + name
    os.system(gen_path_cmd)
    cp_back = "cp -f " + ori_filename + "patch/" + patch_name + " " + "../benchmarks/GSL_function/specfunc4patch/" + insert_fname
    os.system(cp_back)
    rm_code = "rm " + ori_filename + "patch/" + patch_name
    os.system(rm_code)
    osname = os.path.dirname(os.getcwd())
    apply_patch = "patch " + osname + "/benchmarks/gsl_src/gsl-2.1-repair/specfunc/" + insert_fname + " " + "patch_of_" + name + "\n"
    f = open(ori_filename + "patch/patch_cmd.sh", "a")
    f.write(apply_patch)
    f.close()
Ejemplo n.º 2
0
def insert_patches(exname):
    data = xlrd.open_workbook(exname)
    table = data.sheets()[0]
    for i in range(1, table.nrows):
        print i
        if i != 1:
            name = table.row_values(i)[1]
            name = name.strip()
            fun_name = name + "_e"
            ori_bound = ast.literal_eval(table.row_values(i)[3])
            x_l = get_varible_name(fun_name, "fun_index.xls")
            x = x_l[0]
            y = x_l[1]
            z = x_l[2]
            insert_fname, insert_line = search_line_num4f(
                fun_name, "fun_index.xls")
            gsl_file = "../benchmarks/gsl_src/gsl-2.1-repair/specfunc/" + insert_fname
            orig_stdout = sys.stdout
            f = open("temp_file", 'w')
            sys.stdout = f
            print "#include \"patch_of_" + name + ".c\""
            print "if((" + x + "<=" + repr(
                ori_bound[0][1]) + ")&&(" + x + ">=" + repr(
                    ori_bound[0][0]) + ")){"
            print " if((" + y + "<=" + repr(
                ori_bound[1][1]) + ")&&(" + y + ">=" + repr(
                    ori_bound[1][0]) + ")){"
            print "     if((" + z + "<=" + repr(
                ori_bound[2][1]) + ")&&(" + z + ">=" + repr(
                    ori_bound[2][0]) + ")){"
            print "         result->val = accuracy_improve_patch_of_" + name + "(" + x + "," + y + "," + z + ");"
            print "         result->err = GSL_DBL_EPSILON * fabs(result->val);"
            print "         return GSL_SUCCESS;"
            print "     }"
            print " }"
            print "}"
            sys.stdout = orig_stdout
            f.close()
            f = open("temp_file", "r")
            contents = f.readlines()
            f.close()
            f = open(gsl_file, "r")
            new_contents = f.readlines()
            f.close()
            for j in range(1, len(contents)):
                new_contents.insert(insert_line, " " + contents[j])
                insert_line = insert_line + 1
            new_contents.insert(25, contents[0])
            f = open(gsl_file, "w")
            new_contents = "".join(new_contents)
            f.write(new_contents)
            f.close()
            sudo_cmd("rm temp_file")
Ejemplo n.º 3
0
def insert_patches(exname):
    data = xlrd.open_workbook(exname)
    table = data.sheets()[0]
    count = 0
    fail_lst = [9,16]
    for i in range(1,table.nrows):
        print i
        if i not in fail_lst:
            name = table.row_values(i)[1]
            name = name.strip()
            fun_name = name + "_e"
            ori_bound = ast.literal_eval(table.row_values(i)[3])
            x_l = get_varible_name(fun_name, "fun_index.xls")
            x = x_l[0]
            y = x_l[1]
            kb_fun_file = "/home/yixin/PycharmProjects/NPTaylor/experiments/Localizing_results12/" + name + "/kb_fun.txt"
            kb_fun_cof = pickle.load(open(kb_fun_file, "rb"))
            dr = kb_fun_cof[2]
            bounds_file = "/home/yixin/PycharmProjects/NPTaylor/experiments/Localizing_results12/" + name + "/bound_th.txt"
            bounds_th = pickle.load(open(bounds_file, "rb"))
            if dr == 0:
                temp_str = x
                temp_str2 = y
            else:
                temp_str = y
                temp_str2 = x
            if bounds_th != []:
                up_p0 = bounds_th[0]
                kb_up = bounds_th[1]
                down_p0 = bounds_th[2]
                kb_down = bounds_th[3]
                up_str = repr(up_p0[1 - dr]) + "+" + repr(float(kb_up[0])) + "+" + "(" + temp_str + "-" + "(" + repr(
                    up_p0[dr]) + ")" + ")" + "*" + "(" + repr(float(kb_up[1])) + ")"
                down_str = repr(down_p0[1 - dr]) + "+" + repr(
                    float(kb_down[0])) + "+" + "(" + temp_str + "-" + "(" + repr(
                    down_p0[dr]) + ")" + ")" + "*" + "(" + repr(float(kb_down[1])) + ")"
            insert_fname, insert_line = search_line_num4f(fun_name, "fun_index.xls")
            gsl_file = "../benchmarks/gsl_src/gsl-2.1-repair/specfunc/" + insert_fname
            orig_stdout = sys.stdout
            f = open("temp_file", 'w')
            sys.stdout = f
            print "#include \"patch_of_" + name + ".c\""
            print "if((" + x + "<=" + repr(ori_bound[0][1]) + ")&&(" + x + ">=" + repr(ori_bound[0][0]) + ")){"
            print " if((" + y + "<=" + repr(ori_bound[1][1]) + ")&&(" + y + ">=" + repr(ori_bound[1][0]) + ")){"
            if bounds_th != []:
                print " if((" + temp_str2 + "<=" + up_str + ")&&(" + temp_str2 + ">=" + down_str + ")){"
                print "     result->val = accuracy_improve_patch_of_" + name + "(" + x + "," + y + ");"
                print "     result->err = GSL_DBL_EPSILON * fabs(result->val);"
                print "     return GSL_SUCCESS;"
                print " }"
                print " }"
                print "}"
            else:
                print "     result->val = accuracy_improve_patch_of_" + name + "(" + x + "," + y + ");"
                print "     result->err = GSL_DBL_EPSILON * fabs(result->val);"
                print "     return GSL_SUCCESS;"
                print " }"
                print "}"
            sys.stdout = orig_stdout
            f.close()
            f = open("temp_file", "r")
            contents = f.readlines()
            f.close()
            f = open(gsl_file, "r")
            new_contents = f.readlines()
            f.close()
            for j in range(1, len(contents)):
                new_contents.insert(insert_line, " " + contents[j])
                insert_line = insert_line + 1
            new_contents.insert(25, contents[0])
            f = open(gsl_file, "w")
            new_contents = "".join(new_contents)
            f.write(new_contents)
            f.close()
            sudo_cmd("rm temp_file")