[compiler-rt] f50b87e - [NFC][sanitizer] Fix android bot after D102815
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri May 21 14:08:16 PDT 2021
Author: Vitaly Buka
Date: 2021-05-21T14:08:04-07:00
New Revision: f50b87e9ef42efe80e2b3364df848d102075dd11
URL: https://github.com/llvm/llvm-project/commit/f50b87e9ef42efe80e2b3364df848d102075dd11
DIFF: https://github.com/llvm/llvm-project/commit/f50b87e9ef42efe80e2b3364df848d102075dd11.diff
LOG: [NFC][sanitizer] Fix android bot after D102815
https://lab.llvm.org/buildbot/#/builders/77/builds/6519
Added:
Modified:
compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
index 750966a051f05..632b84f7f2078 100644
--- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
@@ -54,6 +54,7 @@ endforeach()
set(SANITIZER_TEST_CFLAGS_COMMON
${COMPILER_RT_UNITTEST_CFLAGS}
${COMPILER_RT_GTEST_CFLAGS}
+ ${COMPILER_RT_GMOCK_CFLAGS}
-I${COMPILER_RT_SOURCE_DIR}/include
-I${COMPILER_RT_SOURCE_DIR}/lib
-I${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common
@@ -151,7 +152,7 @@ macro(add_sanitizer_tests_for_arch arch)
generate_compiler_rt_tests(SANITIZER_TEST_OBJECTS SanitizerUnitTests
"Sanitizer-${arch}-Test" ${arch}
RUNTIME "${SANITIZER_COMMON_LIB}"
- SOURCES ${SANITIZER_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE}
+ SOURCES ${SANITIZER_UNITTESTS} ${COMPILER_RT_GTEST_SOURCE} ${COMPILER_RT_GMOCK_SOURCE}
COMPILE_DEPS ${SANITIZER_TEST_HEADERS}
DEPS gtest
CFLAGS ${SANITIZER_TEST_CFLAGS_COMMON} ${extra_flags}
@@ -208,6 +209,7 @@ if(ANDROID)
add_executable(SanitizerTest
${SANITIZER_UNITTESTS}
${COMPILER_RT_GTEST_SOURCE}
+ ${COMPILER_RT_GMOCK_SOURCE}
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>)
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
index cdf8a80657a8d..1f216ffcab94e 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stacktrace_test.cpp
@@ -14,8 +14,16 @@
#include <string.h>
+#include <algorithm>
+#include <string>
+
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "sanitizer_common/sanitizer_common.h"
+#include "sanitizer_internal_defs.h"
+
+using testing::ContainsRegex;
+using testing::MatchesRegex;
namespace __sanitizer {
@@ -185,32 +193,9 @@ TEST_F(StackPrintTest, SKIP_ON_SPARC(ContainsFullTrace)) {
char buf[3000];
uptr len = trace.PrintTo(buf, sizeof(buf));
-
- // This is the no-truncation case.
- ASSERT_LT(len, sizeof(buf));
-
- // Printed contents should always end with an empty line, unless truncated.
- EXPECT_EQ(buf[len - 2], '\n');
- EXPECT_EQ(buf[len - 1], '\n');
- EXPECT_EQ(buf[len], '\0');
-
- // Buffer contents are delimited by newlines, by default.
- char *saveptr;
- char *line = strtok_r(buf, "\n", &saveptr);
-
- // Checks buffer contents line-by-line.
- for (u32 i = 0; i < trace.size; ++i) {
- char traceline[100];
-
- // Should be synced with the stack trace format, set above.
- snprintf(traceline, sizeof(traceline) - 1, "#%u 0x%lx", i,
- trace.trace[i] - 1);
-
- EXPECT_STREQ(line, traceline);
- line = strtok_r(NULL, "\n", &saveptr);
- }
-
- EXPECT_EQ(line, nullptr);
+ EXPECT_THAT(std::string(buf),
+ MatchesRegex("(#[0-9]+ 0x[0-9a-f]+\n){" +
+ std::to_string(trace.size) + "}\n"));
}
TEST_F(StackPrintTest, SKIP_ON_SPARC(TruncatesContents)) {
More information about the llvm-commits
mailing list