utests: Added unit tests to test LLVM and ASM dump generation.

Submitted by Sirisha Gandikota on Sept. 2, 2015, 8:44 a.m.

Details

Message ID 1441183466-2733-1-git-send-email-sirisha.gandikota@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Sirisha Gandikota Sept. 2, 2015, 8:44 a.m.
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 <sirisha.gandikota@intel.com>
---
 utests/get_cl_info.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

Patch hide | download patch | download mbox

diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp
index e2dc0d7..7c03d95 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<cl_program_info, void *> 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<cl_build_status>(expect_status))));
+    sz = strlen(build_opt) + 1;
+    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,
+                          (void *)(new Info_Result<char *>(build_opt, sz))));
+
+    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";
+    }
+}
+
+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<cl_program_info, void *> 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<cl_build_status>(expect_status))));
+    sz = strlen(build_opt) + 1;
+    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,
+                          (void *)(new Info_Result<char *>(build_opt, sz))));
+
+    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(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                                      *
  * ***************************************************** */

Comments

LGTM

Thanks!
Ruiling
> -----Original Message-----

> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf Of

> Sirisha Gandikota

> Sent: Wednesday, September 2, 2015 4:44 PM

> To: Zou, Nanhai; beignet@lists.freedesktop.org

> Cc: Gandikota, Sirisha

> Subject: [Beignet] [PATCH] 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 <sirisha.gandikota@intel.com>

> ---

>  utests/get_cl_info.cpp | 107

> +++++++++++++++++++++++++++++++++++++++++++++++++

>  1 file changed, 107 insertions(+)

> 

> diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index

> e2dc0d7..7c03d95 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<cl_program_info, void *> 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<cl_build_status>(expect_status))));

> +    sz = strlen(build_opt) + 1;

> +    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,

> +                          (void *)(new Info_Result<char *>(build_opt,

> + sz))));

> +

> +    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";

> +    }

> +}

> +

> +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<cl_program_info, void *> 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<cl_build_status>(expect_status))));

> +    sz = strlen(build_opt) + 1;

> +    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,

> +                          (void *)(new Info_Result<char *>(build_opt,

> + sz))));

> +

> +    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(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                                      *

>   * ***************************************************** */

> --

> 1.9.1

> 

> _______________________________________________

> Beignet mailing list

> Beignet@lists.freedesktop.org

> http://lists.freedesktop.org/mailman/listinfo/beignet
Pushed, thanks.

> -----Original Message-----

> From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf Of

> Song, Ruiling

> Sent: Sunday, September 6, 2015 15:05

> To: Gandikota, Sirisha; Zou, Nanhai; beignet@lists.freedesktop.org

> Cc: Gandikota, Sirisha

> Subject: Re: [Beignet] [PATCH] utests: Added unit tests to test LLVM and

> ASM dump generation.

> 

> LGTM

> 

> Thanks!

> Ruiling

> > -----Original Message-----

> > From: Beignet [mailto:beignet-bounces@lists.freedesktop.org] On Behalf

> > Of Sirisha Gandikota

> > Sent: Wednesday, September 2, 2015 4:44 PM

> > To: Zou, Nanhai; beignet@lists.freedesktop.org

> > Cc: Gandikota, Sirisha

> > Subject: [Beignet] [PATCH] 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 <sirisha.gandikota@intel.com>

> > ---

> >  utests/get_cl_info.cpp | 107

> > +++++++++++++++++++++++++++++++++++++++++++++++++

> >  1 file changed, 107 insertions(+)

> >

> > diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp index

> > e2dc0d7..7c03d95 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<cl_program_info, void *> 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<cl_build_status>(expect_status))));

> > +    sz = strlen(build_opt) + 1;

> > +    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,

> > +                          (void *)(new Info_Result<char *>(build_opt,

> > + sz))));

> > +

> > +    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";

> > +    }

> > +}

> > +

> > +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<cl_program_info, void *> 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<cl_build_status>(expect_status))));

> > +    sz = strlen(build_opt) + 1;

> > +    maps.insert(make_pair(CL_PROGRAM_BUILD_OPTIONS,

> > +                          (void *)(new Info_Result<char *>(build_opt,

> > + sz))));

> > +

> > +    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(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                                      *

> >   * ***************************************************** */

> > --

> > 1.9.1

> >

> > _______________________________________________

> > Beignet mailing list

> > Beignet@lists.freedesktop.org

> > http://lists.freedesktop.org/mailman/listinfo/beignet

> _______________________________________________

> Beignet mailing list

> Beignet@lists.freedesktop.org

> http://lists.freedesktop.org/mailman/listinfo/beignet