diff options
author | Mostyn Bramley-Moore <mostynb@vewd.com> | 2017-12-07 04:13:21 +0900 |
---|---|---|
committer | Qijiang Fan <fqj@google.com> | 2020-06-05 07:58:53 +0900 |
commit | cd7f8276158a0de1af8fd10ca2dd36a897a19341 (patch) | |
tree | becd5a653a99ff04592f38783a7de5257fefbc04 | |
parent | 9fad780d78005e0c767b0aef6d86dfa82856496b (diff) | |
download | libchrome-cd7f8276158a0de1af8fd10ca2dd36a897a19341.tar.gz |
remove valgrind checks from //base
We have not supported valgrind for some time (it was never ported to
the GN build IIUC, and has been obsoleted by ASan/MSan/TSan).
BUG=791518,431702
Change-Id: Ibfad450ee2973cf5916986559f543aced08e108a
Reviewed-on: https://chromium-review.googlesource.com/805894
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Mostyn Bramley-Moore <mostynb@vewd.com>
Cr-Commit-Position: refs/heads/master@{#522154}
CrOS-Libchrome-Original-Commit: d0ecd6a5404c1f7b2b3b9ed0d6bad66fdbceb529
-rw-r--r-- | base/command_line.h | 2 | ||||
-rw-r--r-- | base/debug/proc_maps_linux_unittest.cc | 25 | ||||
-rw-r--r-- | base/message_loop/message_loop_io_posix_unittest.cc | 1 | ||||
-rw-r--r-- | base/metrics/field_trial_unittest.cc | 3 | ||||
-rw-r--r-- | base/observer_list_unittest.cc | 6 | ||||
-rw-r--r-- | base/process/launch.h | 4 | ||||
-rw-r--r-- | base/process/launch_posix.cc | 31 | ||||
-rw-r--r-- | base/process/process_posix.cc | 8 | ||||
-rw-r--r-- | base/process/process_util_unittest.cc | 17 | ||||
-rw-r--r-- | base/security_unittest.cc | 13 | ||||
-rw-r--r-- | base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java | 3 | ||||
-rw-r--r-- | base/test/test_timeouts.h | 2 | ||||
-rw-r--r-- | base/tools_sanity_unittest.cc | 46 |
13 files changed, 43 insertions, 118 deletions
diff --git a/base/command_line.h b/base/command_line.h index 31b22d6b9a..893e7b766d 100644 --- a/base/command_line.h +++ b/base/command_line.h @@ -204,7 +204,7 @@ class BASE_EXPORT CommandLine { void AppendArguments(const CommandLine& other, bool include_program); // Insert a command before the current command. - // Common for debuggers, like "valgrind" or "gdb --args". + // Common for debuggers, like "gdb --args". void PrependWrapper(const StringType& wrapper); #if defined(OS_WIN) diff --git a/base/debug/proc_maps_linux_unittest.cc b/base/debug/proc_maps_linux_unittest.cc index 9b5bcaca0e..7abf152b0e 100644 --- a/base/debug/proc_maps_linux_unittest.cc +++ b/base/debug/proc_maps_linux_unittest.cc @@ -10,7 +10,6 @@ #include "base/macros.h" #include "base/path_service.h" #include "base/strings/stringprintf.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/platform_thread.h" #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" @@ -210,23 +209,7 @@ void CheckProcMapsRegions(const std::vector<MappedMemoryRegion> ®ions) { found_exe = true; } - // Valgrind uses its own allocated stacks instead of the kernel-provided - // stack without letting the kernel know via prctl(PR_SET_MM_START_STACK). - // Depending on which kernel you're running it'll impact the output of - // /proc/self/maps. - // - // Prior to version 3.4, the kernel completely ignores other stacks and - // always prints out the vma lying within mm->start_stack as [stack] even - // if the program was currently executing on a different stack. - // - // Starting in 3.4, the kernel will print out the vma containing the current - // stack pointer as [stack:TID] as long as that vma does not lie within - // mm->start_stack. - // - // Because this has gotten too complicated and brittle of a test, completely - // ignore checking for the stack and address when running under Valgrind. - // See http://crbug.com/431702 for more details. - if (!RunningOnValgrind() && regions[i].path == "[stack]") { + if (regions[i].path == "[stack]") { // On Android the test is run on a background thread, since [stack] is for // the main thread, we cannot test this. #if !defined(OS_ANDROID) @@ -248,10 +231,8 @@ void CheckProcMapsRegions(const std::vector<MappedMemoryRegion> ®ions) { } EXPECT_TRUE(found_exe); - if (!RunningOnValgrind()) { - EXPECT_TRUE(found_stack); - EXPECT_TRUE(found_address); - } + EXPECT_TRUE(found_stack); + EXPECT_TRUE(found_address); } TEST(ProcMapsTest, ReadProcMaps) { diff --git a/base/message_loop/message_loop_io_posix_unittest.cc b/base/message_loop/message_loop_io_posix_unittest.cc index f98d4668d3..89962a3efc 100644 --- a/base/message_loop/message_loop_io_posix_unittest.cc +++ b/base/message_loop/message_loop_io_posix_unittest.cc @@ -145,7 +145,6 @@ TEST_F(MessageLoopForIoPosixTest, FileDescriptorWatcherOutlivesMessageLoop) { TEST_F(MessageLoopForIoPosixTest, FileDescriptorWatcherDoubleStop) { // Verify that it's ok to call StopWatchingFileDescriptor(). - // (Errors only showed up in valgrind.) // Arrange for message loop to live longer than watcher. MessageLoopForIO message_loop; diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc index 42c3ba1e43..3c1be9f298 100644 --- a/base/metrics/field_trial_unittest.cc +++ b/base/metrics/field_trial_unittest.cc @@ -86,8 +86,7 @@ class FieldTrialTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); }; -// Test registration, and also check that destructors are called for trials -// (and that Valgrind doesn't catch us leaking). +// Test registration, and also check that destructors are called for trials. TEST_F(FieldTrialTest, Registration) { const char name1[] = "name 1 test"; const char name2[] = "name 2 test"; diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc index fd88a2d5e8..41bcf2ceb2 100644 --- a/base/observer_list_unittest.cc +++ b/base/observer_list_unittest.cc @@ -891,8 +891,10 @@ TEST(ObserverListTest, IteratorOutlivesList) { for (auto& observer : *observer_list) observer.Observe(0); - // If this test fails, there'll be Valgrind errors when this function goes out - // of scope. + + // There are no EXPECT* statements for this test, if we catch + // use-after-free errors for observer_list (eg with ASan) then + // this test has failed. See http://crbug.com/85296. } TEST(ObserverListTest, BasicStdIterator) { diff --git a/base/process/launch.h b/base/process/launch.h index 2e06c4c386..1d99dc2816 100644 --- a/base/process/launch.h +++ b/base/process/launch.h @@ -364,9 +364,7 @@ BASE_EXPORT LaunchOptions LaunchOptionsForTest(); // // This function uses the libc clone wrapper (which updates libc's pid cache) // internally, so callers may expect things like getpid() to work correctly -// after in both the child and parent. An exception is when this code is run -// under Valgrind. Valgrind does not support the libc clone wrapper, so the libc -// pid cache may be incorrect after this function is called under Valgrind. +// after in both the child and parent. // // As with fork(), callers should be extremely careful when calling this while // multiple threads are running, since at the time the fork happened, the diff --git a/base/process/launch_posix.cc b/base/process/launch_posix.cc index 148ad4f54c..90c2d830db 100644 --- a/base/process/launch_posix.cc +++ b/base/process/launch_posix.cc @@ -38,8 +38,6 @@ #include "base/process/process_metrics.h" #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" -#include "base/third_party/valgrind/valgrind.h" #include "base/threading/platform_thread.h" #include "base/threading/thread_restrictions.h" #include "build/build_config.h" @@ -287,14 +285,8 @@ void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) { if (fd == dir_fd) continue; - // When running under Valgrind, Valgrind opens several FDs for its - // own use and will complain if we try to close them. All of - // these FDs are >= |max_fds|, so we can check against that here - // before closing. See https://bugs.kde.org/show_bug.cgi?id=191758 - if (fd < static_cast<int>(max_fds)) { - int ret = IGNORE_EINTR(close(fd)); - DPCHECK(ret == 0); - } + int ret = IGNORE_EINTR(close(fd)); + DPCHECK(ret == 0); } } @@ -751,25 +743,6 @@ pid_t ForkWithFlags(unsigned long flags, pid_t* ptid, pid_t* ctid) { RAW_LOG(FATAL, "Invalid usage of ForkWithFlags"); } - // Valgrind's clone implementation does not support specifiying a child_stack - // without CLONE_VM, so we cannot use libc's clone wrapper when running under - // Valgrind. As a result, the libc pid cache may be incorrect under Valgrind. - // See crbug.com/442817 for more details. - if (RunningOnValgrind()) { - // See kernel/fork.c in Linux. There is different ordering of sys_clone - // parameters depending on CONFIG_CLONE_BACKWARDS* configuration options. -#if defined(ARCH_CPU_X86_64) - return syscall(__NR_clone, flags, nullptr, ptid, ctid, nullptr); -#elif defined(ARCH_CPU_X86) || defined(ARCH_CPU_ARM_FAMILY) || \ - defined(ARCH_CPU_MIPS_FAMILY) || defined(ARCH_CPU_S390_FAMILY) || \ - defined(ARCH_CPU_PPC64_FAMILY) - // CONFIG_CLONE_BACKWARDS defined. - return syscall(__NR_clone, flags, nullptr, ptid, nullptr, ctid); -#else -#error "Unsupported architecture" -#endif - } - jmp_buf env; if (setjmp(env) == 0) { return CloneAndLongjmpInChild(flags, ptid, ctid, &env); diff --git a/base/process/process_posix.cc b/base/process/process_posix.cc index 2481e26ba1..3e63cd069d 100644 --- a/base/process/process_posix.cc +++ b/base/process/process_posix.cc @@ -15,7 +15,6 @@ #include "base/logging.h" #include "base/posix/eintr_wrapper.h" #include "base/process/kill.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/thread_restrictions.h" #include "build/build_config.h" @@ -315,13 +314,6 @@ bool Process::Terminate(int exit_code, bool wait) const { bool result = kill(process_, SIGTERM) == 0; if (result && wait) { int tries = 60; - - if (RunningOnValgrind()) { - // Wait for some extra time when running under Valgrind since the child - // processes may take some time doing leak checking. - tries *= 2; - } - unsigned sleep_ms = 4; // The process may not end immediately due to pending I/O diff --git a/base/process/process_util_unittest.cc b/base/process/process_util_unittest.cc index 43f2898801..52b27bf208 100644 --- a/base/process/process_util_unittest.cc +++ b/base/process/process_util_unittest.cc @@ -29,7 +29,6 @@ #include "base/synchronization/waitable_event.h" #include "base/test/multiprocess_test.h" #include "base/test/test_timeouts.h" -#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/platform_thread.h" #include "base/threading/thread.h" #include "build/build_config.h" @@ -884,11 +883,8 @@ TEST_F(ProcessUtilTest, LaunchProcess) { #if defined(OS_LINUX) // Test a non-trival value for clone_flags. - // Don't test on Valgrind as it has limited support for clone(). - if (!RunningOnValgrind()) { - EXPECT_EQ("wibble\n", TestLaunchProcess(echo_base_test, env_changes, - no_clear_environ, CLONE_FS)); - } + EXPECT_EQ("wibble\n", TestLaunchProcess(echo_base_test, env_changes, + no_clear_environ, CLONE_FS)); EXPECT_EQ( "BASE_TEST=wibble\n", @@ -1087,8 +1083,7 @@ MULTIPROCESS_TEST_MAIN(CheckPidProcess) { #if defined(CLONE_NEWUSER) && defined(CLONE_NEWPID) TEST_F(ProcessUtilTest, CloneFlags) { - if (RunningOnValgrind() || - !base::PathExists(FilePath("/proc/self/ns/user")) || + if (!base::PathExists(FilePath("/proc/self/ns/user")) || !base::PathExists(FilePath("/proc/self/ns/pid"))) { // User or PID namespaces are not supported. return; @@ -1107,12 +1102,6 @@ TEST_F(ProcessUtilTest, CloneFlags) { #endif // defined(CLONE_NEWUSER) && defined(CLONE_NEWPID) TEST(ForkWithFlagsTest, UpdatesPidCache) { - // The libc clone function, which allows ForkWithFlags to keep the pid cache - // up to date, does not work on Valgrind. - if (RunningOnValgrind()) { - return; - } - // Warm up the libc pid cache, if there is one. ASSERT_EQ(syscall(__NR_getpid), getpid()); diff --git a/base/security_unittest.cc b/base/security_unittest.cc index a41607c857..8d292211b8 100644 --- a/base/security_unittest.cc +++ b/base/security_unittest.cc @@ -54,17 +54,6 @@ NOINLINE Type HideValueFromCompiler(volatile Type value) { #define MALLOC_OVERFLOW_TEST(function) DISABLED_##function #endif -#if defined(OS_LINUX) && defined(__x86_64__) -// Detect runtime TCMalloc bypasses. -bool IsTcMallocBypassed() { - // This should detect a TCMalloc bypass from Valgrind. - char* g_slice = getenv("G_SLICE"); - if (g_slice && !strcmp(g_slice, "always-malloc")) - return true; - return false; -} -#endif - // There are platforms where these tests are known to fail. We would like to // be able to easily check the status on the bots, but marking tests as // FAILS_ is too clunky. @@ -133,8 +122,6 @@ bool ArePointersToSameArea(void* ptr1, void* ptr2, size_t size) { // Check if TCMalloc uses an underlying random memory allocator. TEST(SecurityTest, MALLOC_OVERFLOW_TEST(RandomMemoryAllocations)) { - if (IsTcMallocBypassed()) - return; size_t kPageSize = 4096; // We support x86_64 only. // Check that malloc() returns an address that is neither the kernel's // un-hinted mmap area, nor the current brk() area. The first malloc() may diff --git a/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java b/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java index 98e12adb8d..7a815c09a4 100644 --- a/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java +++ b/base/test/android/javatests/src/org/chromium/base/test/util/ScalableTimeout.java @@ -6,7 +6,8 @@ package org.chromium.base.test.util; /** * Utility class for scaling various timeouts by a common factor. - * For example, to run tests under Valgrind, you might want the following: + * For example, to run tests under slow memory tools, you might do + * something like this: * adb shell "echo 20.0 > /data/local/tmp/chrome_timeout_scale" */ public class ScalableTimeout { diff --git a/base/test/test_timeouts.h b/base/test/test_timeouts.h index 9d42eb91fe..a75a17ccbd 100644 --- a/base/test/test_timeouts.h +++ b/base/test/test_timeouts.h @@ -10,7 +10,7 @@ #include "base/time/time.h" // Returns common timeouts to use in tests. Makes it possible to adjust -// the timeouts for different environments (like Valgrind). +// the timeouts for different environments (like TSan). class TestTimeouts { public: // Argument that can be passed on the command line to indicate "no timeout". diff --git a/base/tools_sanity_unittest.cc b/base/tools_sanity_unittest.cc index 5c41bd74f2..a01d07bd82 100644 --- a/base/tools_sanity_unittest.cc +++ b/base/tools_sanity_unittest.cc @@ -41,14 +41,15 @@ if (debug::IsBinaryInstrumented()) { EXPECT_DEATH(action, \ #define HARMFUL_ACCESS(action,error_regexp) EXPECT_DEATH(action,error_regexp) #endif // !OS_IOS && !SYZYASAN #else -#define HARMFUL_ACCESS(action,error_regexp) \ -do { if (RunningOnValgrind()) { action; } } while (0) +#define HARMFUL_ACCESS(action, error_regexp) +#define HARMFUL_ACCESS_IS_NOOP #endif void DoReadUninitializedValue(char *ptr) { // Comparison with 64 is to prevent clang from optimizing away the // jump -- valgrind only catches jumps and conditional moves, but clang uses - // the borrow flag if the condition is just `*ptr == '\0'`. + // the borrow flag if the condition is just `*ptr == '\0'`. We no longer + // support valgrind, but this constant should be fine to keep as-is. if (*ptr == 64) { VLOG(1) << "Uninit condition is true"; } else { @@ -65,6 +66,7 @@ void ReadUninitializedValue(char *ptr) { #endif } +#ifndef HARMFUL_ACCESS_IS_NOOP void ReadValueOutOfArrayBoundsLeft(char *ptr) { char c = ptr[-2]; VLOG(1) << "Reading a byte out of bounds: " << c; @@ -75,15 +77,14 @@ void ReadValueOutOfArrayBoundsRight(char *ptr, size_t size) { VLOG(1) << "Reading a byte out of bounds: " << c; } -// This is harmless if you run it under Valgrind thanks to redzones. void WriteValueOutOfArrayBoundsLeft(char *ptr) { ptr[-1] = kMagicValue; } -// This is harmless if you run it under Valgrind thanks to redzones. void WriteValueOutOfArrayBoundsRight(char *ptr, size_t size) { ptr[size] = kMagicValue; } +#endif // HARMFUL_ACCESS_IS_NOOP void MakeSomeErrors(char *ptr, size_t size) { ReadUninitializedValue(ptr); @@ -149,44 +150,37 @@ TEST(ToolsSanityTest, MAYBE_AccessesToMallocMemory) { HARMFUL_ACCESS(foo[5] = 0, "heap-use-after-free"); } +#if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) + static int* allocateArray() { // Clang warns about the mismatched new[]/delete if they occur in the same // function. return new int[10]; } +// This test may corrupt memory if not compiled with AddressSanitizer. TEST(ToolsSanityTest, MAYBE_ArrayDeletedWithoutBraces) { -#if !defined(ADDRESS_SANITIZER) && !defined(SYZYASAN) - // This test may corrupt memory if not run under Valgrind or compiled with - // AddressSanitizer. - if (!RunningOnValgrind()) - return; -#endif - // Without the |volatile|, clang optimizes away the next two lines. int* volatile foo = allocateArray(); delete foo; } +#endif +#if defined(ADDRESS_SANITIZER) static int* allocateScalar() { // Clang warns about the mismatched new/delete[] if they occur in the same // function. return new int; } +// This test may corrupt memory if not compiled with AddressSanitizer. TEST(ToolsSanityTest, MAYBE_SingleElementDeletedWithBraces) { -#if !defined(ADDRESS_SANITIZER) - // This test may corrupt memory if not run under Valgrind or compiled with - // AddressSanitizer. - if (!RunningOnValgrind()) - return; -#endif - // Without the |volatile|, clang optimizes away the next two lines. int* volatile foo = allocateScalar(); (void) foo; delete [] foo; } +#endif #if defined(ADDRESS_SANITIZER) || defined(SYZYASAN) @@ -221,6 +215,7 @@ TEST(ToolsSanityTest, DISABLED_AddressSanitizerGlobalOOBCrashTest) { *access = 43; } +#ifndef HARMFUL_ACCESS_IS_NOOP TEST(ToolsSanityTest, AsanHeapOverflow) { HARMFUL_ACCESS(debug::AsanHeapOverflow() ,"to the right"); } @@ -233,7 +228,7 @@ TEST(ToolsSanityTest, AsanHeapUseAfterFree) { HARMFUL_ACCESS(debug::AsanHeapUseAfterFree(), "heap-use-after-free"); } -#if defined(SYZYASAN) +#if defined(SYZYASAN) && defined(COMPILER_MSVC) TEST(ToolsSanityTest, AsanCorruptHeapBlock) { HARMFUL_ACCESS(debug::AsanCorruptHeapBlock(), ""); } @@ -243,7 +238,8 @@ TEST(ToolsSanityTest, AsanCorruptHeap) { // particular string to look for in the stack trace. EXPECT_DEATH(debug::AsanCorruptHeap(), ""); } -#endif // SYZYASAN +#endif // SYZYASAN && COMPILER_MSVC +#endif // !HARMFUL_ACCESS_IS_NOOP #endif // ADDRESS_SANITIZER || SYZYASAN @@ -423,4 +419,12 @@ TEST(ToolsSanityTest, BadUnrelatedCast) { #endif // CFI_ERROR_MSG +#undef CFI_ERROR_MSG +#undef MAYBE_AccessesToNewMemory +#undef MAYBE_AccessesToMallocMemory +#undef MAYBE_ArrayDeletedWithoutBraces +#undef MAYBE_SingleElementDeletedWithBraces +#undef HARMFUL_ACCESS +#undef HARMFUL_ACCESS_IS_NOOP + } // namespace base |