|
14 | 14 | // limitations under the License. |
15 | 15 | // |
16 | 16 | #include "testHarness.h" |
| 17 | +#include "stringHelpers.h" |
17 | 18 | #include "compat.h" |
18 | 19 | #include <algorithm> |
19 | 20 | #include <stdio.h> |
20 | 21 | #include <stdlib.h> |
21 | 22 | #include <string.h> |
22 | 23 | #include <cassert> |
23 | 24 | #include <deque> |
| 25 | +#include <filesystem> |
24 | 26 | #include <mutex> |
25 | 27 | #include <set> |
26 | 28 | #include <stdexcept> |
|
33 | 35 | #include "imageHelpers.h" |
34 | 36 | #include "parseParameters.h" |
35 | 37 |
|
| 38 | +namespace fs = std::filesystem; |
| 39 | + |
36 | 40 | #if !defined(_WIN32) |
37 | 41 | #include <sys/utsname.h> |
38 | 42 | #include <unistd.h> |
@@ -95,11 +99,25 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], |
95 | 99 | return EXIT_SUCCESS; |
96 | 100 | } |
97 | 101 |
|
98 | | - FILE *file = fopen(fileName, "w"); |
| 102 | + fs::path file_path(fileName); |
| 103 | + |
| 104 | + // When running under Bazel test, prepend the Bazel output directory to |
| 105 | + // the provided path |
| 106 | + if (nullptr != getenv("BAZEL_TEST")) |
| 107 | + { |
| 108 | + char *bazel_output_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); |
| 109 | + if (nullptr != bazel_output_dir) |
| 110 | + { |
| 111 | + file_path = fs::path(bazel_output_dir) / file_path; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + auto file_path_str = to_string(file_path.u8string()); |
| 116 | + FILE *file = fopen(file_path_str.c_str(), "w"); |
99 | 117 | if (NULL == file) |
100 | 118 | { |
101 | 119 | log_error("ERROR: Failed to open '%s' for writing results.\n", |
102 | | - fileName); |
| 120 | + file_path_str.c_str()); |
103 | 121 | return EXIT_FAILURE; |
104 | 122 | } |
105 | 123 |
|
@@ -128,7 +146,8 @@ static int saveResultsToJson(const char *suiteName, test_definition testList[], |
128 | 146 |
|
129 | 147 | int ret = fclose(file) ? EXIT_FAILURE : EXIT_SUCCESS; |
130 | 148 |
|
131 | | - log_info("Saving results to %s: %s!\n", fileName, save_map[ret]); |
| 149 | + log_info("Saving results to %s: %s!\n", file_path_str.c_str(), |
| 150 | + save_map[ret]); |
132 | 151 |
|
133 | 152 | return ret; |
134 | 153 | } |
@@ -309,6 +328,8 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum, |
309 | 328 | "CL_CONFORMANCE_RESULTS_FILENAME (currently '%s')\n", |
310 | 329 | fileName != NULL ? fileName : "<undefined>"); |
311 | 330 | log_info("\t to save results to JSON file.\n"); |
| 331 | + log_info("\t When running in Bazel test this is relative to " |
| 332 | + "$TEST_UNDECLARED_OUTPUTS_DIR.\n"); |
312 | 333 |
|
313 | 334 | log_info("\n"); |
314 | 335 | log_info("Test names:\n"); |
|
0 commit comments