[PATCH vkd3d 2/6] tests: Add more flexible todo() implementation.

Józef Kucia joseph.kucia at gmail.com
Mon Dec 3 04:31:27 CST 2018


From: Józef Kucia <jkucia at codeweavers.com>

Based on wine/test.h.

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 include/private/vkd3d_test.h | 75 +++++++++++++++++++++++-------------
 tests/d3d12.c                | 56 +++++++++++----------------
 2 files changed, 71 insertions(+), 60 deletions(-)

diff --git a/include/private/vkd3d_test.h b/include/private/vkd3d_test.h
index fd3ed1572da6..a2649dd64f76 100644
--- a/include/private/vkd3d_test.h
+++ b/include/private/vkd3d_test.h
@@ -32,12 +32,15 @@ static void vkd3d_test_main(int argc, char **argv);
 static const char *vkd3d_test_name;
 static const char *vkd3d_test_platform = "other";
 
+static void vkd3d_test_start_todo(bool is_todo);
+static int vkd3d_test_loop_todo(void);
+static void vkd3d_test_end_todo(void);
+
 #define START_TEST(name) \
         static const char *vkd3d_test_name = #name; \
         static void vkd3d_test_main(int argc, char **argv)
 
 #define ok ok_(__LINE__)
-#define todo todo_(__LINE__)
 #define skip skip_(__LINE__)
 #define trace trace_(__LINE__)
 
@@ -73,6 +76,11 @@ static const char *vkd3d_test_platform = "other";
 #define VKD3D_TEST_TRACE(args...) \
         vkd3d_test_trace(vkd3d_line, args); } while (0)
 
+#define todo_if(is_todo) \
+    for (vkd3d_test_start_todo(is_todo); vkd3d_test_loop_todo(); vkd3d_test_end_todo())
+
+#define todo todo_if(true)
+
 static struct
 {
     LONG success_count;
@@ -82,6 +90,9 @@ static struct
     LONG todo_success_count;
 
     unsigned int debug_level;
+
+    unsigned int todo_level;
+    bool todo_do_loop;
 } vkd3d_test_state;
 
 static bool
@@ -99,7 +110,24 @@ broken(bool condition)
 static void
 vkd3d_test_check_ok(unsigned int line, bool result, const char *fmt, va_list args)
 {
-    if (result)
+    bool is_todo = vkd3d_test_state.todo_level && !vkd3d_test_platform_is_windows();
+
+    if (is_todo)
+    {
+        if (result)
+        {
+            printf("%s:%d Todo succeeded: ", vkd3d_test_name, line);
+            vprintf(fmt, args);
+            InterlockedIncrement(&vkd3d_test_state.todo_success_count);
+        }
+        else
+        {
+            printf("%s:%d: Todo: ", vkd3d_test_name, line);
+            vprintf(fmt, args);
+            InterlockedIncrement(&vkd3d_test_state.todo_count);
+        }
+    }
+    else if (result)
     {
         if (vkd3d_test_state.debug_level > 1)
             printf("%s:%d: Test succeeded.\n", vkd3d_test_name, line);
@@ -123,31 +151,6 @@ vkd3d_test_ok(unsigned int line, bool result, const char *fmt, ...)
     va_end(args);
 }
 
-static void VKD3D_PRINTF_FUNC(3, 4) VKD3D_UNUSED
-vkd3d_test_todo(unsigned int line, bool result, const char *fmt, ...)
-{
-    va_list args;
-
-    va_start(args, fmt);
-    if (vkd3d_test_platform_is_windows())
-    {
-        vkd3d_test_check_ok(line, result, fmt, args);
-    }
-    else if (result)
-    {
-        printf("%s:%d Todo succeeded: ", vkd3d_test_name, line);
-        vprintf(fmt, args);
-        InterlockedIncrement(&vkd3d_test_state.todo_success_count);
-    }
-    else
-    {
-        printf("%s:%d: Todo: ", vkd3d_test_name, line);
-        vprintf(fmt, args);
-        InterlockedIncrement(&vkd3d_test_state.todo_count);
-    }
-    va_end(args);
-}
-
 static void VKD3D_PRINTF_FUNC(2, 3) VKD3D_UNUSED
 vkd3d_test_skip(unsigned int line, const char *fmt, ...)
 {
@@ -283,6 +286,24 @@ static inline void vkd3d_run_test(const char *name, vkd3d_test_pfn test_pfn)
     test_pfn();
 }
 
+static inline void vkd3d_test_start_todo(bool is_todo)
+{
+    vkd3d_test_state.todo_level = (vkd3d_test_state.todo_level << 1) | is_todo;
+    vkd3d_test_state.todo_do_loop = true;
+}
+
+static inline int vkd3d_test_loop_todo(void)
+{
+    bool do_loop = vkd3d_test_state.todo_do_loop;
+    vkd3d_test_state.todo_do_loop = false;
+    return do_loop;
+}
+
+static inline void vkd3d_test_end_todo(void)
+{
+    vkd3d_test_state.todo_level >>= 1;
+}
+
 #define run_test(test_pfn) \
         vkd3d_run_test(#test_pfn, test_pfn)
 
diff --git a/tests/d3d12.c b/tests/d3d12.c
index 3956fbaa3b56..e9dbbaa8c3ba 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -1412,8 +1412,8 @@ static void test_format_support(void)
     memset(&format_support, 0, sizeof(format_support));
     hr = ID3D12Device_CheckFeatureSupport(device, D3D12_FEATURE_FORMAT_SUPPORT,
             &format_support, sizeof(format_support));
-    todo(hr == S_OK, "Got unexpected hr %#x.\n", hr);
-    todo(format_support.Support1 == D3D12_FORMAT_SUPPORT1_BUFFER,
+    todo ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
+    todo ok(format_support.Support1 == D3D12_FORMAT_SUPPORT1_BUFFER,
             "Got unexpected support1 %#x.\n", format_support.Support1);
     ok(!format_support.Support2 || format_support.Support2 == D3D12_FORMAT_SUPPORT2_TILED,
             "Got unexpected support2 %#x.\n", format_support.Support2);
@@ -1792,7 +1792,7 @@ static void test_create_committed_resource(void)
     hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE,
             &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, NULL,
             &IID_ID3D12Resource, (void **)&resource);
-    todo(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ID3D12Resource_Release(resource);
 
@@ -1835,7 +1835,7 @@ static void test_create_committed_resource(void)
     hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE,
             &resource_desc, D3D12_RESOURCE_STATE_RENDER_TARGET, NULL,
             &IID_ID3D12Resource, (void **)&resource);
-    todo(hr == E_INVALIDARG || broken_on_warp(true), "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_INVALIDARG || broken_on_warp(true), "Got unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ID3D12Resource_Release(resource);
 
@@ -2487,7 +2487,7 @@ static void test_create_root_signature(void)
     root_signature_desc.pStaticSamplers = NULL;
     root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
     hr = create_root_signature(device, &root_signature_desc, &root_signature);
-    todo(hr == E_FAIL || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_FAIL || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ID3D12RootSignature_Release(root_signature);
     root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_PIXEL;
@@ -2522,7 +2522,7 @@ static void test_create_root_signature(void)
     root_signature_desc.pStaticSamplers = NULL;
     root_signature_desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;
     hr = create_root_signature(device, &root_signature_desc, &root_signature);
-    todo(hr == E_FAIL || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_FAIL || hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ID3D12RootSignature_Release(root_signature);
     root_parameters[0].ShaderVisibility = D3D12_SHADER_VISIBILITY_GEOMETRY;
@@ -5472,7 +5472,7 @@ static void test_invalid_texture_resource_barriers(void)
     transition_resource_state(command_list, readback_buffer,
             D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COMMON);
     hr = ID3D12GraphicsCommandList_Close(command_list);
-    todo(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
     hr = ID3D12CommandAllocator_Reset(command_allocator);
     ok(SUCCEEDED(hr), "Failed to reset command allocator, hr %#x.\n", hr);
@@ -5485,7 +5485,7 @@ static void test_invalid_texture_resource_barriers(void)
     transition_resource_state(command_list, upload_buffer,
             D3D12_RESOURCE_STATE_GENERIC_READ, D3D12_RESOURCE_STATE_COMMON);
     hr = ID3D12GraphicsCommandList_Close(command_list);
-    todo(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
 
     ID3D12CommandAllocator_Release(command_allocator);
     ID3D12CommandQueue_Release(queue);
@@ -5540,7 +5540,7 @@ static void test_device_removed_reason(void)
 
     hr = ID3D12Device_CreateCommandQueue(device, &command_queue_desc,
             &IID_ID3D12CommandQueue, (void **)&tmp_queue);
-    todo(hr == DXGI_ERROR_DEVICE_REMOVED, "Got unexpected hr %#x.\n", hr);
+    todo ok(hr == DXGI_ERROR_DEVICE_REMOVED, "Got unexpected hr %#x.\n", hr);
     if (SUCCEEDED(hr))
         ID3D12CommandQueue_Release(tmp_queue);
 
@@ -9484,7 +9484,7 @@ static void test_root_signature_serialization_(unsigned int line, const DWORD *c
             (unsigned int)blob_buffer[0], (unsigned int)code[0]);
     for (i = 1; i < 5; ++i)
     {
-        todo_(line)(blob_buffer[i] == code[i], "Got checksum %#x, expected %#x at %u.\n",
+        todo ok_(line)(blob_buffer[i] == code[i], "Got checksum %#x, expected %#x at %u.\n",
                 (unsigned int)blob_buffer[i], (unsigned int)code[i], i - 1);
     }
     for (; i < code_size / sizeof(DWORD); ++i)
@@ -12880,7 +12880,7 @@ static void test_update_descriptor_heap_after_closing_command_list(void)
             D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
     get_texture_readback_with_command_list(context.render_target, 0, &rb, queue, command_list);
     value = get_readback_uint(&rb, 0, 0, 0);
-    todo(value == 0xff00ff00, "Got unexpected value %#x.\n", value);
+    todo ok(value == 0xff00ff00, "Got unexpected value %#x.\n", value);
     release_resource_readback(&rb);
 
     ID3D12DescriptorHeap_Release(cpu_heap);
@@ -17604,17 +17604,12 @@ static void test_atomic_instructions(void)
             unsigned int value = get_readback_uint(&rb, j, 0, 0);
             unsigned int expected = test->expected_result[j];
 
-            if (test->i.x < 0
+            todo_if(test->i.x < 0
                     && (!strcmp(instructions[j], "atomic_imax") || !strcmp(instructions[j], "atomic_imin")))
-                todo(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
-                        "with inputs (%u, %u), (%d), %#x (%d).\n",
-                        i, value, value, expected, expected, instructions[j],
-                        test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
-            else
-                ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
-                        "with inputs (%u, %u), (%d), %#x (%d).\n",
-                        i, value, value, expected, expected, instructions[j],
-                        test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
+            ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
+                    "with inputs (%u, %u), (%d), %#x (%d).\n",
+                    i, value, value, expected, expected, instructions[j],
+                    test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
         }
         release_resource_readback(&rb);
         reset_command_list(command_list, context.allocator);
@@ -17629,16 +17624,11 @@ static void test_atomic_instructions(void)
             unsigned int value = get_readback_uint(&rb, j, 0, 0);
             unsigned int expected = test->expected_result[j];
 
-            if (test->i.x < 0 && todo_instruction)
-                todo(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
-                        "with inputs (%u, %u), (%d), %#x (%d).\n",
-                        i, value, value, expected, expected, imm_instructions[j],
-                        test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
-            else
-                ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
-                        "with inputs (%u, %u), (%d), %#x (%d).\n",
-                        i, value, value, expected, expected, imm_instructions[j],
-                        test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
+            todo_if(test->i.x < 0 && todo_instruction)
+            ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
+                    "with inputs (%u, %u), (%d), %#x (%d).\n",
+                    i, value, value, expected, expected, imm_instructions[j],
+                    test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
         }
         release_resource_readback(&rb);
         reset_command_list(command_list, context.allocator);
@@ -18008,7 +17998,7 @@ static void test_create_query_heap(void)
     heap_desc.NodeMask = 0;
 
     hr = ID3D12Device_CreateQueryHeap(device, &heap_desc, &IID_ID3D12QueryHeap, (void **)&query_heap);
-    todo(hr == S_OK, "Failed to create query heap, type %u, hr %#x.\n", heap_desc.Type, hr);
+    todo ok(hr == S_OK, "Failed to create query heap, type %u, hr %#x.\n", heap_desc.Type, hr);
 
     if (hr == S_OK)
         ID3D12QueryHeap_Release(query_heap);
@@ -18516,7 +18506,7 @@ static void test_resolve_query_data_in_reordered_command_list(void)
     reset_command_list(command_lists[0], context.allocator);
     get_buffer_readback_with_command_list(readback_buffer, DXGI_FORMAT_UNKNOWN, &rb, queue, command_lists[0]);
     result = get_readback_uint64(&rb, 0, 0);
-    todo(result == context.render_target_desc.Width * context.render_target_desc.Height,
+    todo ok(result == context.render_target_desc.Width * context.render_target_desc.Height,
             "Got unexpected result %"PRIu64".\n", result);
     release_resource_readback(&rb);
 
-- 
2.18.1




More information about the wine-devel mailing list