Set sharding and tmpdir environment variables for googletest
The patch for googletest to prefer GTEST_TMP_DIR is
google/googletest#619 and should be merged soon.
--
Change-Id: If48220e8e1e4e78a8768aeb14b5b58e4f246c8c3
Reviewed-on: https://bazel-review.googlesource.com/#/c/2170/
MOS_MIGRATED_REVID=106043714
diff --git a/src/test/cpp/util/BUILD b/src/test/cpp/util/BUILD
index e59029c..e47f35e 100644
--- a/src/test/cpp/util/BUILD
+++ b/src/test/cpp/util/BUILD
@@ -24,6 +24,7 @@
cc_test(
name = "strings_test",
srcs = ["strings_test.cc"],
+ shard_count = 2,
deps = [
"//src/main/cpp/util:strings",
"//third_party:gtest",
diff --git a/third_party/BUILD b/third_party/BUILD
index 98a7181..91a4506 100644
--- a/third_party/BUILD
+++ b/third_party/BUILD
@@ -349,6 +349,9 @@
hdrs = [
"gtest/gtest.h",
],
+ data = [
+ "//tools:test_sharding_compliant",
+ ],
includes = ["."],
# gtest detects pthread, and the linker fails without it.
linkopts = ["-lpthread"],
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh
index 49b56e6..6264110 100755
--- a/tools/test/test-setup.sh
+++ b/tools/test/test-setup.sh
@@ -20,6 +20,13 @@
# Executing the test log will page it.
echo 'exec ${PAGER:-/usr/bin/less} "$0" || exit 1'
+# Tell googletest about Bazel sharding.
+if [[ -n "${TEST_TOTAL_SHARDS+x}" ]] && ((TEST_TOTAL_SHARDS != 0)); then
+ export GTEST_SHARD_INDEX="${TEST_SHARD_INDEX}"
+ export GTEST_TOTAL_SHARDS="${TEST_TOTAL_SHARDS}"
+fi
+export GTEST_TMP_DIR="${TEST_TMPDIR}"
+
DIR="$TEST_SRCDIR"
if [ ! -z "$TEST_WORKSPACE" ]