tests: Introduce assert_that().

This allows us to put a bug_if() or todo_if() in the front of functions
that check other conditions not directly related to the actual test.

assert_that() is similar to ok(). The main difference is that it ignores
bug_if() and todo_if().

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2019-03-11 12:19:20 +01:00 committed by Alexandre Julliard
parent b0c8561cff
commit 6c141d7457
4 changed files with 56 additions and 29 deletions

View File

@ -40,10 +40,26 @@ static void vkd3d_test_end_todo(void);
static const char *vkd3d_test_name = #name; \
static void vkd3d_test_main(int argc, char **argv)
/*
* Use assert_that() for conditions that should always be true.
* todo_if() and bug_if() do not influence assert_that().
*/
#define assert_that assert_that_(__LINE__)
#define ok ok_(__LINE__)
#define skip skip_(__LINE__)
#define trace trace_(__LINE__)
#define assert_that_(line) \
do { \
unsigned int vkd3d_line = line; \
VKD3D_TEST_ASSERT_THAT
#define VKD3D_TEST_ASSERT_THAT(args...) \
vkd3d_test_assert_that(vkd3d_line, args); } while (0)
#define ok_(line) \
do { \
unsigned int vkd3d_line = line; \
@ -116,6 +132,33 @@ broken(bool condition)
return condition && vkd3d_test_platform_is_windows();
}
static void
vkd3d_test_check_assert_that(unsigned int line, bool result, const char *fmt, va_list args)
{
if (result)
{
InterlockedIncrement(&vkd3d_test_state.success_count);
if (vkd3d_test_state.debug_level > 1)
printf("%s:%d%s: Test succeeded.\n", vkd3d_test_name, line, vkd3d_test_state.context);
}
else
{
InterlockedIncrement(&vkd3d_test_state.failure_count);
printf("%s:%d%s: Test failed: ", vkd3d_test_name, line, vkd3d_test_state.context);
vprintf(fmt, args);
}
}
static void VKD3D_PRINTF_FUNC(3, 4) VKD3D_UNUSED
vkd3d_test_assert_that(unsigned int line, bool result, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vkd3d_test_check_assert_that(line, result, fmt, args);
va_end(args);
}
static void
vkd3d_test_check_ok(unsigned int line, bool result, const char *fmt, va_list args)
{
@ -147,17 +190,9 @@ vkd3d_test_check_ok(unsigned int line, bool result, const char *fmt, va_list arg
}
vprintf(fmt, args);
}
else if (result)
{
InterlockedIncrement(&vkd3d_test_state.success_count);
if (vkd3d_test_state.debug_level > 1)
printf("%s:%d%s: Test succeeded.\n", vkd3d_test_name, line, vkd3d_test_state.context);
}
else
{
InterlockedIncrement(&vkd3d_test_state.failure_count);
printf("%s:%d%s: Test failed: ", vkd3d_test_name, line, vkd3d_test_state.context);
vprintf(fmt, args);
vkd3d_test_check_assert_that(line, result, fmt, args);
}
}

View File

@ -5606,7 +5606,6 @@ static void test_draw_uav_only(void)
D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle;
D3D12_ROOT_PARAMETER root_parameter;
struct test_context_desc desc;
struct resource_readback rb;
struct test_context context;
ID3D12CommandQueue *queue;
ID3D12Resource *resource;
@ -5688,10 +5687,8 @@ static void test_draw_uav_only(void)
transition_resource_state(command_list, resource,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
get_texture_readback_with_command_list(resource, 0, &rb, queue, command_list);
bug_if(is_radv_device(context.device))
check_readback_data_uint(&rb, NULL, 500, 0);
release_resource_readback(&rb);
check_sub_resource_uint(resource, 0, queue, command_list, 500, 0);
ID3D12DescriptorHeap_Release(cpu_descriptor_heap);
ID3D12DescriptorHeap_Release(descriptor_heap);
@ -7906,7 +7903,7 @@ static void test_shader_instructions(void)
struct ivec4 i;
} output;
bool skip_on_warp;
bool skip_on_mesa;
bool is_mesa_bug;
}
tests[] =
{
@ -8671,12 +8668,6 @@ static void test_shader_instructions(void)
continue;
}
if (tests[i].skip_on_mesa && is_mesa_device(context.device))
{
skip("Skipping shader '%s' test on Mesa.\n", tests[i].ps->name);
continue;
}
if (current_ps != tests[i].ps)
{
if (context.pipeline_state)
@ -8704,6 +8695,7 @@ static void test_shader_instructions(void)
transition_resource_state(command_list, context.render_target,
D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
bug_if(tests[i].is_mesa_bug && is_mesa_device(context.device))
check_sub_resource_vec4(context.render_target, 0, queue, command_list, &tests[i].output.f, 2);
reset_command_list(command_list, context.allocator);

View File

@ -220,12 +220,12 @@ static void wait_queue_idle_(unsigned int line, ID3D12Device *device, ID3D12Comm
hr = ID3D12Device_CreateFence(device, 0, D3D12_FENCE_FLAG_NONE,
&IID_ID3D12Fence, (void **)&fence);
ok_(line)(hr == S_OK, "Failed to create fence, hr %#x.\n", hr);
assert_that_(line)(hr == S_OK, "Failed to create fence, hr %#x.\n", hr);
hr = ID3D12CommandQueue_Signal(queue, fence, 1);
ok_(line)(hr == S_OK, "Failed to signal fence, hr %#x.\n", hr);
assert_that_(line)(hr == S_OK, "Failed to signal fence, hr %#x.\n", hr);
hr = wait_for_fence(fence, 1);
ok_(line)(hr == S_OK, "Failed to wait for fence, hr %#x.\n", hr);
assert_that_(line)(hr == S_OK, "Failed to wait for fence, hr %#x.\n", hr);
ID3D12Fence_Release(fence);
}

View File

@ -121,7 +121,7 @@ static ID3D12Resource *create_buffer_(unsigned int line, ID3D12Device *device,
hr = ID3D12Device_CreateCommittedResource(device, &heap_properties,
D3D12_HEAP_FLAG_NONE, &resource_desc, initial_resource_state,
NULL, &IID_ID3D12Resource, (void **)&buffer);
ok_(line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
assert_that_(line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
return buffer;
}
@ -291,10 +291,10 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi
HRESULT hr;
hr = ID3D12Resource_GetDevice(texture, &IID_ID3D12Device, (void **)&device);
ok(hr == S_OK, "Failed to get device, hr %#x.\n", hr);
assert_that(hr == S_OK, "Failed to get device, hr %#x.\n", hr);
resource_desc = ID3D12Resource_GetDesc(texture);
ok(resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER,
assert_that(resource_desc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER,
"Resource %p is not texture.\n", texture);
miplevel = sub_resource % resource_desc.MipLevels;
@ -317,7 +317,7 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi
hr = ID3D12Device_CreateCommittedResource(device, &heap_properties, D3D12_HEAP_FLAG_NONE,
&resource_desc, D3D12_RESOURCE_STATE_RESOLVE_DEST, NULL,
&IID_ID3D12Resource, (void **)&src_resource);
ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
assert_that(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
ID3D12GraphicsCommandList_ResolveSubresource(command_list,
src_resource, 0, texture, sub_resource, resource_desc.Format);
@ -348,7 +348,7 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi
ID3D12GraphicsCommandList_CopyTextureRegion(command_list, &dst_location, 0, 0, 0, &src_location, NULL);
hr = ID3D12GraphicsCommandList_Close(command_list);
ok(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
assert_that(hr == S_OK, "Failed to close command list, hr %#x.\n", hr);
exec_command_list(queue, command_list);
wait_queue_idle(device, queue);
@ -360,7 +360,7 @@ static void get_texture_readback_with_command_list(ID3D12Resource *texture, unsi
read_range.Begin = 0;
read_range.End = resource_desc.Width;
hr = ID3D12Resource_Map(rb->resource, 0, &read_range, &rb->data);
ok(hr == S_OK, "Failed to map readback buffer, hr %#x.\n", hr);
assert_that(hr == S_OK, "Failed to map readback buffer, hr %#x.\n", hr);
}
static void *get_readback_data(struct resource_readback *rb,