intel/compiler: Free resources on test teardown
authorRohan Garg <rohan.garg@collabora.com>
Wed, 10 Feb 2021 15:43:08 +0000 (16:43 +0100)
committerRohan Garg <rohan.garg@collabora.com>
Tue, 16 Feb 2021 14:07:52 +0000 (15:07 +0100)
Ensure that all resources are properly released by
properly parenting them to a memory context and releasing
the context during test teardown.

Signed-off-by: Rohan Garg <rohan.garg@collabora.com>
Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8162>

src/intel/compiler/test_eu_compact.cpp
src/intel/compiler/test_fs_cmod_propagation.cpp
src/intel/compiler/test_fs_copy_propagation.cpp
src/intel/compiler/test_fs_saturate_propagation.cpp
src/intel/compiler/test_fs_scoreboard.cpp
src/intel/compiler/test_vec4_cmod_propagation.cpp
src/intel/compiler/test_vec4_copy_propagation.cpp
src/intel/compiler/test_vec4_dead_code_eliminate.cpp
src/intel/compiler/test_vec4_register_coalesce.cpp

index a371a32..f966ba4 100644 (file)
@@ -340,5 +340,6 @@ main(UNUSED int argc, UNUSED char **argv)
       fail |= run_tests(devinfo);
    }
 
+   free(devinfo);
    return fail;
 }
index af9489e..6abd7ee 100644 (file)
@@ -30,11 +30,12 @@ using namespace brw;
 
 class cmod_propagation_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct brw_wm_prog_data *prog_data;
    struct gl_shader_program *shader_prog;
    fs_visitor *v;
@@ -54,29 +55,39 @@ class cmod_propagation_fs_visitor : public fs_visitor
 {
 public:
    cmod_propagation_fs_visitor(struct brw_compiler *compiler,
+                               void *mem_ctx,
                                struct brw_wm_prog_data *prog_data,
                                nir_shader *shader)
-      : fs_visitor(compiler, NULL, NULL, NULL,
+      : fs_visitor(compiler, NULL, mem_ctx, NULL,
                    &prog_data->base, shader, 8, -1) {}
 };
 
 
 void cmod_propagation_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
-   prog_data = ralloc(NULL, struct brw_wm_prog_data);
+   prog_data = ralloc(ctx, struct brw_wm_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_FRAGMENT, NULL, NULL);
 
-   v = new cmod_propagation_fs_visitor(compiler, prog_data, shader);
+   v = new cmod_propagation_fs_visitor(compiler, ctx, prog_data, shader);
 
    devinfo->gen = 7;
 }
 
+void cmod_propagation_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static fs_inst *
 instruction(bblock_t *block, int num)
 {
index db08a34..8ec01f4 100644 (file)
@@ -30,11 +30,12 @@ using namespace brw;
 
 class copy_propagation_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct brw_wm_prog_data *prog_data;
    struct gl_shader_program *shader_prog;
    fs_visitor *v;
@@ -44,29 +45,39 @@ class copy_propagation_fs_visitor : public fs_visitor
 {
 public:
    copy_propagation_fs_visitor(struct brw_compiler *compiler,
+                               void *mem_ctx,
                                struct brw_wm_prog_data *prog_data,
                                nir_shader *shader)
-      : fs_visitor(compiler, NULL, NULL, NULL,
+      : fs_visitor(compiler, NULL, mem_ctx, NULL,
                    &prog_data->base, shader, 8, -1) {}
 };
 
 
 void copy_propagation_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
-   prog_data = ralloc(NULL, struct brw_wm_prog_data);
+   prog_data = ralloc(ctx, struct brw_wm_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_FRAGMENT, NULL, NULL);
 
-   v = new copy_propagation_fs_visitor(compiler, prog_data, shader);
+   v = new copy_propagation_fs_visitor(compiler, ctx, prog_data, shader);
 
    devinfo->gen = 4;
 }
 
+void copy_propagation_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static fs_inst *
 instruction(bblock_t *block, int num)
 {
index df8f5cc..1d4c799 100644 (file)
@@ -30,11 +30,12 @@ using namespace brw;
 
 class saturate_propagation_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct brw_wm_prog_data *prog_data;
    struct gl_shader_program *shader_prog;
    fs_visitor *v;
@@ -44,29 +45,40 @@ class saturate_propagation_fs_visitor : public fs_visitor
 {
 public:
    saturate_propagation_fs_visitor(struct brw_compiler *compiler,
+                                   void *mem_ctx,
                                    struct brw_wm_prog_data *prog_data,
                                    nir_shader *shader)
-      : fs_visitor(compiler, NULL, NULL, NULL,
+      : fs_visitor(compiler, NULL, mem_ctx, NULL,
                    &prog_data->base, shader, 16, -1) {}
 };
 
 
 void saturate_propagation_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
-   prog_data = ralloc(NULL, struct brw_wm_prog_data);
+   prog_data = ralloc(ctx, struct brw_wm_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_FRAGMENT, NULL, NULL);
 
-   v = new saturate_propagation_fs_visitor(compiler, prog_data, shader);
+   v = new saturate_propagation_fs_visitor(compiler, ctx, prog_data, shader);
 
    devinfo->gen = 6;
 }
 
+void saturate_propagation_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
+
 static fs_inst *
 instruction(bblock_t *block, int num)
 {
index 71733c8..470b0f9 100644 (file)
@@ -30,11 +30,12 @@ using namespace brw;
 
 class scoreboard_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct brw_wm_prog_data *prog_data;
    struct gl_shader_program *shader_prog;
    fs_visitor *v;
@@ -42,20 +43,29 @@ public:
 
 void scoreboard_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
-   prog_data = ralloc(NULL, struct brw_wm_prog_data);
+   prog_data = ralloc(ctx, struct brw_wm_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_FRAGMENT, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_FRAGMENT, NULL, NULL);
 
-   v = new fs_visitor(compiler, NULL, NULL, NULL, &prog_data->base, shader, 8, -1);
+   v = new fs_visitor(compiler, NULL, ctx, NULL, &prog_data->base, shader, 8, -1);
 
    devinfo->gen = 12;
 }
 
+void scoreboard_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static fs_inst *
 instruction(bblock_t *block, int num)
 {
index 02c6f85..516e5a3 100644 (file)
@@ -33,11 +33,12 @@ using namespace brw;
 
 class cmod_propagation_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct gl_shader_program *shader_prog;
    struct brw_vue_prog_data *prog_data;
    vec4_visitor *v;
@@ -47,9 +48,10 @@ class cmod_propagation_vec4_visitor : public vec4_visitor
 {
 public:
    cmod_propagation_vec4_visitor(struct brw_compiler *compiler,
+                                 void *mem_ctx,
                                  nir_shader *shader,
                                  struct brw_vue_prog_data *prog_data)
-      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
+      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, mem_ctx,
                      false, -1)
       {
          prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
@@ -96,20 +98,29 @@ protected:
 
 void cmod_propagation_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
-   prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
+   prog_data = ralloc(ctx, struct brw_vue_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
 
-   v = new cmod_propagation_vec4_visitor(compiler, shader, prog_data);
+   v = new cmod_propagation_vec4_visitor(compiler, ctx, shader, prog_data);
 
    devinfo->gen = 4;
 }
 
+void cmod_propagation_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static vec4_instruction *
 instruction(bblock_t *block, int num)
 {
index 238f04d..8bdceb5 100644 (file)
@@ -31,11 +31,12 @@ int ret = 0;
 
 class copy_propagation_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct gl_shader_program *shader_prog;
    struct brw_vue_prog_data *prog_data;
    vec4_visitor *v;
@@ -45,9 +46,10 @@ class copy_propagation_vec4_visitor : public vec4_visitor
 {
 public:
    copy_propagation_vec4_visitor(struct brw_compiler *compiler,
+                                 void *mem_ctx,
                                  nir_shader *shader,
                                  struct brw_vue_prog_data *prog_data)
-      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
+      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, mem_ctx,
                      false /* no_spills */, -1)
    {
       prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
@@ -88,20 +90,30 @@ protected:
 
 void copy_propagation_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
-   prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
+   prog_data = ralloc(ctx, struct brw_vue_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
 
-   v = new copy_propagation_vec4_visitor(compiler, shader, prog_data);
+   v = new copy_propagation_vec4_visitor(compiler, ctx, shader, prog_data);
 
    devinfo->gen = 4;
 }
 
+void copy_propagation_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
+
 static void
 copy_propagation(vec4_visitor *v)
 {
index 9bf787f..7463663 100644 (file)
@@ -29,11 +29,12 @@ using namespace brw;
 
 class dead_code_eliminate_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct gl_shader_program *shader_prog;
    struct brw_vue_prog_data *prog_data;
    vec4_visitor *v;
@@ -43,9 +44,10 @@ class dead_code_eliminate_vec4_visitor : public vec4_visitor
 {
 public:
    dead_code_eliminate_vec4_visitor(struct brw_compiler *compiler,
+                                 void *mem_ctx,
                                  nir_shader *shader,
                                  struct brw_vue_prog_data *prog_data)
-      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
+      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, mem_ctx,
                      false /* no_spills */, -1)
    {
       prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
@@ -86,20 +88,29 @@ protected:
 
 void dead_code_eliminate_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
-   prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
+   prog_data = ralloc(ctx, struct brw_vue_prog_data);
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
 
-   v = new dead_code_eliminate_vec4_visitor(compiler, shader, prog_data);
+  v = new dead_code_eliminate_vec4_visitor(compiler, ctx, shader, prog_data);
 
    devinfo->gen = 4;
 }
 
+void dead_code_eliminate_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static void
 dead_code_eliminate(vec4_visitor *v)
 {
index 4621fd6..657c7a8 100644 (file)
@@ -33,11 +33,12 @@ int ret = 0;
 
 class register_coalesce_test : public ::testing::Test {
    virtual void SetUp();
+   virtual void TearDown();
 
 public:
    struct brw_compiler *compiler;
    struct gen_device_info *devinfo;
-   struct gl_context *ctx;
+   void *ctx;
    struct gl_shader_program *shader_prog;
    struct brw_vue_prog_data *prog_data;
    vec4_visitor *v;
@@ -48,9 +49,10 @@ class register_coalesce_vec4_visitor : public vec4_visitor
 {
 public:
    register_coalesce_vec4_visitor(struct brw_compiler *compiler,
+                                  void *mem_ctx,
                                   nir_shader *shader,
                                   struct brw_vue_prog_data *prog_data)
-      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, NULL,
+      : vec4_visitor(compiler, NULL, NULL, prog_data, shader, mem_ctx,
                      false /* no_spills */, -1)
    {
       prog_data->dispatch_mode = DISPATCH_MODE_4X2_DUAL_OBJECT;
@@ -91,20 +93,30 @@ protected:
 
 void register_coalesce_test::SetUp()
 {
-   ctx = (struct gl_context *)calloc(1, sizeof(*ctx));
-   compiler = (struct brw_compiler *)calloc(1, sizeof(*compiler));
-   devinfo = (struct gen_device_info *)calloc(1, sizeof(*devinfo));
-   prog_data = (struct brw_vue_prog_data *)calloc(1, sizeof(*prog_data));
+   ctx = ralloc_context(NULL);
+   compiler = rzalloc(ctx, struct brw_compiler);
+   devinfo = rzalloc(ctx, struct gen_device_info);
    compiler->devinfo = devinfo;
 
+   prog_data = ralloc(ctx, struct brw_vue_prog_data);
+
    nir_shader *shader =
-      nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
+      nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
 
-   v = new register_coalesce_vec4_visitor(compiler, shader, prog_data);
+   v = new register_coalesce_vec4_visitor(compiler, ctx, shader, prog_data);
 
    devinfo->gen = 4;
 }
 
+void register_coalesce_test::TearDown()
+{
+   delete v;
+   v = NULL;
+
+   ralloc_free(ctx);
+   ctx = NULL;
+}
+
 static void
 _register_coalesce(vec4_visitor *v, const char *func)
 {