mesa/src/compiler/nir/tests/nir_test.h
Konstantin Seurer 6eb0a3a5b7 nir/tests: Refactor boilerplate into a common header
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24249>
2023-07-24 11:44:46 +00:00

41 lines
792 B
C++

/*
* Copyright © 2023 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#ifndef NIR_TESTS_NIR_TEST_H
#define NIR_TESTS_NIR_TEST_H
#include <gtest/gtest.h>
#include "nir.h"
#include "nir_builder.h"
class nir_test : public ::testing::Test {
protected:
nir_test(const char *name)
{
glsl_type_singleton_init_or_ref();
static const nir_shader_compiler_options options = {};
_b = nir_builder_init_simple_shader(MESA_SHADER_COMPUTE, &options, "%s", name);
b = &_b;
}
virtual ~nir_test()
{
if (HasFailure()) {
printf("\nShader from the failed test:\n\n");
nir_print_shader(b->shader, stdout);
}
ralloc_free(b->shader);
glsl_type_singleton_decref();
}
nir_builder _b;
nir_builder *b;
};
#endif