include: Make test context information nestable.

Based on Wine.
This commit is contained in:
Zebediah Figura 2023-02-23 16:20:40 -06:00 committed by Alexandre Julliard
parent 1bf5050d3d
commit dfa4bfdd03
Notes: Alexandre Julliard 2023-04-04 22:35:39 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/133
5 changed files with 232 additions and 161 deletions

View File

@ -118,7 +118,8 @@ struct vkd3d_test_state
bool bug_enabled;
const char *test_name_filter;
char context[1024];
char context[8][128];
unsigned int context_count;
};
extern struct vkd3d_test_state vkd3d_test_state;
@ -136,7 +137,12 @@ broken(bool condition)
static void vkd3d_test_printf(unsigned int line, const char *msg)
{
printf("%s:%u%s: %s", vkd3d_test_name, line, vkd3d_test_state.context, msg);
unsigned int i;
printf("%s:%u: ", vkd3d_test_name, line);
for (i = 0; i < vkd3d_test_state.context_count; ++i)
printf("%s: ", vkd3d_test_state.context[i]);
printf("%s", msg);
}
static void
@ -399,21 +405,25 @@ static inline void vkd3d_test_end_bug(void)
vkd3d_test_state.bug_level >>= 1;
}
static inline void vkd3d_test_set_context(const char *fmt, ...)
static inline void vkd3d_test_push_context(const char *fmt, ...)
{
va_list args;
if (!fmt)
if (vkd3d_test_state.context_count < ARRAY_SIZE(vkd3d_test_state.context))
{
vkd3d_test_state.context[0] = '\0';
return;
}
vkd3d_test_state.context[0] = ':';
va_start(args, fmt);
vsnprintf(&vkd3d_test_state.context[1], sizeof(vkd3d_test_state.context) - 1, fmt, args);
vsnprintf(vkd3d_test_state.context[vkd3d_test_state.context_count],
sizeof(vkd3d_test_state.context), fmt, args);
va_end(args);
vkd3d_test_state.context[sizeof(vkd3d_test_state.context) - 1] = '\0';
vkd3d_test_state.context[vkd3d_test_state.context_count][sizeof(vkd3d_test_state.context[0]) - 1] = '\0';
}
++vkd3d_test_state.context_count;
}
static inline void vkd3d_test_pop_context(void)
{
if (vkd3d_test_state.context_count)
--vkd3d_test_state.context_count;
}
#define run_test(test_pfn) \

File diff suppressed because it is too large Load Diff

View File

@ -351,10 +351,10 @@ static void test_preprocess(void)
for (i = 0; i < ARRAY_SIZE(tests); ++i)
{
vkd3d_test_set_context("Source \"%s\"", tests[i].source);
vkd3d_test_push_context("Source \"%s\"", tests[i].source);
check_preprocess(tests[i].source, NULL, NULL, tests[i].present, tests[i].absent);
vkd3d_test_pop_context();
}
vkd3d_test_set_context(NULL);
macros[0].Name = "KEY";
macros[0].Definition = "value";

View File

@ -780,6 +780,9 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o
if (!ret || line[0] == '[')
{
if (state != STATE_NONE)
vkd3d_test_pop_context();
switch (state)
{
case STATE_INPUT_LAYOUT:
@ -1033,7 +1036,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o
runner->input_element_count = 0;
}
vkd3d_test_set_context("Section %.*s, line %u", strlen(line) - 1, line, line_number);
vkd3d_test_push_context("Section %.*s, line %u", strlen(line) - 1, line, line_number);
}
else if (line[0] != '%' && line[0] != '\n')
{
@ -1082,6 +1085,8 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o
}
}
vkd3d_test_pop_context();
out:
for (i = 0; i < runner->input_element_count; ++i)
free(runner->input_elements[i].name);
@ -1095,8 +1100,6 @@ out:
}
fclose(f);
vkd3d_test_set_context(NULL);
}
#ifdef _WIN32

View File

@ -385,7 +385,7 @@ static void test_dxbc(void)
const struct vkd3d_shader_dxbc_section_desc *section = &dxbc_desc.sections[i];
const uint8_t *data = section->data.code;
vkd3d_test_set_context("Section %u", i);
vkd3d_test_push_context("Section %u", i);
ok(section->tag == sections[i].tag, "Got unexpected tag 0x%08x, expected 0x%08x.\n",
section->tag, sections[i].tag);
ok(section->data.size == sections[i].data.size, "Got unexpected size %zu, expected %zu.\n",
@ -394,8 +394,8 @@ static void test_dxbc(void)
ok(data > dxbc_start && data <= dxbc_end - section->data.size,
"Data {%p, %zu} is not contained within blob {%p, %zu}.\n",
data, section->data.size, dxbc_start, dxbc_end - dxbc_start);
vkd3d_test_pop_context();
}
vkd3d_test_set_context(NULL);
pfn_vkd3d_shader_free_dxbc(&dxbc_desc);
vkd3d_shader_free_shader_code(&dxbc);