예제 #1
0
파일: builder.py 프로젝트: samithaj/CPR
def build_project(project_path, build_command=None):
    emitter.normal("\tbuilding program")
    dir_command = "cd " + project_path + ";"
    if build_command is None:
        build_command = "CC=" + CC + " CXX=" + CXX + " "
        if values.CONF_BUILD_FLAGS == "disable":
            build_command += "bear make -j`nproc`  "
        else:
            build_command += "bear make CFLAGS=\"" + C_FLAGS + "\" "
            build_command += "CXXFLAGS=\"" + CXX_FLAGS + " LDFLAGS=" + LD_FLAGS + "\" -j`nproc` > "
    else:
        if build_command == "skip":
            emitter.warning("\t[warning] skipping build")
            return
        if not os.path.isfile(project_path + "/compile_commands.json"):
            build_command = build_command.replace("make ", "bear make ")
        if CC == "wllvm":
            build_command = remove_fsanitize(build_command)
        build_command = apply_flags(build_command)
    if not build_command:
        error_exit("[Not Found] Build Command")

    build_command = dir_command + build_command
    build_command = build_command + " > " + definitions.FILE_MAKE_LOG
    ret_code = execute_command(build_command)
    if int(ret_code) != 0:
        emitter.error(build_command)
        error_exit("BUILD FAILED!!\nExit Code: " + str(ret_code))
예제 #2
0
def recover_patch_list(result_list, patch_list, path_condition, assertion):
    recover_list = []
    emitter.error(
        "\t[error] something went wrong with patch validation, attempting to recover"
    )
    emitter.debug("result list size: " + str(len(result_list)))
    emitter.debug("patch list size: " + str(len(patch_list)))
    emitter.warning(
        "\t[warning] attempting to re-run parallel refinement: missing " +
        str(len(patch_list) - len(result_list)))

    diff_list_a = get_diff_list(result_list, patch_list)
    result_list_a = parallel.refine_patch_space(diff_list_a, path_condition,
                                                assertion)
    recover_list = update_index(result_list_a, diff_list_a, patch_list)
    if len(diff_list_a) != len(result_list_a):
        emitter.error(
            "\t[error] something went wrong with patch validation, attempting to recover"
        )
        emitter.debug("result list size: " + str(len(result_list)))
        emitter.debug("patch list size: " + str(len(patch_list)))
        emitter.warning(
            "\t[warning] attempting to re-run sequential refinement: missing "
            + str(len(diff_list_a) - len(result_list_a)))
        diff_list_b = get_diff_list(result_list_a, diff_list_a)
        result_list_b = parallel.refine_patch_space(diff_list_b,
                                                    path_condition, assertion,
                                                    True)
        recover_list = recover_list + update_index(result_list_b, diff_list_b,
                                                   patch_list)
    return recover_list
예제 #3
0
파일: main.py 프로젝트: rshariffdeen/CPR
def main():
    import sys
    is_error = False
    signal.signal(signal.SIGALRM, timeout_handler)
    try:
        run(sys.argv[1:])
    except KeyboardInterrupt as e:
        is_error = True
        parallel.pool.terminate()
        parallel.pool.join()
        logger.error(traceback.format_exc())
    except Exception as e:
        is_error = True
        emitter.error("Runtime Error")
        emitter.error(str(e))
        logger.error(traceback.format_exc())
    finally:
        # Final running time and exit message
        # os.system("ps -aux | grep 'python' | awk '{print $2}' | xargs kill -9")
        total_duration = format((time.time() - start_time) / 60, '.3f')
        time_info[definitions.KEY_DURATION_TOTAL] = str(total_duration)
        emitter.end(time_info, is_error)
        logger.end(time_info, is_error)
        logger.store()
예제 #4
0
def run_cegis(program_path, project_path, patch_list):
    test_output_list = values.LIST_TEST_OUTPUT
    test_template = reader.collect_specification(test_output_list[0])
    binary_dir_path = "/".join(program_path.split("/")[:-1])
    time_check = time.time()
    assertion, largest_path_condition = concolic.run_concolic_exploration(
        program_path, patch_list)
    duration = (time.time() - time_check) / 60
    values.TIME_TO_EXPLORE = duration
    emitter.normal("\tcombining explored program paths")
    if not assertion:
        patch = patch_list[0]
        emitter.emit_patch(patch, message="\tfinal patch: ")
        return
    program_specification = generator.generate_program_specification(
        binary_dir_path)
    complete_specification = And(Not(assertion), program_specification)
    emitter.normal("\tcomputed the program specification formula")
    emitter.sub_title("Evaluating Patch Pool")
    iteration = 0
    output_dir = definitions.DIRECTORY_OUTPUT
    counter_example_list = []
    time_check = time.time()
    values.CONF_TIME_CHECK = None
    satisfied = utilities.check_budget(values.DEFAULT_TIMEOUT_CEGIS_REFINE)
    patch_generator = generator.generate_patch(project_path,
                                               counter_example_list)
    count_throw = 0
    while not satisfied:
        iteration = iteration + 1
        values.ITERATION_NO = iteration
        emitter.sub_sub_title("Iteration: " + str(iteration))
        patch = next(patch_generator, None)
        if not patch:
            emitter.error("[error] cannot generate a patch")
        patch_formula = app.generator.generate_formula_from_patch(patch)
        emitter.emit_patch(patch, message="\tgenerated patch: ")
        patch_formula_extended = generator.generate_extended_patch_formula(
            patch_formula, largest_path_condition)
        violation_check = And(complete_specification, patch_formula_extended)
        if is_sat(violation_check):
            model = generator.generate_model(violation_check)
            # print(model)
            arg_list = values.ARGUMENT_LIST
            poc_path = values.CONF_PATH_POC
            values.FILE_POC_GEN = definitions.DIRECTORY_OUTPUT + "/violation-" + str(
                values.ITERATION_NO)
            gen_path = values.FILE_POC_GEN
            input_arg_list, input_var_list = generator.generate_new_input(
                violation_check, arg_list, poc_path, gen_path)
            klee_out_dir = output_dir + "/klee-output-" + str(iteration)
            klee_test_file = output_dir + "/klee-test-" + str(iteration)
            exit_code = concolic.run_concrete_execution(
                program_path + ".bc", input_arg_list, True, klee_out_dir)
            # assert exit_code == 0
            emitter.normal("\t\tgenerating new assertion")
            test_assertion, count_obs = generator.generate_assertion(
                test_template, klee_out_dir)
            write_smtlib(test_assertion, klee_test_file)
            counter_example_list.append((klee_test_file, klee_out_dir))
            emitter.highlight("\t\tnew counter-example added")
            patch = None
            emitter.highlight("\t\tremoving current patch")
            count_throw = count_throw + 1
        else:
            klee_test_file = output_dir + "/klee-test-FINAL"
            # print(to_smtlib(violation_check, False))
            write_smtlib(violation_check, klee_test_file)
            break
        satisfied = utilities.check_budget(values.DEFAULT_TIMEOUT_CEGIS_REFINE)
        if satisfied:
            emitter.warning("\t[warning] ending due to timeout of " +
                            str(values.DEFAULT_TIMEOUT_CEGIS_REFINE) +
                            " minutes")
    duration = (time.time() - time_check) / 60
    values.TIME_TO_REDUCE = duration
    # patch_list = [patch]
    # definitions.FILE_PATCH_SET = definitions.DIRECTORY_OUTPUT + "/patch-set-cegis"
    # writer.write_patch_set(patch_list, definitions.FILE_PATCH_SET)
    # patch = next(patch_generator, None)
    # while patch is not None:
    #     patch_formula = app.generator.generate_formula_from_patch(patch)
    #     patch_formula_extended = generator.generate_extended_patch_formula(patch_formula, largest_path_condition)
    #     violation_check = And(complete_specification, patch_formula_extended)
    #     if is_unsat(violation_check):
    #         count_final = count_final + 1
    #     patch = next(patch_generator, None)
    emitter.emit_patch(patch, message="\tfinal patch: ")
    values.COUNT_PATCH_END = values.COUNT_PATCH_START - count_throw
예제 #5
0
def read_conf(arg_list):
    emitter.normal("reading configuration values from arguments")
    if len(arg_list) > 0:
        for arg in arg_list:
            if definitions.ARG_DEBUG in arg:
                values.DEBUG = True
            elif definitions.ARG_CONF_FILE in arg:
                values.FILE_CONFIGURATION = str(arg).replace(
                    definitions.ARG_CONF_FILE, '')
            elif definitions.ARG_DISABLE_DISTANCE_CAL in arg:
                values.IS_DISABLE_DISTANCE_CAL = True
            elif definitions.ARG_COLLECT_STAT in arg:
                values.CONF_COLLECT_STAT = True
            elif definitions.ARG_DIST_METRIC in arg:
                option = int(arg.replace(definitions.ARG_DIST_METRIC, ''))
                values.CONF_DISTANCE_METRIC = values.OPTIONS_DIST_METRIC[
                    option]
            elif definitions.ARG_LOW_BOUND in arg:
                bound_value = int(arg.replace(definitions.ARG_LOW_BOUND, ''))
                values.CONF_LOW_BOUND = bound_value
            elif definitions.ARG_MAX_BOUND in arg:
                bound_value = int(arg.replace(definitions.ARG_MAX_BOUND, ''))
                values.CONF_MAX_BOUND = bound_value
            elif definitions.ARG_RANK_LIMIT in arg:
                values.CONF_RANK_LIMIT = int(
                    arg.replace(definitions.ARG_RANK_LIMIT, ""))
            elif definitions.ARG_SELECTION_METHOD in arg:
                option = int(arg.replace(definitions.ARG_SELECTION_METHOD, ''))
                if option not in values.OPTIONS_SELECT_METHOD:
                    emitter.error(
                        "Invalid option for " +
                        definitions.ARG_SELECTION_METHOD.replace("=", "") +
                        " : " + arg)
                    emitter.emit_help()
                    exit()
                values.CONF_SELECTION_STRATEGY = values.OPTIONS_SELECT_METHOD[
                    option]
            elif definitions.ARG_OPERATION_MODE in arg:
                option = int(arg.replace(definitions.ARG_OPERATION_MODE, ''))
                if option not in values.OPTIONS_OPERATION_MODE:
                    emitter.error(
                        "Invalid option for " +
                        definitions.ARG_OPERATION_MODE.replace("=", "") +
                        " : " + arg)
                    emitter.emit_help()
                    exit()
                values.CONF_OPERATION_MODE = values.OPTIONS_OPERATION_MODE[
                    option]
            elif definitions.ARG_PATCH_TYPE in arg:
                option = int(arg.replace(definitions.ARG_PATCH_TYPE, ''))
                if option not in values.OPTIONS_PATCH_TYPE:
                    emitter.error("Invalid option for " +
                                  definitions.ARG_PATCH_TYPE.replace("=", "") +
                                  " : " + arg)
                    emitter.emit_help()
                    exit()
                values.CONF_PATCH_TYPE = values.OPTIONS_PATCH_TYPE[option]
            elif definitions.ARG_REFINE_METHOD in arg:
                option = int(arg.replace(definitions.ARG_REFINE_METHOD, ''))
                if option not in values.OPTIONS_REFINE_METHOD:
                    emitter.error(
                        "Invalid option for " +
                        definitions.ARG_REFINE_METHOD.replace("=", "") +
                        " : " + arg)
                    emitter.emit_help()
                    exit()
                values.CONF_REFINE_METHOD = values.OPTIONS_REFINE_METHOD[
                    option]
            elif definitions.ARG_REDUCE_METHOD in arg:
                option = int(arg.replace(definitions.ARG_REDUCE_METHOD, ''))
                if option not in values.OPTIONS_REDUCE_METHOD:
                    emitter.error(
                        "Invalid option for " +
                        definitions.ARG_REDUCE_METHOD.replace("=", "") +
                        " : " + arg)
                    emitter.emit_help()
                    exit()
                values.CONF_REDUCE_METHOD = values.OPTIONS_REDUCE_METHOD[
                    option]
            elif definitions.ARG_SKIP_BUILD in arg:
                values.CONF_SKIP_BUILD = True
            elif definitions.ARG_ITERATION_COUNT in arg:
                values.CONF_ITERATION_LIMIT = int(
                    arg.replace(definitions.ARG_ITERATION_COUNT, ""))
            elif definitions.ARG_COMP_ALL in arg:
                values.CONF_ALL_COMPS = True
            elif definitions.ARG_SKIP_GENERATION in arg:
                values.CONF_SKIP_GEN = True
            elif definitions.ARG_SKIP_TEST in arg:
                values.CONF_SKIP_TEST = True
            elif definitions.ARG_TIME_DURATION in arg:
                values.CONF_TIME_DURATION = int(
                    arg.replace(definitions.ARG_TIME_DURATION, ""))
            elif definitions.ARG_CEGIS_TIME_SPLIT in arg:
                if ":" not in arg:
                    emitter.error(
                        "Invalid option for " +
                        definitions.ARG_CEGIS_TIME_SPLIT.replace("=", "") +
                        " : " + arg)
                    emitter.emit_help()
                    exit()
                else:
                    time_split = arg.replace(definitions.ARG_CEGIS_TIME_SPLIT,
                                             "")
                    values.CONF_TIME_SPLIT = time_split

            else:
                emitter.error("Invalid argument: " + arg)
                emitter.emit_help()
                exit()
    else:
        emitter.emit_help()
        exit()
예제 #6
0
def read_conf_file():
    emitter.normal("reading configuration values form configuration file")
    emitter.note("\t[file] " + values.FILE_CONFIGURATION)
    logger.information(values.FILE_CONFIGURATION)
    if not os.path.exists(values.FILE_CONFIGURATION):
        emitter.error("[NOT FOUND] Configuration file " +
                      values.FILE_CONFIGURATION)
        exit()
    if os.path.getsize(values.FILE_CONFIGURATION) == 0:
        emitter.error("[EMPTY] Configuration file " +
                      values.FILE_CONFIGURATION)
        exit()
    with open(values.FILE_CONFIGURATION, 'r') as conf_file:
        configuration_list = [i.strip() for i in conf_file.readlines()]

    for configuration in configuration_list:
        if definitions.CONF_PATH_PROJECT in configuration:
            values.CONF_PATH_PROJECT = configuration.replace(
                definitions.CONF_PATH_PROJECT, '')
        elif definitions.CONF_BINARY_PATH in configuration:
            values.CONF_PATH_PROGRAM = configuration.replace(
                definitions.CONF_BINARY_PATH, '')
        elif definitions.CONF_COMMAND_BUILD in configuration:
            values.CONF_COMMAND_BUILD = configuration.replace(
                definitions.CONF_COMMAND_BUILD, '')
        elif definitions.CONF_COMMAND_CONFIG in configuration:
            values.CONF_COMMAND_CONFIG = configuration.replace(
                definitions.CONF_COMMAND_CONFIG, '')
        elif definitions.CONF_RANK_LIMIT in configuration:
            values.CONF_RANK_LIMIT = int(
                configuration.replace(definitions.CONF_RANK_LIMIT, ''))
        elif definitions.CONF_SEED_FILE in configuration:
            seed_file_path = configuration.replace(definitions.CONF_SEED_FILE,
                                                   '')
            if not os.path.isfile(seed_file_path):
                seed_file_path = values.CONF_PATH_PROJECT + "/" + seed_file_path
                if not os.path.isfile(seed_file_path):
                    error_exit("Seed file " + seed_file_path + " not found")
            values.CONF_SEED_FILE = seed_file_path
        elif definitions.CONF_TEST_INPUT_FILE in configuration:
            test_file_path = configuration.replace(
                definitions.CONF_TEST_INPUT_FILE, '')
            if not os.path.isfile(test_file_path):
                test_file_path = values.CONF_PATH_PROJECT + "/" + test_file_path
                if not os.path.isfile(test_file_path):
                    error_exit("Seed file " + test_file_path + " not found")
            values.CONF_TEST_INPUT_FILE = test_file_path
        elif definitions.CONF_SEED_DIR in configuration:
            seed_dir_path = configuration.replace(definitions.CONF_SEED_DIR,
                                                  '')
            if not os.path.isdir(seed_dir_path):
                seed_dir_path = values.CONF_PATH_PROJECT + "/" + seed_dir_path
                if not os.path.isdir(seed_dir_path):
                    error_exit("Seed dir " + seed_dir_path + " not found")
            values.CONF_SEED_DIR = seed_dir_path
        elif definitions.CONF_TEST_OUTPUT_DIR in configuration:
            output_dir_path = configuration.replace(
                definitions.CONF_TEST_OUTPUT_DIR, '')
            if not os.path.isdir(output_dir_path):
                output_dir_path = values.CONF_PATH_PROJECT + "/" + output_dir_path
                if not os.path.isdir(output_dir_path):
                    error_exit("Seed dir " + output_dir_path + " not found")
            values.CONF_TEST_OUTPUT_DIR = output_dir_path
        elif definitions.CONF_TEST_INPUT_DIR in configuration:
            input_dir_path = configuration.replace(
                definitions.CONF_TEST_INPUT_DIR, '')
            if not os.path.isdir(input_dir_path):
                input_dir_path = values.CONF_PATH_PROJECT + "/" + input_dir_path
                if not os.path.isdir(input_dir_path):
                    error_exit("Seed dir " + input_dir_path + " not found")
            values.CONF_TEST_INPUT_DIR = input_dir_path
        elif definitions.CONF_TEST_OUTPUT_LIST in configuration:
            values.CONF_TEST_OUTPUT_LIST = configuration.replace(
                definitions.CONF_TEST_OUTPUT_LIST, '').split(",")
        elif definitions.CONF_TEST_INPUT_LIST in configuration:
            input_list = configuration.replace(
                definitions.CONF_TEST_INPUT_LIST, '').split("],[")
            processed_list = []
            for input in input_list:
                processed_list.append(input.replace("[", "").replace("]", ""))
            values.CONF_TEST_INPUT_LIST = processed_list
        elif definitions.CONF_SEED_LIST in configuration:
            seed_list = configuration.replace(definitions.CONF_SEED_LIST,
                                              '').split("],[")
            processed_list = []
            for seed_input in seed_list:
                processed_list.append(
                    seed_input.replace("[", "").replace("]", ""))
            values.CONF_SEED_LIST = processed_list
        elif definitions.CONF_PATH_SPECIFICATION in configuration:
            values.CONF_PATH_SPECIFICATION = configuration.replace(
                definitions.CONF_PATH_SPECIFICATION, '')
            assertion_file_path = values.CONF_PATH_PROJECT + "/" + values.CONF_PATH_SPECIFICATION
            values.SPECIFICATION_TXT = reader.collect_specification(
                assertion_file_path)
        elif definitions.CONF_CUSTOM_COMP_LIST in configuration:
            values.CONF_CUSTOM_COMP_LIST = configuration.replace(
                definitions.CONF_CUSTOM_COMP_LIST, '').split(",")
        elif definitions.CONF_GENERAL_COMP_LIST in configuration:
            values.CONF_GENERAL_COMP_LIST = configuration.replace(
                definitions.CONF_GENERAL_COMP_LIST, '').split(",")
        elif definitions.CONF_DEPTH_VALUE in configuration:
            values.CONF_DEPTH_VALUE = configuration.replace(
                definitions.CONF_DEPTH_VALUE, '')
        elif definitions.CONF_DIR_SRC in configuration:
            values.CONF_DIR_SRC = configuration.replace(
                definitions.CONF_DIR_SRC, '').replace("//", "/")
            if values.CONF_DIR_SRC:
                if values.CONF_DIR_SRC[-1] == "/":
                    values.CONF_DIR_SRC = values.CONF_DIR_SRC[:-1]
        elif definitions.CONF_LOC_BUG in configuration:
            values.CONF_LOC_BUG = configuration.replace(
                definitions.CONF_LOC_BUG, '')
        elif definitions.CONF_LOC_PATCH in configuration:
            values.CONF_LOC_PATCH = configuration.replace(
                definitions.CONF_LOC_PATCH, '')
        elif definitions.CONF_PATH_POC in configuration:
            values.CONF_PATH_POC = configuration.replace(
                definitions.CONF_PATH_POC, '')
            if not os.path.isfile(values.CONF_PATH_POC):
                poc_path = values.CONF_PATH_PROJECT + "/" + values.CONF_PATH_POC
                if os.path.isfile(poc_path):
                    values.CONF_PATH_POC = poc_path
                else:
                    error_exit("Test file " + values.CONF_PATH_POC +
                               " not found")
        elif definitions.CONF_LOW_BOUND in configuration:
            values.CONF_LOW_BOUND = int(
                configuration.replace(definitions.CONF_LOW_BOUND, ''))
        elif definitions.CONF_MAX_BOUND in configuration:
            values.CONF_MAX_BOUND = int(
                configuration.replace(definitions.CONF_MAX_BOUND, ''))
        elif definitions.CONF_MAX_FORK in configuration:
            values.CONF_MAX_FORK = int(
                configuration.replace(definitions.CONF_MAX_FORK, ''))
        elif definitions.CONF_GEN_SEARCH_LIMIT in configuration:
            values.CONF_GEN_SEARCH_LIMIT = int(
                configuration.replace(definitions.CONF_GEN_SEARCH_LIMIT, ''))
        elif definitions.CONF_TAG_ID in configuration:
            values.CONF_TAG_ID = configuration.replace(definitions.CONF_TAG_ID,
                                                       '')
        elif definitions.CONF_STATIC in configuration:
            conf_text = configuration.replace(definitions.CONF_STATIC, '')
            if "true" in str(conf_text).lower():
                values.CONF_STATIC = True
        elif definitions.CONF_IS_CRASH in configuration:
            conf_text = configuration.replace(definitions.CONF_IS_CRASH, '')
            if "true" in str(conf_text).lower():
                values.CONF_IS_CRASH = True
        elif definitions.CONF_GEN_SPECIAL_PATH in configuration:
            conf_text = configuration.replace(
                definitions.CONF_GEN_SPECIAL_PATH, '')
            if "false" in str(conf_text).lower():
                values.CONF_GEN_PATH_SPECIAL = False
        elif definitions.CONF_IS_CPP in configuration:
            conf_text = configuration.replace(definitions.CONF_IS_CPP, '')
            if "true" in str(conf_text).lower():
                values.CONF_IS_CPP = True
        elif definitions.CONF_FLAG_ASAN in configuration:
            values.CONF_FLAG_ASAN = configuration.replace(
                definitions.CONF_FLAG_ASAN, '')
        elif definitions.CONF_FLAGS_C in configuration:
            values.CONF_FLAGS_C = configuration.replace(
                definitions.CONF_FLAGS_C, '')
        elif definitions.CONF_FLAGS_CXX in configuration:
            values.CONF_FLAGS_CXX = configuration.replace(
                definitions.CONF_FLAGS_CXX, '')
        elif definitions.CONF_SELECTION_STRATEGY in configuration:
            values.CONF_SELECTION_STRATEGY = configuration.replace(
                definitions.CONF_SELECTION_STRATEGY, '')
            if values.CONF_SELECTION_STRATEGY not in values.OPTIONS_SELECT_METHOD:
                error_exit("Invalid configuration for " +
                           definitions.CONF_SELECTION_STRATEGY)
        elif definitions.CONF_DISTANCE_METRIC in configuration:
            values.CONF_DISTANCE_METRIC = configuration.replace(
                definitions.CONF_DISTANCE_METRIC, '')
            if values.CONF_DISTANCE_METRIC not in values.OPTIONS_DIST_METRIC.values(
            ):
                error_exit("Invalid configuration for " +
                           definitions.CONF_DISTANCE_METRIC)
        elif definitions.CONF_PATCH_TYPE in configuration:
            values.CONF_PATCH_TYPE = configuration.replace(
                definitions.CONF_PATCH_TYPE, '')
            if values.CONF_PATCH_TYPE not in values.OPTIONS_PATCH_TYPE.values(
            ):
                error_exit("Invalid configuration for " +
                           definitions.CONF_PATCH_TYPE)
        elif definitions.CONF_OPERATION_MODE in configuration:
            values.CONF_OPERATION_MODE = configuration.replace(
                definitions.CONF_OPERATION_MODE, '')
            if values.CONF_OPERATION_MODE not in values.OPTIONS_OPERATION_MODE:
                error_exit("Invalid configuration for " +
                           definitions.CONF_OPERATION_MODE)
        elif definitions.CONF_BUILD_FLAGS in configuration:
            values.CONF_BUILD_FLAGS = configuration.replace(
                definitions.CONF_BUILD_FLAGS, '')
        elif definitions.CONF_KLEE_FLAGS in configuration:
            values.CONF_KLEE_FLAGS = configuration.replace(
                definitions.CONF_KLEE_FLAGS, '')
        elif definitions.CONF_ITERATION_LIMIT in configuration:
            values.CONF_ITERATION_LIMIT = int(
                configuration.replace(definitions.CONF_ITERATION_LIMIT, ''))
        elif definitions.CONF_STACK_SIZE in configuration:
            values.CONF_STACK_SIZE = int(
                configuration.replace(definitions.CONF_STACK_SIZE, ''))
        elif definitions.CONF_MASK_ARG in configuration:
            values.CONF_MASK_ARG = configuration.replace(
                definitions.CONF_MASK_ARG, '').split(",")
        elif definitions.CONF_TIMEOUT_SAT in configuration:
            values.CONF_TIMEOUT_SAT = int(
                configuration.replace(definitions.CONF_TIMEOUT_SAT, ''))
        elif definitions.CONF_TIMEOUT_KLEE in configuration:
            values.CONF_TIMEOUT_KLEE = int(
                configuration.replace(definitions.CONF_TIMEOUT_KLEE, ''))

    if not values.CONF_TAG_ID:
        emitter.error("[NOT FOUND] Tag ID ")
        exit()
    if values.CONF_DIR_SRC:
        if "/" != values.CONF_DIR_SRC[0]:
            values.CONF_DIR_SRC = values.CONF_PATH_PROJECT + "/" + values.CONF_DIR_SRC
    else:
        values.CONF_DIR_SRC = values.CONF_PATH_PROJECT
    if "/" != values.CONF_PATH_PROGRAM[0]:
        values.CONF_PATH_PROGRAM = values.CONF_DIR_SRC + "/" + values.CONF_PATH_PROGRAM
예제 #7
0
파일: main.py 프로젝트: rshariffdeen/CPR
def timeout_handler(signum, frame):
    emitter.error("TIMEOUT Exception")
    raise Exception("end of time")
예제 #8
0
파일: builder.py 프로젝트: samithaj/CPR
def config_project(project_path, is_llvm, custom_config_command=None):
    emitter.normal("\tconfiguring program")
    dir_command = "cd " + project_path + ";"

    config_command = None
    if custom_config_command is not None:
        if custom_config_command == "skip":
            emitter.warning("\t[warning] skipping configuration")
            return
        else:
            if os.path.exists(project_path + "/" + "aclocal.m4"):
                pre_config_command = "rm aclocal.m4;aclocal"
                execute_command(pre_config_command)

            if CC == "wllvm":
                custom_config_command = remove_fsanitize(custom_config_command)
                if "cmake" in custom_config_command:
                    custom_config_command = custom_config_command.replace(
                        "clang", "wllvm")
                    custom_config_command = custom_config_command.replace(
                        "clang++", "wllvm++")
                # print(custom_config_command)
            # config_command = "CC=" + CC + " "
            # config_command += "CXX=" + CXX + " "
            config_command = custom_config_command
            if "--cc=" in config_command:
                config_command = config_command.replace(
                    "--cc=clang-7", "--cc=" + CC)
            # print(config_command)

    elif os.path.exists(project_path + "/autogen.sh"):
        config_command = "./autogen.sh;"
        config_command += "CC=" + CC + " "
        config_command += "CXX=" + CXX + " "
        config_command += "./configure "
        config_command += "CFLAGS=\"" + C_FLAGS + "\" "
        config_command += "CXXFLAGS=\"" + CXX_FLAGS + "\""

    elif os.path.exists(project_path + "/configure.ac"):
        config_command = "autoreconf -i;"
        config_command += "CC=" + CC + " "
        config_command += "CXX=" + CXX + " "
        config_command += "./configure "
        config_command += "CFLAGS=\"" + C_FLAGS + "\" "
        config_command += "CXXFLAGS=\"" + CXX_FLAGS + "\""

    elif os.path.exists(project_path + "/configure.in"):
        config_command = "autoreconf -i;"
        config_command += "CC=" + CC + " "
        config_command += "CXX=" + CXX + " "
        config_command += "./configure "
        config_command += "CFLAGS=\"" + C_FLAGS + "\" "
        config_command += "CXXFLAGS=\"" + CXX_FLAGS + "\""

    elif os.path.exists(project_path + "/configure"):
        config_command = "CC=" + CC + " "
        config_command += "CXX=" + CXX + " "
        config_command += "./configure "
        config_command += "CFLAGS=\"" + C_FLAGS + "\" "
        config_command += "CXXFLAGS=\"" + CXX_FLAGS + "\""

    elif os.path.exists(project_path + "/CMakeLists.txt"):
        config_command = "cmake -DCMAKE_C_COMPILER=" + CC + " "
        config_command += "-DCMAKE_CPP_COMPILER=" + CXX + " "
        config_command += "-DCMAKE_C_FLAGS=\"" + C_FLAGS + "\" "
        config_command += "-DCMAKE_CXX_FLAGS=\"" + CXX_FLAGS + "\" . "

    if is_llvm:
        config_command = "LLVM_COMPILER=clang;" + config_command

    if not config_command:
        error_exit("[Not Found] Configuration Command")

    config_command = dir_command + config_command
    ret_code = execute_command(config_command)
    if int(ret_code) != 0:
        emitter.error(config_command)
        error_exit("CONFIGURATION FAILED!!\nExit Code: " + str(ret_code))
예제 #9
0
def error_exit(*arg_list):
    emitter.error("Repair Failed")
    for arg in arg_list:
        emitter.error(str(arg))
    raise Exception("Error. Exiting...")