Module: Mesa Branch: main Commit: 5f79e78911028240084934795a71c720c7a90dcd URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5f79e78911028240084934795a71c720c7a90dcd
Author: Caio Oliveira <[email protected]> Date: Thu Feb 23 19:24:24 2023 -0800 spirv: Add skip_os_break_in_debug_build option to use in unit tests When running in the CI environment, instead of crashing the test binary, it is preferable to just fail gracefully (in this case return a NULL shader) like is done in release mode, so other tests continue to be executed. For convenience add a variable break_on_failure to the test so the breaking behavior can be re-enable in individual tests when debugging. Reviewed-by: Jesse Natalie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21512> --- src/compiler/spirv/nir_spirv.h | 6 ++++++ src/compiler/spirv/spirv_to_nir.c | 3 ++- src/compiler/spirv/tests/helpers.h | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h index d4668cf3d17..6eafeaa2971 100644 --- a/src/compiler/spirv/nir_spirv.h +++ b/src/compiler/spirv/nir_spirv.h @@ -120,6 +120,12 @@ struct spirv_to_nir_options { /* Force texture sampling to be non-uniform. */ bool force_tex_non_uniform; + + /* In Debug Builds, instead of emitting an OS break on failure, just return NULL from + * spirv_to_nir(). This is useful for the unit tests that want to report a test failed + * but continue executing other tests. + */ + bool skip_os_break_in_debug_build; }; bool gl_spirv_validation(const uint32_t *words, size_t word_count, diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 8f44532a79c..299f4208c91 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -203,7 +203,8 @@ _vtn_fail(struct vtn_builder *b, const char *file, unsigned line, vtn_dump_shader(b, dump_path, "fail"); #ifndef NDEBUG - os_break(); + if (!b->options->skip_os_break_in_debug_build) + os_break(); #endif vtn_longjmp(b->fail_jump, 1); diff --git a/src/compiler/spirv/tests/helpers.h b/src/compiler/spirv/tests/helpers.h index c2082ddd74b..645d1fcf752 100644 --- a/src/compiler/spirv/tests/helpers.h +++ b/src/compiler/spirv/tests/helpers.h @@ -30,7 +30,7 @@ class spirv_test : public ::testing::Test { protected: spirv_test() - : shader(NULL) + : shader(NULL), break_on_failure(false) { glsl_type_singleton_init_or_ref(); } @@ -54,6 +54,7 @@ protected: spirv_options.push_const_addr_format = nir_address_format_32bit_offset; spirv_options.shared_addr_format = nir_address_format_32bit_offset; spirv_options.task_payload_addr_format = nir_address_format_32bit_offset; + spirv_options.skip_os_break_in_debug_build = !break_on_failure; nir_shader_compiler_options nir_options; memset(&nir_options, 0, sizeof(nir_options)); @@ -82,6 +83,7 @@ protected: } nir_shader *shader; + bool break_on_failure; }; #endif /* SPIRV_TEST_HELPERS_H */
