Currently, if a probe fails, it will print the line number of the [test] block the probe is in, not the line number of the probe itself. This makes it somewhat difficult to debug.
This commit makes it print the line number that a test fails at.
This code was actually written by @hverbeet for my first attempt at fixing this, !499.
CC @zfigura
From: Petrichor Park ppark@codeweavers.com
Currently, if a probe fails, it will print the line number of the [test] block the probe is in, not the line number of the probe itself. This makes it somewhat difficult to debug.
This commit makes it print the line number that a test fails at. --- tests/shader_runner.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 0e6104ce3..f94e33094 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -1121,6 +1121,7 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o HRESULT expect_hr = S_OK; bool skip_tests = false; char line_buffer[256]; + const char *testname; FILE *f;
if (!test_options.filename) @@ -1134,12 +1135,19 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o runner->minimum_shader_model = minimum_shader_model; runner->maximum_shader_model = maximum_shader_model;
+ if ((testname = strrchr(test_options.filename, '/'))) + ++testname; + else + testname = test_options.filename; + for (;;) { char *ret = fgets(line_buffer, sizeof(line_buffer), f); const char *line = line_buffer;
- ++line_number; + if (line_number++) + vkd3d_test_pop_context(); + vkd3d_test_push_context("%s:%u", testname, line_number);
if (!ret || line[0] == '[') { @@ -1289,9 +1297,6 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o } }
- if (state != STATE_NONE) - vkd3d_test_pop_context(); - if (!ret) break; } @@ -1432,8 +1437,6 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o free(runner->input_elements[i].name); runner->input_element_count = 0; } - - vkd3d_test_push_context("Section %.*s, line %u", strlen(line_buffer) - 1, line_buffer, line_number); } else if (line[0] != '%' && line[0] != '\n') { @@ -1488,6 +1491,9 @@ void run_shader_tests(struct shader_runner *runner, const struct shader_runner_o } }
+ if (line_number) + vkd3d_test_pop_context(); + for (i = 0; i < runner->input_element_count; ++i) free(runner->input_elements[i].name); free(runner->input_elements);
One thing I have noticed is that if there's shader code that doesn't compile at all, there's not really a helpful message. It says `Test failed: Got unexpected hr 0x80004005.` on a line *after* the code block.
I don't think it's the world's biggest priority because compile errors aren't really what we're testing for here, though.