From 7948916d24aa8248a1d13fffe9893e6befc6b787 Mon Sep 17 00:00:00 2001 From: Ole Strohm Date: Thu, 5 Mar 2026 14:33:15 +0000 Subject: [PATCH] Make CL_CONFORMANCE_RESULTS_FILENAME Bazel-aware Bazel requires that test outputs are put in a specific directory given by $TEST_UNDECLARED_OUTPUTS_DIR when running a test through Bazel test This patch checks for the environment variable $BAZEL_TEST, which Bazel sets when running tests, and prepends the specified directory to the user-provided path. The behaviour when running outside of a bazel test environment is unchanged --- test_common/harness/testHarness.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/test_common/harness/testHarness.cpp b/test_common/harness/testHarness.cpp index 301b86d002..09c57e4053 100644 --- a/test_common/harness/testHarness.cpp +++ b/test_common/harness/testHarness.cpp @@ -14,6 +14,7 @@ // limitations under the License. // #include "testHarness.h" +#include "stringHelpers.h" #include "compat.h" #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -33,6 +35,8 @@ #include "imageHelpers.h" #include "parseParameters.h" +namespace fs = std::filesystem; + #if !defined(_WIN32) #include #include @@ -95,11 +99,25 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], return EXIT_SUCCESS; } - FILE *file = fopen(fileName, "w"); + fs::path file_path(fileName); + + // When running under Bazel test, prepend the Bazel output directory to + // the provided path + if (nullptr != getenv("BAZEL_TEST")) + { + char *bazel_output_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); + if (nullptr != bazel_output_dir) + { + file_path = fs::path(bazel_output_dir) / file_path; + } + } + + auto file_path_str = to_string(file_path.u8string()); + FILE *file = fopen(file_path_str.c_str(), "w"); if (NULL == file) { log_error("ERROR: Failed to open '%s' for writing results.\n", - fileName); + file_path_str.c_str()); return EXIT_FAILURE; } @@ -128,7 +146,8 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], int ret = fclose(file) ? EXIT_FAILURE : EXIT_SUCCESS; - log_info("Saving results to %s: %s!\n", fileName, save_map[ret]); + log_info("Saving results to %s: %s!\n", file_path_str.c_str(), + save_map[ret]); return ret; } @@ -309,6 +328,8 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, "CL_CONFORMANCE_RESULTS_FILENAME (currently '%s')\n", fileName != NULL ? fileName : ""); log_info("\t to save results to JSON file.\n"); + log_info("\t When running in Bazel test this is relative to " + "$TEST_UNDECLARED_OUTPUTS_DIR.\n"); log_info("\n"); log_info("Test names:\n");