Zebediah Figura : tests: Add some basic tests for #if and related preprocessor directives.

Alexandre Julliard julliard at winehq.org
Mon Nov 23 15:41:30 CST 2020


Module: vkd3d
Branch: master
Commit: ca28ac17fb39b234a4ce0686abf8259f83b55755
URL:    https://source.winehq.org/git/vkd3d.git/?a=commit;h=ca28ac17fb39b234a4ce0686abf8259f83b55755

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Sat Nov 21 17:23:45 2020 -0600

tests: Add some basic tests for #if and related preprocessor directives.

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 Makefile.am                  |   2 +
 tests/preproc-if.shader_test | 126 +++++++++++++++++++++++++++++++++++++++++++
 tests/shader_runner_d3d12.c  |  31 +++++++++++
 3 files changed, 159 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 93289a2..60789f4 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 0000000..54ee94d
--- /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 787e90a..39495fa 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:
                 {




More information about the wine-cvs mailing list