コード例 #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 get_sorted_space(partition_list):
    dimension_list = list(partition_list[0].keys())
    dim_count = len(dimension_list)
    merged_space = None
    if dim_count == 1:
        merged_space = sorted(
            partition_list, key=lambda x: x[dimension_list[0]]['lower-bound'])
    elif dim_count == 2:
        merged_space = sorted(partition_list,
                              key=lambda x:
                              (x[dimension_list[0]]['lower-bound'], x[
                                  dimension_list[1]]['lower-bound']))
    elif dim_count == 3:
        merged_space = sorted(
            partition_list,
            key=lambda x:
            (x[dimension_list[0]]['lower-bound'], x[dimension_list[1]][
                'lower-bound'], x[dimension_list[2]]['lower-bound']))
    elif dim_count == 4:
        merged_space = sorted(
            partition_list,
            key=lambda x: (x[dimension_list[0]]['lower-bound'], x[
                dimension_list[1]]['lower-bound'], x[dimension_list[2]][
                    'lower-bound'], x[dimension_list[3]]['lower-bound']))
    else:
        utilities.error_exit("unhandled sorting of multi-dimensional space")
    return merged_space
コード例 #3
0
ファイル: configuration.py プロジェクト: samithaj/CPR
def collect_test_list():
    emitter.normal("reading test configuration")
    if values.CONF_TEST_INPUT_LIST:
        for test_input in values.CONF_TEST_INPUT_LIST:
            values.LIST_TEST_INPUT.append(test_input)
    elif values.CONF_TEST_INPUT_FILE:
        with open(values.CONF_TEST_INPUT_FILE, "r") as in_file:
            content_lines = in_file.readlines()
            for content in content_lines:
                values.LIST_TEST_INPUT.append(content.strip().replace(
                    "\n", ""))
    else:
        error_exit("No test input is given (at least one is required)")

    if values.CONF_TEST_INPUT_DIR:
        test_file_dir = values.CONF_TEST_INPUT_DIR
        file_list = [
            f for f in os.listdir(test_file_dir)
            if os.path.isfile(os.path.join(test_file_dir, f))
        ]
        for test_file in file_list:
            test_file_index = test_file
            if "." in test_file:
                test_file_index = str(test_file).split(".")[0]
            test_abs_path = test_file_dir + "/" + test_file
            # if not values.CONF_PATH_POC:
            #     values.CONF_PATH_POC = test_abs_path
            values.LIST_TEST_FILES[test_file_index] = test_abs_path
    elif values.CONF_PATH_POC:
        test_file = values.CONF_PATH_POC
        test_file_index = test_file
        if "." in test_file:
            test_file_index = str(test_file).split(".")[0]
        values.LIST_TEST_FILES[test_file_index] = values.CONF_PATH_POC

    if values.CONF_TEST_OUTPUT_LIST:
        for expected_output in values.CONF_TEST_OUTPUT_LIST:
            values.LIST_TEST_OUTPUT.append(expected_output)
    elif values.CONF_TEST_OUTPUT_DIR:
        expected_output_dir = values.CONF_TEST_OUTPUT_DIR
        file_list = [
            f for f in os.listdir(expected_output_dir)
            if os.path.isfile(os.path.join(expected_output_dir, f))
        ]
        for expected_output_file in file_list:
            if ".smt2" in expected_output_file:
                expected_file_abs_path = expected_output_dir + "/" + expected_output_file
                expected_file_rel_path = str(expected_file_abs_path).replace(
                    values.CONF_PATH_PROJECT + "/", "")
                values.LIST_TEST_OUTPUT.append(expected_file_rel_path)
    else:
        error_exit("No expected output is given (at least one is required)")

    test_input_list = values.LIST_TEST_INPUT
    concretized_test_input_list = []
    for arg_list_str in test_input_list:
        arg_list = extract_input_arg_list(arg_list_str)
        concretized_arg_list = []
        for arg in arg_list:
            if "$POC_" in arg:
                file_index = "_".join(str(arg).split("_")[1:])
                file_path = values.LIST_TEST_FILES[file_index]
                concretized_arg_list.append(file_path)
            elif "$POC" in arg:
                file_index = list(values.LIST_TEST_FILES.keys())[0]
                file_path = values.LIST_TEST_FILES[file_index]
                concretized_arg_list.append(file_path)
            else:
                concretized_arg_list.append(arg)
        concretized_arg_str = ",".join(concretized_arg_list)
        concretized_test_input_list.append(concretized_arg_str)
    values.LIST_TEST_INPUT = concretized_test_input_list
コード例 #4
0
ファイル: configuration.py プロジェクト: samithaj/CPR
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
コード例 #5
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))