Exemplo n.º 1
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
Exemplo n.º 2
0
def title(title):
    write("\n" + "=" * 100 + "\n\n\t" + title + "\n" + "=" * 100 + "\n", CYAN)
    logger.information(title)
Exemplo n.º 3
0
def sub_sub_title(sub_title):
    write("\n\t\t" + sub_title + "\n\t\t" + "-" * 90 + "\n", CYAN)
    logger.information(sub_title)
Exemplo n.º 4
0
def information(message, jump_line=True):
    if values.DEBUG:
        write(message, GREY, jump_line)
    logger.information(message)