intel/compiler: Free resources on test teardown

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>
This commit is contained in:
Rohan Garg
2021-02-10 16:43:08 +01:00
parent 628c10f14e
commit 56bbbc8322
9 changed files with 155 additions and 64 deletions

View File

@@ -340,5 +340,6 @@ main(UNUSED int argc, UNUSED char **argv)
fail |= run_tests(devinfo);
}
free(devinfo);
return fail;
}

View 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)
{

View 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)
{

View 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)
{

View 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)
{

View 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)
{

View 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)
{

View 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)
{

View 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;
nir_shader *shader =
nir_shader_create(NULL, MESA_SHADER_VERTEX, NULL, NULL);
prog_data = ralloc(ctx, struct brw_vue_prog_data);
v = new register_coalesce_vec4_visitor(compiler, shader, prog_data);
nir_shader *shader =
nir_shader_create(ctx, MESA_SHADER_VERTEX, NULL, NULL);
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)
{