From 9aac700d028c35efacc00afdb8ff6ded15535a9b Mon Sep 17 00:00:00 2001 From: Brian Atkinson Date: Wed, 19 Feb 2020 18:20:38 -0800 Subject: [PATCH] Use GetTestUndeclaredOutputsDir to access TEST_UNDECLARED_OUTPUTS_DIR. On Windows, Bazel populates environment variables with `/`s only. Changing path manipulation logic to use `\` properly on Windows will conflict with this behavior, requiring a layer of indirection to deal with Bazel. PiperOrigin-RevId: 296104352 Change-Id: Ibaa19d0c4d231a15811232c63bcefc9d4931f88b --- tensorflow/compiler/xla/tests/literal_test_util.cc | 6 ++---- tensorflow/compiler/xla/tests/literal_test_util_test.cc | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tensorflow/compiler/xla/tests/literal_test_util.cc b/tensorflow/compiler/xla/tests/literal_test_util.cc index 4dd59cdca5d..bb82193ae33 100644 --- a/tensorflow/compiler/xla/tests/literal_test_util.cc +++ b/tensorflow/compiler/xla/tests/literal_test_util.cc @@ -18,6 +18,7 @@ limitations under the License. #include "absl/strings/str_format.h" #include "tensorflow/compiler/xla/literal_comparison.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/platform/path.h" #include "tensorflow/core/platform/test.h" namespace xla { @@ -30,10 +31,7 @@ void WriteLiteralToTempFile(const LiteralSlice& literal, const string& name) { // TEST_UNDECLARED_OUTPUTS_DIR. This plays well with tools that inspect test // results, especially when they're run on remote machines. string outdir; - const char* undeclared_outputs_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); - if (undeclared_outputs_dir != nullptr) { - outdir = undeclared_outputs_dir; - } else { + if (!tensorflow::io::GetTestUndeclaredOutputsDir(&outdir)) { outdir = tensorflow::testing::TmpDir(); } diff --git a/tensorflow/compiler/xla/tests/literal_test_util_test.cc b/tensorflow/compiler/xla/tests/literal_test_util_test.cc index 66373af5686..e2ad5a7e08f 100644 --- a/tensorflow/compiler/xla/tests/literal_test_util_test.cc +++ b/tensorflow/compiler/xla/tests/literal_test_util_test.cc @@ -25,6 +25,7 @@ limitations under the License. #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/logging.h" +#include "tensorflow/core/platform/path.h" #include "tensorflow/core/platform/test.h" namespace xla { @@ -129,10 +130,7 @@ TEST(LiteralTestUtilTest, ExpectNearFailurePlacesResultsInTemporaryDirectory) { tensorflow::Env* env = tensorflow::Env::Default(); string outdir; - const char* undeclared_outputs_dir = getenv("TEST_UNDECLARED_OUTPUTS_DIR"); - if (undeclared_outputs_dir != nullptr) { - outdir = undeclared_outputs_dir; - } else { + if (!tensorflow::io::GetTestUndeclaredOutputsDir(&outdir)) { outdir = tensorflow::testing::TmpDir(); } string pattern = tensorflow::io::JoinPath(outdir, "tempfile-*.pb");