ART: Add symbolization pass to host gtests
When running under sanitization, add a symbolization pass to gtest
failures. This compensates for the disabled runtime symbolization,
and brings gtest to parity with run-tests.
This pass is only enabled under sanitization as it incurs extra
I/O for a temporary file, and loses the default coloration.
Bug: 31098551
Test: m test-art-host-gtest
Test: m SANITIZE_HOST=address test-art-host-gtest
Change-Id: Id36d907f3ffe9c8480fa5b4af94807d5e6532fda
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 4f5df03..1f210e1 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -451,13 +451,27 @@
ART_TEST_HOST_GTEST_DEPENDENCIES += $$(gtest_deps)
+.PHONY: $$(gtest_rule)
+ifeq (,$(SANITIZE_HOST))
+$$(gtest_rule): $$(gtest_exe) $$(gtest_deps)
+ $(hide) ($$(call ART_TEST_SKIP,$$@) && $$< && \
+ $$(call ART_TEST_PASSED,$$@)) || $$(call ART_TEST_FAILED,$$@)
+else
# Note: envsetup currently exports ASAN_OPTIONS=detect_leaks=0 to suppress leak detection, as some
# build tools (e.g., ninja) intentionally leak. We want leak checks when we run our tests, so
# override ASAN_OPTIONS. b/37751350
-.PHONY: $$(gtest_rule)
+# Note 2: Under sanitization, also capture the output, and run it through the stack tool on failure
+# (with the x86-64 ABI, as this allows symbolization of both x86 and x86-64). We don't do this in
+# general as it loses all the color output, and we have our own symbolization step when not running
+# under ASAN.
$$(gtest_rule): $$(gtest_exe) $$(gtest_deps)
- $(hide) ($$(call ART_TEST_SKIP,$$@) && ASAN_OPTIONS=detect_leaks=1 $$< && \
- $$(call ART_TEST_PASSED,$$@)) || $$(call ART_TEST_FAILED,$$@)
+ $(hide) ($$(call ART_TEST_SKIP,$$@) && set -o pipefail && \
+ ASAN_OPTIONS=detect_leaks=1 $$< 2>&1 | tee $$<.tmp.out >&2 && \
+ { $$(call ART_TEST_PASSED,$$@) ; rm $$<.tmp.out ; }) || \
+ ( grep -q AddressSanitizer $$<.tmp.out && \
+ { echo "ABI: 'x86_64'" | cat - $$<.tmp.out | development/scripts/stack | tail -n 3000 ; } ; \
+ rm $$<.tmp.out ; $$(call ART_TEST_FAILED,$$@))
+endif
ART_TEST_HOST_GTEST$$($(3)ART_PHONY_TEST_HOST_SUFFIX)_RULES += $$(gtest_rule)
ART_TEST_HOST_GTEST_RULES += $$(gtest_rule)