Ejemplo n.º 1
0
def init_output_var(test_case):    
    global_var_data_type = "Struct_Uint8Data_Typedef"
    return_obj_data_type = "Struct_Uint8Data_Typedef"        
        
    # Initialize return object   
    for obj in test_case.return_objs:
        if "True" == obj.is_pointer:
            if 8 == Config.system_register_size:
                return_obj_data_type = "Struct_Uint8PtrData_Typedef"
            if 16 == Config.system_register_size:
                return_obj_data_type = "Struct_Uint16PtrData_Typedef"
            if 32 == Config.system_register_size:
                return_obj_data_type = "Struct_Uint64PtrData_Typedef"

        GenUtils.gen_comment_line(gen_source_file, "Declare object to store returning value")
        GenUtils.gen_var_declaration(gen_source_file, return_obj_data_type, obj.gen_name)
        # Declare a temporary pointer to stored the returning address.
        if "True" == obj.is_pointer:
            GenUtils.source_file("uint8_t *result_ptr;")


    # Initialize global variables   
    for var in test_case.global_vars:
        GenUtils.gen_comment_line(gen_source_file, "Declare object to check value of " + var.actual_mem)
        GenUtils.gen_var_declaration(gen_source_file, global_var_data_type, var.gen_name)
    GenUtils.gen_break_line(gen_source_file)
Ejemplo n.º 2
0
def call_test_method(test_case):
    # Create an array with null items ("None" is similar to null")
    param_list = [None] * len(test_case.params)
    
    # Get list of parameters from "testcase" class
    i = 0
    for param in test_case.params:
        param_list[i] = param.param_name
        i += 1

    result_var = ""
    type_cast = ""
    if len(test_case.return_objs) > 0:
        result_var = "result_ptr"
        if "True" == test_case.return_objs[0].is_pointer:
            type_cast = "(uint8_t*)"
    


    GenUtils.gen_comment_line(gen_source_file, "Call the tested function")
    params_count = len(param_list)
    if params_count > 0:
        GenUtils.gen_function_call_with_arg(gen_source_file, test_case.function_name, result_var, type_cast, param_list)
    else:
        GenUtils.gen_function_call_no_arg(gen_source_file, test_case.function_name, result_var, type_cast)
    GenUtils.gen_break_line(gen_source_file)    
Ejemplo n.º 3
0
def compare_one_register(global_var):
    global_var_name = global_var.gen_name
    global_var_name_to_function = "&" + global_var_name

    # define temporary array to pass as parameters to GenUtils.gen_function_call_with_arg()
    temp_global_var = [global_var_name_to_function]

    GenUtils.gen_comment_line(gen_source_file, "Compare " + global_var_name + " with expected value")
    
    # Contents of global_var_n.actual
    actual_content = global_var_name + ".actual = "
    actual_content += global_var.actual_mem
    actual_content += ";"
    # Contents of global_var_n.expected
    expected_content = global_var_name + ".expected = "
    expected_content += global_var.expected
    expected_content += ";"
    # Contents of global_var_n.mask
    mask_content = global_var_name + ".mask = "
    mask_content += global_var.mask
    mask_content += ";"
    
    GenUtils.source_file(actual_content)
    GenUtils.source_file(expected_content)
    GenUtils.source_file(mask_content)
    
    GenUtils.gen_function_call_with_arg(gen_source_file, "compareBitsOnUint8", "", "", temp_global_var)  
Ejemplo n.º 4
0
def call_funct_preconditon(testcase):
    invoked_func_str = testcase.invoked_func_precondition
    if "-" != invoked_func_str:
        statements = invoked_func_str.split("\n")
        
        GenUtils.gen_comment_line(gen_source_file, "Test case precondition configuration")
        for statement in statements:
            GenUtils.source_file(statement)
        GenUtils.gen_break_line(gen_source_file)
Ejemplo n.º 5
0
def init_param(test_case):
    for param in test_case.params:
        GenUtils.gen_comment_line(gen_source_file, "Initialize " + param.gen_name)
        if param.is_struct_type == "False":
            GenUtils.gen_var_definition(gen_source_file, param.type, param.param_name, param.init_value)
        else:
            GenUtils.gen_var_declaration(gen_source_file, param.type, param.param_name)
            # Split the structure init contents into lines and store in an array
            struct_member_init = param.init_value.split("\n") 
            for statement in struct_member_init:
                GenUtils.source_file(param.param_name + "." + statement + ";")
    GenUtils.gen_break_line(gen_source_file)
Ejemplo n.º 6
0
def gen_section_5_variable(file_type):
    if "SourceFile" == file_type:
        GenUtils.gen_comment_block(gen_source_file, "5. Global, Static and Extern Variables")
        no_test_ccase = len(XlsProcessing.test_suite.test_cases)
        GenUtils.gen_comment_line(gen_source_file, "List of all test cases")
        with GenUtils.source_file.block("void (*TestcaseList_array[" + str(no_test_ccase) + \
        "])(void) = ", ";"):
            counter = 1
            for test_case in XlsProcessing.test_suite.test_cases:
                if counter < no_test_ccase:
                    GenUtils.source_file(test_case.testcase_name + ",")           
                else:
                    GenUtils.source_file(test_case.testcase_name)
                counter += 1
        GenUtils.gen_break_line(gen_source_file)
    if "HeaderFile" == file_type:
        GenUtils.gen_comment_block(gen_header_file, "5. Global, Static and Extern Variables")
        GenUtils.gen_break_line(gen_header_file)
Ejemplo n.º 7
0
def compare_returning_value(return_obj):
    return_obj_name = return_obj.gen_name
    return_obj_name_to_function = "&" + return_obj_name                   

    # define temporary array to pass as parameters to GenUtils.GenUtils.gen_function_call_with_arg()
    temp_return_obj = [return_obj_name_to_function]

    GenUtils.gen_comment_line(gen_source_file, "Compare " + return_obj_name + " with expected value")
    
    # Contents of actual result after function calling
    actual_content = return_obj_name + ".actual = "
    actual_content += "result_ptr;" #fixed name
    # Contents of return_obj.expected_value
    expected_content = return_obj_name + ".expected = (uint8_t*)" # perform a pointer casting
    expected_content += return_obj.expected_value
    expected_content += ";"
        
    GenUtils.source_file(actual_content)
    GenUtils.source_file(expected_content)
    
    GenUtils.gen_function_call_with_arg(gen_source_file, "compareOnUint8Ptr", "", "", temp_return_obj)