From 6d87f03488a454e55fb56ee3ac453af73bf61fef Mon Sep 17 00:00:00 2001 From: Sirisha Gandikota Date: Wed, 2 Sep 2015 01:44:26 -0700 Subject: utests: Added unit tests to test LLVM and ASM dump generation. This patch adds 2 new tests 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 build options along with the dump file names. Methods added: 1) get_build_llvm_info() tests LLVM dump generation 2) get_build_asm_info() tests ASM dump generation Signed-off-by: Sirisha Gandikota Reviewed-by: "Song, Ruiling" --- utests/get_cl_info.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'utests/get_cl_info.cpp') diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index e2dc0d77..7c03d957 100644 --- a/utests/get_cl_info.cpp +++ b/utests/get_cl_info.cpp @@ -364,6 +364,113 @@ void get_program_build_info(void) MAKE_UTEST_FROM_FUNCTION(get_program_build_info); + +// This method uses clGetProgramBuildInfo to check the llvm dump build options sent +// and verifies that the llvm dump file is actually generated in the backend. +void get_build_llvm_info(void) +{ + map maps; + cl_build_status expect_status; + char llvm_file[] = "test_llvm_dump.txt"; + char build_opt[] = "-dump-opt-llvm=test_llvm_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); + } + + OCL_CALL (cl_kernel_init, "compiler_if_else.cl", "compiler_if_else", SOURCE, build_opt); + + /* Do our test.*/ + expect_status = CL_BUILD_SUCCESS; + maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS, + (void *)(new Info_Result(expect_status)))); + sz = strlen(build_opt) + 1; + maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS, + (void *)(new Info_Result(build_opt, sz)))); + + for (map::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"; + } +} + +MAKE_UTEST_FROM_FUNCTION(get_build_llvm_info); + + +// This method uses clGetProgramBuildInfo to check the asm dump build options sent +// And verifies that the asm dump file is actually generated in the backend. +void get_build_asm_info(void) +{ + map maps; + cl_build_status expect_status; + char asm_file[] = "test_asm_dump.txt"; + char build_opt[] ="-dump-opt-asm=test_asm_dump.txt"; + FILE *fp = NULL; + int sz; + + //Remove any pre-existing file + if( (fp = fopen(asm_file, "r")) != NULL) { + fclose(fp); + std::remove(asm_file); + } + + OCL_CALL (cl_kernel_init, "compiler_if_else.cl", "compiler_if_else", SOURCE, build_opt); + + /* Do our test.*/ + expect_status = CL_BUILD_SUCCESS; + maps.insert(make_pair(CL_PROGRAM_BUILD_STATUS, + (void *)(new Info_Result(expect_status)))); + sz = strlen(build_opt) + 1; + maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS, + (void *)(new Info_Result(build_opt, sz)))); + + for (map::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(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_build_asm_info); + + /* ***************************************************** * * clGetContextInfo * * ***************************************************** */ -- cgit v1.2.1