Fix MemtagNoteTest and make it runnable on non-MTE devices.
Update the path to the helper binary, and run the test on non-MTE
hardware with the expectation that the bug is not detected.
Test: bionic-unit-tests
Bug: none
Change-Id: I34eb4dc46d0bacd83824d307398f7891d4806686
diff --git a/tests/heap_tagging_level_test.cpp b/tests/heap_tagging_level_test.cpp
index edbd995..cfb2490 100644
--- a/tests/heap_tagging_level_test.cpp
+++ b/tests/heap_tagging_level_test.cpp
@@ -197,24 +197,33 @@
TEST_P(MemtagNoteTest, SEGV) {
#if defined(__BIONIC__) && defined(__aarch64__)
- if (!(getauxval(AT_HWCAP2) & HWCAP2_MTE)) {
- GTEST_SKIP() << "requires MTE support";
- }
+ // Note that we do not check running_with_hwasan() - what matters here is whether the test binary
+ // itself is built with HWASan.
+ bool withHWASAN = __has_feature(hwaddress_sanitizer);
+ bool withMTE = getauxval(AT_HWCAP2) & HWCAP2_MTE;
const char* kNoteSuffix[] = {"disabled", "async", "sync"};
- const char* kExpectedOutput[] = {"normal exit\n", "SEGV_MTEAERR\n", "SEGV_MTESERR\n"};
+ const char* kExpectedOutputHWASAN[] = {".*tag-mismatch.*", ".*tag-mismatch.*",
+ ".*tag-mismatch.*"};
+ const char* kExpectedOutputMTE[] = {"normal exit\n", "SEGV_MTEAERR\n", "SEGV_MTESERR\n"};
+ const char* kExpectedOutputNonMTE[] = {"normal exit\n", "normal exit\n", "normal exit\n"};
+ const char** kExpectedOutput =
+ withHWASAN ? kExpectedOutputHWASAN : (withMTE ? kExpectedOutputMTE : kExpectedOutputNonMTE);
+ const int kExpectedExitStatus = withHWASAN ? -SIGABRT : 0;
MemtagNote note = std::get<0>(GetParam());
bool isStatic = std::get<1>(GetParam());
std::string helper_base = std::string("heap_tagging_") + (isStatic ? "static_" : "") +
kNoteSuffix[static_cast<int>(note)] + "_helper";
fprintf(stderr, "=== %s\n", helper_base.c_str());
- std::string helper = GetTestlibRoot() + "/" + helper_base + "/" + helper_base;
+ std::string helper = GetTestlibRoot() + "/" + helper_base;
chmod(helper.c_str(), 0755);
ExecTestHelper eth;
eth.SetArgs({helper.c_str(), nullptr});
- eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, 0,
+ eth.Run([&]() { execve(helper.c_str(), eth.GetArgs(), eth.GetEnv()); }, kExpectedExitStatus,
kExpectedOutput[static_cast<int>(note)]);
+#else
+ GTEST_SKIP() << "bionic/arm64 only";
#endif
}