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
-- v3: tests: Print the failing line numbers when a test fails.
From: Henri Verbeet hverbeet@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 9b373e017..bac3a8f26 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -1130,6 +1130,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) @@ -1143,12 +1144,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] == '[') { @@ -1298,9 +1306,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; } @@ -1443,8 +1448,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') { @@ -1499,6 +1502,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);
On Mon Dec 11 10:54:07 2023 +0000, Giovanni Mascellani wrote:
Yeah, one fallout of this change is that actions that happen at the end of a section (i.e. most prominently code compilation, but also setting resources) get the line number of the starting of the following section, which can be confusing. It shouldn't be too hard to fix that, though: I just need to delay `vkd3d_test_push_context()` a little bit an push another context for the `if (!ret || line[0] == '[')` block in `shader_runner.c`.
OK, and this is because the code is *compiled* in `compile_shader`, but it's only checked for validity in the `STATE_PREPROC`? So it's showing the line where the preprocessing is done even though it "should" be showing the line where the compiling is done?
This merge request was approved by Henri Verbeet.