[Beignet] [PATCH 2/2] utests: Added unit test to test LLVM and ASM dump generation in a two step build process with clCompile and clLink APIs.

Song, Ruiling ruiling.song at intel.com
Sat Oct 10 02:01:33 PDT 2015



> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Manasi Navare
> Sent: Thursday, October 1, 2015 7:35 PM
> To: beignet at lists.freedesktop.org
> Cc: Navare, Manasi D
> Subject: [Beignet] [PATCH 2/2] utests: Added unit test to test LLVM and ASM
> dump generation in a two step build process with clCompile and clLink APIs.
> 
>     This patch adds a new test to the unit tests. It uses the existing
>     framework and data structures and tests the llvm/asm dump generation
>     when these flags (-dump-opt-llvm, -dump-opt-asm) are passed as compile and
> link
>     options to clCompileProgram and clLinkProgram APIs along with the dump file
> names.
> 
>     Method added:
>     1) get_compile_link_llvm_asm_info() tests LLVM dump generation after
> clCompileProgram() stage
>        and Gen ASM dump generation after clLinkProgram stage
> 
> Signed-off-by: Manasi Navare <manasi.d.navare at intel.com>
> ---
>  utests/get_cl_info.cpp  | 61
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  utests/utest_helper.cpp | 61
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  utests/utest_helper.hpp |  2 ++
>  3 files changed, 124 insertions(+)
> 
> diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index
> 7c03d95..4513b33 100644
> --- a/utests/get_cl_info.cpp
> +++ b/utests/get_cl_info.cpp
> @@ -470,6 +470,67 @@ void get_build_asm_info(void)
> 
>  MAKE_UTEST_FROM_FUNCTION(get_build_asm_info);
> 
> +void get_compile_link_llvm_asm_info(void)
> +{
> +    map<cl_program_info, void *> maps;
> +    cl_build_status expect_status;
> +    char llvm_file[] = "test_llvm_dump.txt";
> +    char asm_file[] = "test_asm_dump.txt";
> +    char compile_opt[] = "-dump-opt-llvm=test_llvm_dump.txt";
> +    char link_opt[] = "-dump-opt-asm=test_asm_dump.txt";
> +    FILE *fp = NULL;
> +    int sz;
> +
> +    //Remove any pre-existing file
> +    if( (fp = fopen(llvm_file, "r")) != NULL) {
> +        fclose(fp);
> +        std::remove(llvm_file);
> +    }
> +    if( (fp = fopen(asm_file, "r")) != NULL) {
> +        fclose(fp);
> +        std::remove(asm_file);
> +    }
> +
> +    OCL_CALL (cl_kernel_compile_link, "compiler_if_else.cl",
> + "compiler_if_else", compile_opt, link_opt);
> +
> +    /* Do our test.*/
> +    expect_status = CL_BUILD_SUCCESS;
> +    maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS,
> +                          (void *)(new
> + Info_Result<cl_build_status>(expect_status))));
> +
> +
> +    for (map<cl_program_info, void *>::iterator x = maps.begin(); x !=
> maps.end(); ++x) {
> +        switch (x->first) {
> +        case CL_PROGRAM_BUILD_STATUS:
> +            CALL_PROG_BUILD_INFO_AND_RET(cl_build_status);
> +            break;
> +        case CL_PROGRAM_BUILD_OPTIONS:
> +            CALL_PROG_BUILD_INFO_AND_RET(char *);
> +            break;
> +        default:
> +            break;
> +        }
> +    }
> +
> +    //Test is successful if the backend created the file
> +    if( (fp = fopen(llvm_file, "r")) == NULL) {
> +        std::cout << "LLVM file creation.. FAILED";
> +        OCL_ASSERT(0);
> +    } else {
> +        fclose(fp);
> +        std::cout << "LLVM file created.. SUCCESS";
> +    }
> +    if( (fp = fopen(asm_file, "r")) == NULL) {
> +        std::cout << "ASM file creation.. FAILED";
> +        OCL_ASSERT(0);
> +    } else {
> +        fclose(fp);
> +        std::cout << "ASM file created.. SUCCESS";
> +    }
> +}
> +
> +MAKE_UTEST_FROM_FUNCTION(get_compile_link_llvm_asm_info);

I think it is better to separate as two test cases.

> +                file_name, kernel_name);
> +    const char *src = cl_file_map_begin(fm);
> +    const size_t sz = cl_file_map_size(fm);
> +    program = clCreateProgramWithSource(ctx, 1, &src, &sz, &status);
> +    cl_file_map_delete(fm);
> +
> +    if (status != CL_SUCCESS) {
> +      fprintf(stderr, "error calling clCreateProgramWithBinary\n");

Wrong message here.



More information about the Beignet mailing list