From ca28ac17fb39b234a4ce0686abf8259f83b55755 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Sat, 21 Nov 2020 17:23:45 -0600 Subject: [PATCH] tests: Add some basic tests for #if and related preprocessor directives. Signed-off-by: Zebediah Figura Signed-off-by: Henri Verbeet Signed-off-by: Matteo Bruni Signed-off-by: Alexandre Julliard --- Makefile.am | 2 + tests/preproc-if.shader_test | 126 +++++++++++++++++++++++++++++++++++ tests/shader_runner_d3d12.c | 31 +++++++++ 3 files changed, 159 insertions(+) create mode 100644 tests/preproc-if.shader_test diff --git a/Makefile.am b/Makefile.am index 93289a23..60789f43 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,6 +64,7 @@ vkd3d_shader_tests = \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/math.shader_test \ + tests/preproc-if.shader_test \ tests/swizzle-0.shader_test \ tests/swizzle-1.shader_test \ tests/swizzle-2.shader_test \ @@ -206,6 +207,7 @@ XFAIL_TESTS = \ tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \ tests/math.shader_test \ + tests/preproc-if.shader_test \ tests/swizzle-0.shader_test \ tests/swizzle-1.shader_test \ tests/swizzle-2.shader_test \ diff --git a/tests/preproc-if.shader_test b/tests/preproc-if.shader_test new file mode 100644 index 00000000..54ee94d6 --- /dev/null +++ b/tests/preproc-if.shader_test @@ -0,0 +1,126 @@ +[preproc] +#if 1 +pass +#endif + +[preproc] +#if 1 +pass + +[preproc] +pass +#if 0 +fail + +[preproc] +#if 1 +pass +#else +fail +#endif + +[preproc] +#if 0 +fail +#else +pass +#endif + +[preproc] +#if 0 +fail +#else +pass + +[preproc] +#if 0 +fail +#elif 1 +pass +#else +fail +#endif + +[preproc] +#if 1 +pass +#elif 1 +fail +#else +fail +#endif + +[preproc] +#if 0 +fail +#elif 0 +fail +#else +pass +#endif + +[preproc] +#if 0 +#if 1 +fail +#endif +#else +#if 0 +fail +#else +pass +#endif +#endif + +[preproc] +#if 0 +fail +#endif +pass + +[preproc] +#endif +pass + +[preproc] +/* The #elif is effectively ignored here. */ +#if 0 +fail +#else +pass +#elif 0 +#endif + +[preproc] +#if 0 +fail +#else +#elif 0 +pass +#endif + +[preproc] +/* Similarly, the second #else is effectively ignored here. */ +#if 0 +fail +#else +pass +#else +#endif + +[preproc] +/* Similarly, the second #else is effectively ignored here. */ +#if 0 +fail +#else +#else +pass +#endif + +[preproc] +#if 0 +#define KEY fail +#else +#define KEY pass +#endif +KEY diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 787e90ad..39495fa2 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -102,6 +102,7 @@ static ID3D10Blob *compile_shader(const char *source, const char *target) enum parse_state { STATE_NONE, + STATE_PREPROC, STATE_SHADER_INVALID_PIXEL, STATE_SHADER_PIXEL, STATE_TEST, @@ -345,6 +346,33 @@ START_TEST(shader_runner_d3d12) shader_source_len = 0; break; } + + case STATE_PREPROC: + { + ID3D10Blob *blob = NULL, *errors = NULL; + HRESULT hr; + char *text; + + hr = D3DPreprocess(shader_source, strlen(shader_source), NULL, NULL, NULL, &blob, &errors); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + if (hr == S_OK) + { + if (errors) + { + if (vkd3d_test_state.debug_level) + trace("%s\n", (char *)ID3D10Blob_GetBufferPointer(errors)); + ID3D10Blob_Release(errors); + } + + text = ID3D10Blob_GetBufferPointer(blob); + ok(strstr(text, "pass"), "'pass' not found in preprocessed shader.\n"); + ok(!strstr(text, "fail"), "'fail' found in preprocessed shader.\n"); + ID3D10Blob_Release(blob); + } + + shader_source_len = 0; + break; + } } } @@ -359,6 +387,8 @@ START_TEST(shader_runner_d3d12) state = STATE_SHADER_INVALID_PIXEL; else if (!strcmp(line, "[test]\n")) state = STATE_TEST; + else if (!strcmp(line, "[preproc]\n")) + state = STATE_PREPROC; vkd3d_test_set_context("Section %.*s, line %u", strlen(line) - 1, line, line_number); } @@ -371,6 +401,7 @@ START_TEST(shader_runner_d3d12) fprintf(stderr, "Ignoring line '%s' in %s.\n", line, argv[1]); break; + case STATE_PREPROC: case STATE_SHADER_INVALID_PIXEL: case STATE_SHADER_PIXEL: {