[compiler-rt] r182730 - [lsan] Begin converting LSan tests to output tests.

Sergey Matveev earthdok at google.com
Mon May 27 04:41:46 PDT 2013


Author: smatveev
Date: Mon May 27 06:41:46 2013
New Revision: 182730

URL: http://llvm.org/viewvc/llvm-project?rev=182730&view=rev
Log:
[lsan] Begin converting LSan tests to output tests.

In this CL all old tests are removed and one LIT test is added.

Added:
    compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/
    compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/lit.local.cfg
    compiler-rt/trunk/lib/lsan/lit_tests/use_globals_initialized.cc
    compiler-rt/trunk/lib/lsan/tests/lsan_dummy_unittest.cc
Removed:
    compiler-rt/trunk/lib/lsan/tests/lsan_test.cc
    compiler-rt/trunk/lib/lsan/tests/lsan_tls_loadable.cc
Modified:
    compiler-rt/trunk/lib/asan/asan_allocator2.cc
    compiler-rt/trunk/lib/lsan/lit_tests/lit.cfg
    compiler-rt/trunk/lib/lsan/lsan_allocator.cc
    compiler-rt/trunk/lib/lsan/lsan_common.cc
    compiler-rt/trunk/lib/lsan/lsan_common.h
    compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
    compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh

Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Mon May 27 06:41:46 2013
@@ -775,7 +775,6 @@ template void ForEachChunk<PrintLeakedCb
 template void ForEachChunk<CollectLeaksCb>(CollectLeaksCb const &callback);
 template void ForEachChunk<MarkIndirectlyLeakedCb>(
     MarkIndirectlyLeakedCb const &callback);
-template void ForEachChunk<ReportLeakedCb>(ReportLeakedCb const &callback);
 template void ForEachChunk<ClearTagCb>(ClearTagCb const &callback);
 #endif  // CAN_SANITIZE_LEAKS
 }  // namespace __lsan

Added: compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/lit.local.cfg?rev=182730&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/lit.local.cfg (added)
+++ compiler-rt/trunk/lib/lsan/lit_tests/SharedLibs/lit.local.cfg Mon May 27 06:41:46 2013
@@ -0,0 +1,4 @@
+# Sources in this directory are compiled as shared libraries and used by
+# tests in parent directory.
+
+config.suffixes = []

Modified: compiler-rt/trunk/lib/lsan/lit_tests/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lit_tests/lit.cfg?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lit_tests/lit.cfg (original)
+++ compiler-rt/trunk/lib/lsan/lit_tests/lit.cfg Mon May 27 06:41:46 2013
@@ -30,10 +30,15 @@ if (not compiler_rt_lit_cfg) or (not os.
             % compiler_rt_lit_cfg)
 lit.load_config(config, compiler_rt_lit_cfg)
 
-# Setup default compiler flags used with -fsanitize=leak option.
-clang_lsan_cxxflags = ("-ccc-cxx "
-                      + "-fsanitize=leak "
-                      + "-g")
+clang_cxxflags = ("-ccc-cxx "
+                      + "-g "
+                      + "-O0 "
+                      + "-m64 ")
+
+clang_lsan_cxxflags = clang_cxxflags + "-fsanitize=leak "
+
+config.substitutions.append( ("%clangxx ", (" " + config.clang + " " +
+                                                clang_cxxflags + " ")) )
 config.substitutions.append( ("%clangxx_lsan ", (" " + config.clang + " " +
                                                 clang_lsan_cxxflags + " ")) )
 

Added: compiler-rt/trunk/lib/lsan/lit_tests/use_globals_initialized.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lit_tests/use_globals_initialized.cc?rev=182730&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/lit_tests/use_globals_initialized.cc (added)
+++ compiler-rt/trunk/lib/lsan/lit_tests/use_globals_initialized.cc Mon May 27 06:41:46 2013
@@ -0,0 +1,21 @@
+// Test that initialized globals are included in the root set. 
+// RUN: LSAN_BASE="report_blocks=1:use_stacks=0:use_registers=0"
+// RUN: %clangxx_lsan %s -o %t
+// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=0" %t 2>&1 | FileCheck %s
+// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_globals=1" %t 2>&1
+// RUN: LSAN_OPTIONS="" %t 2>&1
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void *data_var = (void *)1;
+
+int main() {
+  data_var = malloc(1337);
+  fprintf(stderr, "Test alloc: %p.\n", data_var);
+  return 0;
+}
+// CHECK: Test alloc: [[ADDR:.*]].
+// CHECK: LeakSanitizer: detected memory leaks
+// CHECK: Directly leaked 1337 byte block at [[ADDR]]
+// CHECK: SUMMARY: LeakSanitizer:

Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Mon May 27 06:41:46 2013
@@ -186,6 +186,5 @@ template void ForEachChunk<PrintLeakedCb
 template void ForEachChunk<CollectLeaksCb>(CollectLeaksCb const &callback);
 template void ForEachChunk<MarkIndirectlyLeakedCb>(
     MarkIndirectlyLeakedCb const &callback);
-template void ForEachChunk<ReportLeakedCb>(ReportLeakedCb const &callback);
 template void ForEachChunk<ClearTagCb>(ClearTagCb const &callback);
 }  // namespace __lsan

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Mon May 27 06:41:46 2013
@@ -28,19 +28,25 @@ Flags lsan_flags;
 static void InitializeFlags() {
   Flags *f = flags();
   // Default values.
-  f->sources = kSourceAllAligned;
   f->report_blocks = false;
   f->resolution = 0;
   f->max_leaks = 0;
   f->exitcode = 23;
+  f->use_registers = true;
+  f->use_globals = true;
+  f->use_stacks = true;
+  f->use_tls = true;
+  f->use_unaligned = false;
   f->log_pointers = false;
   f->log_threads = false;
 
   const char *options = GetEnv("LSAN_OPTIONS");
   if (options) {
-    bool aligned = true;
-    ParseFlag(options, &aligned, "aligned");
-    if (!aligned) f->sources |= kSourceUnaligned;
+    ParseFlag(options, &f->use_registers, "use_registers");
+    ParseFlag(options, &f->use_globals, "use_globals");
+    ParseFlag(options, &f->use_stacks, "use_stacks");
+    ParseFlag(options, &f->use_tls, "use_tls");
+    ParseFlag(options, &f->use_unaligned, "use_unaligned");
     ParseFlag(options, &f->report_blocks, "report_blocks");
     ParseFlag(options, &f->resolution, "resolution");
     CHECK_GE(&f->resolution, 0);
@@ -132,11 +138,11 @@ static void ProcessThreads(SuspendedThre
       sp = stack_begin;
     }
 
-    if (flags()->use_registers() && have_registers)
+    if (flags()->use_registers && have_registers)
       ScanRangeForPointers(registers_begin, registers_end, frontier,
                            "REGISTERS", kReachable);
 
-    if (flags()->use_stacks()) {
+    if (flags()->use_stacks) {
       if (flags()->log_threads)
         Report("Stack at %p-%p, SP = %p.\n", stack_begin, stack_end, sp);
       if (sp < stack_begin || sp >= stack_end) {
@@ -153,7 +159,7 @@ static void ProcessThreads(SuspendedThre
                            kReachable);
     }
 
-    if (flags()->use_tls()) {
+    if (flags()->use_tls) {
       if (flags()->log_threads) Report("TLS at %p-%p.\n", tls_begin, tls_end);
       if (cache_begin == cache_end) {
         ScanRangeForPointers(tls_begin, tls_end, frontier, "TLS", kReachable);
@@ -198,7 +204,7 @@ static void ClassifyAllChunks(SuspendedT
   // Holds the flood fill frontier.
   InternalVector<uptr> frontier(GetPageSizeCached());
 
-  if (flags()->use_globals())
+  if (flags()->use_globals)
     ProcessGlobalRegions(&frontier);
   ProcessThreads(suspended_threads, &frontier);
   FloodFillReachable(&frontier);
@@ -298,7 +304,7 @@ static void DoLeakCheckCallback(const Su
   }
   Printf("\n");
   Printf("=================================================================\n");
-  Report("ERROR: LeakSanitizer: detected leaks.\n");
+  Report("ERROR: LeakSanitizer: detected memory leaks\n");
   leak_report.PrintLargest(flags()->max_leaks);
   if (flags()->report_blocks)
     PrintLeaked();
@@ -320,43 +326,6 @@ void DoLeakCheck() {
   }
 }
 
-///// Reporting of leaked blocks' addresses (for testing). /////
-
-void ReportLeakedCb::operator()(void *p) const {
-  p = GetUserBegin(p);
-  LsanMetadata m(p);
-  if (m.allocated() && m.tag() != kReachable)
-    leaked_->push_back(p);
-}
-
-struct ReportLeakedParam {
-  InternalVector<void *> *leaked;
-  uptr sources;
-  bool success;
-};
-
-static void ReportLeakedCallback(const SuspendedThreadsList &suspended_threads,
-                                 void *arg) {
-  // Allocator must not be locked when we call GetRegionBegin().
-  UnlockAllocator();
-  ReportLeakedParam *param = reinterpret_cast<ReportLeakedParam *>(arg);
-  flags()->sources = param->sources;
-  ClassifyAllChunks(suspended_threads);
-  ForEachChunk(ReportLeakedCb(param->leaked));
-  ForEachChunk(ClearTagCb());
-  param->success = true;
-}
-
-void ReportLeaked(InternalVector<void *> *leaked, uptr sources) {
-  CHECK_EQ(0, leaked->size());
-  ReportLeakedParam param;
-  param.leaked = leaked;
-  param.success = false;
-  param.sources = sources;
-  LockAndSuspendThreads(ReportLeakedCallback, &param);
-  CHECK(param.success);
-}
-
 ///// LeakReport implementation. /////
 
 // A hard limit on the number of distinct leaks, to avoid quadratic complexity

Modified: compiler-rt/trunk/lib/lsan/lsan_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.h?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.h Mon May 27 06:41:46 2013
@@ -35,32 +35,11 @@ enum ChunkTag {
   kReachable = 2
 };
 
-// Sources of pointers.
-// Global variables (.data and .bss).
-const uptr kSourceGlobals = 1 << 0;
-// Thread stacks.
-const uptr kSourceStacks = 1 << 1;
-// TLS and thread-specific storage.
-const uptr kSourceTLS = 1 << 2;
-// Thread registers.
-const uptr kSourceRegisters = 1 << 3;
-// Unaligned pointers.
-const uptr kSourceUnaligned = 1 << 4;
-
-// Aligned pointers everywhere.
-const uptr kSourceAllAligned =
-    kSourceGlobals | kSourceStacks | kSourceTLS | kSourceRegisters;
-
 struct Flags {
-  bool use_registers() const { return sources & kSourceRegisters; }
-  bool use_globals() const { return sources & kSourceGlobals; }
-  bool use_stacks() const { return sources & kSourceStacks; }
-  bool use_tls() const { return sources & kSourceTLS; }
   uptr pointer_alignment() const {
-    return (sources & kSourceUnaligned) ? 1 : sizeof(uptr);
+    return use_unaligned ? 1 : sizeof(uptr);
   }
 
-  uptr sources;
   // Print addresses of leaked blocks after main leak report.
   bool report_blocks;
   // Aggregate two blocks into one leak if this many stack frames match. If
@@ -71,6 +50,19 @@ struct Flags {
   // If nonzero kill the process with this exit code upon finding leaks.
   int exitcode;
 
+  // Flags controlling the root set of reachable memory.
+  // Global variables (.data and .bss).
+  bool use_globals;
+  // Thread stacks.
+  bool use_stacks;
+  // Thread registers.
+  bool use_registers;
+  // TLS and thread-specific storage.
+  bool use_tls;
+
+  // Consider unaligned pointers valid.
+  bool use_unaligned;
+
   // Debug logging.
   bool log_pointers;
   bool log_threads;
@@ -143,15 +135,6 @@ class CollectLeaksCb {
   LeakReport *leak_report_;
 };
 
-// Dumps addresses of unreachable chunks to a vector (for testing).
-class ReportLeakedCb {
- public:
-  explicit ReportLeakedCb(InternalVector<void *> *leaked) : leaked_(leaked) {}
-  void operator()(void *p) const;
- private:
-  InternalVector<void *> *leaked_;
-};
-
 // Resets each chunk's tag to default (kDirectlyLeaked).
 class ClearTagCb {
  public:

Modified: compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_linux.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common_linux.cc Mon May 27 06:41:46 2013
@@ -114,7 +114,7 @@ void ProcessPlatformSpecificAllocationsC
 // Handle dynamically allocated TLS blocks by treating all chunks allocated from
 // ld-linux.so as reachable.
 void ProcessPlatformSpecificAllocations(InternalVector<uptr> *frontier) {
-  if (!flags()->use_tls()) return;
+  if (!flags()->use_tls) return;
   if (!linker) return;
   ForEachChunk(ProcessPlatformSpecificAllocationsCb(frontier));
 }

Modified: compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/lsan/tests/CMakeLists.txt Mon May 27 06:41:46 2013
@@ -6,7 +6,7 @@ include_directories(..)
 include_directories(../..)
 
 set(LSAN_TESTS_SRC
-  lsan_test.cc)
+  lsan_dummy_unittest.cc)
 
 set(LSAN_TESTS_CFLAGS
   ${LSAN_CFLAGS}
@@ -17,8 +17,6 @@ add_custom_target(LsanTests)
 set_target_properties(LsanTests PROPERTIES
   FOLDER "LSan unittests")
 
-set(LSAN_LOADABLE_SRC "lsan_tls_loadable.cc")
-
 # Compile source for the given architecture, using compiler
 # options in ${ARGN}, and add it to the object list.
 macro(lsan_compile obj_list source arch)
@@ -45,14 +43,9 @@ macro(add_lsan_tests_for_arch arch)
   lsan_compile(LSAN_TESTS_OBJ ${LSAN_TESTS_SRC} ${arch} ${LSAN_TESTS_CFLAGS}
       -I${LSAN_SRC_DIR})
   add_lsan_test(Lsan ${arch} ${LSAN_TESTS_OBJ})
-  add_library("lsan_tls_loadable-${arch}" SHARED ${LSAN_LOADABLE_SRC})
-  set_property(TARGET "lsan_tls_loadable-${arch}" PROPERTY
-      LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-  add_dependencies(Lsan-${arch}-Test  lsan_tls_loadable-${arch})
 endmacro()
 
 # Build tests for 64-bit Linux only.
 if(UNIX AND NOT APPLE AND CAN_TARGET_x86_64)
   add_lsan_tests_for_arch(x86_64)
 endif()
-

Added: compiler-rt/trunk/lib/lsan/tests/lsan_dummy_unittest.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/lsan_dummy_unittest.cc?rev=182730&view=auto
==============================================================================
    (empty)

Removed: compiler-rt/trunk/lib/lsan/tests/lsan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/lsan_test.cc?rev=182729&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/lsan_test.cc (original)
+++ compiler-rt/trunk/lib/lsan/tests/lsan_test.cc (removed)
@@ -1,299 +0,0 @@
-//=-- lsan_test.cc --------------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of LeakSanitizer.
-// Tests for leak checking functionality.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX && defined(__x86_64__)
-
-#include <dlfcn.h>
-#include <pthread.h>
-#include <string>
-
-#include "gtest/gtest.h"
-#include "sanitizer_common/sanitizer_atomic.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/tests/sanitizer_test_utils.h"
-
-#include "lsan.h"
-#include "lsan_common.h"
-
-static char **global_argv;
-
-namespace {
-uptr kMagic = 0xBABABABABABABABA;
-#define HIDE(p) ((void *)((uptr)(p) ^ kMagic))
-#define PEEK(p) HIDE(p)
-
-uptr kSmallAllocSize = 10;
-// maxsize in primary allocator is always less than this.
-uptr kLargeAllocSize = 1 << 25;
-
-::testing::AssertionResult IsLeaked(void *hidden_p, uptr sources) {
-  InternalVector<void *> leaked(1);
-  __lsan::ReportLeaked(&leaked, sources);
-  for (uptr i = 0; i < leaked.size(); i++)
-    if (leaked[i] == PEEK(hidden_p))
-      return ::testing::AssertionSuccess() << PEEK(hidden_p) << " is leaked";
-  return ::testing::AssertionFailure() << PEEK(hidden_p) << " is not leaked";
-}
-
-#define EXPECT_LEAKED(p, sources) EXPECT_TRUE(IsLeaked(HIDE((p)), sources))
-#define EXPECT_NOT_LEAKED(p, sources) EXPECT_FALSE(IsLeaked(HIDE((p)), sources))
-
-// Tests for various sources of pointers.
-// Stacks and registers are tricky: pointers sometimes get stuck in them and
-// cause false negatives. This is not considered a bug in LSan, but we don't
-// want it to interfere with our tests, so we disable those sources whenever we
-// can. We don't disable globals though: if a stale pointer somehow makes it
-// into global state and causes a false negative, we want to know.
-
-uptr kAllButStackAndRegisters =
-    __lsan::kSourceAllAligned & ~__lsan::kSourceStacks &
-    ~__lsan::kSourceRegisters;
-
-void TestSource(void **p, uptr source) {
-  uptr baseline = kAllButStackAndRegisters | source;
-  *p = malloc(kSmallAllocSize);
-  EXPECT_NOT_LEAKED(*p, baseline);
-  EXPECT_LEAKED(*p, baseline & ~source);
-  // Check again, in case the first EXPECT_NOT_LEAKED was a false negative.
-  EXPECT_NOT_LEAKED(*p, baseline);
-  free((void *)*p);
-  *p = NULL;
-}
-
-void *data_var = (void*) 1;
-
-TEST(LeakSanitizer, InitializedGlobals) {
-  TestSource(&data_var, __lsan::kSourceGlobals);
-}
-
-void *bss_var;
-
-TEST(LeakSanitizer, UninitializedGlobals) {
-  TestSource(&bss_var, __lsan::kSourceGlobals);
-}
-
-TEST(LeakSanitizer, Stack) {
-  void *local_var;
-  TestSource(&local_var, __lsan::kSourceStacks);
-}
-
-THREADLOCAL void *tl_var;
-
-TEST(LeakSanitizer, StaticTLS) {
-  TestSource(&tl_var, __lsan::kSourceTLS);
-}
-
-// Dynamically allocated TLS space.
-TEST(LeakSanitizer, DynamicTLS) {
-  // Compute the path to our loadable DSO.  We assume it's in the same
-  // directory.
-  char **argv = global_argv;
-  const std::string kLoadableSO = "liblsan_tls_loadable-x86_64.so";
-  std::string path = argv[0];
-  size_t last_slash = path.rfind('/');
-  ASSERT_NE(last_slash, std::string::npos);
-  path.erase(last_slash + 1);
-  path.append(kLoadableSO);
-  void *handle = dlopen(path.c_str(), RTLD_LAZY);
-  ASSERT_TRUE(handle != NULL) << "dlerror " << dlerror();
-  typedef void **(* store_t)(void *p);
-  store_t StoreToTLS = (store_t)dlsym(handle, "StoreToTLS");
-  ASSERT_EQ(0, dlerror());
-
-  void *p = malloc(kSmallAllocSize);
-  void **p_in_tls = StoreToTLS(p);
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  EXPECT_LEAKED(p, kAllButStackAndRegisters & ~__lsan::kSourceTLS);
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  free(p);
-  *p_in_tls = NULL;
-}
-
-// From glibc: this many keys are stored in the thread descriptor directly.
-const uptr PTHREAD_KEY_2NDLEVEL_SIZE = 32;
-
-// Thread-specific storage that is statically alocated in the thread descriptor.
-TEST(LeakSanitizer, PthreadSpecificStatic) {
-  pthread_key_t key;
-  ASSERT_EQ(0, pthread_key_create(&key, NULL));
-  ASSERT_LT(key, PTHREAD_KEY_2NDLEVEL_SIZE);
-  void *p = malloc(kSmallAllocSize);
-  ASSERT_EQ(0, pthread_setspecific(key, p));
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  EXPECT_LEAKED(p, kAllButStackAndRegisters & ~__lsan::kSourceTLS);
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  ASSERT_EQ(0, pthread_setspecific(key, 0));
-  free(p);
-}
-
-// Dynamically allocated thread-specific storage.
-TEST(LeakSanitizer, PthreadSpecificDynamic) {
-  static const uptr kDummyKeysCount = PTHREAD_KEY_2NDLEVEL_SIZE;
-  pthread_key_t dummy_keys[kDummyKeysCount];
-  for (uptr i = 0; i < kDummyKeysCount; i++)
-    ASSERT_EQ(0, pthread_key_create(&dummy_keys[i], NULL));
-  pthread_key_t key;
-  ASSERT_EQ(0, pthread_key_create(&key, NULL));
-  void *p  = malloc(kSmallAllocSize);
-  ASSERT_EQ(0, pthread_setspecific(key, p));
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  EXPECT_LEAKED(p, kAllButStackAndRegisters & ~__lsan::kSourceTLS);
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters);
-  ASSERT_EQ(0, pthread_setspecific(key, NULL));
-  CHECK_EQ(0, pthread_key_delete(key));
-  for (uptr i = 0; i < kDummyKeysCount; i++)
-    CHECK_EQ(0, pthread_key_delete(dummy_keys[i]));
-  free(p);
-}
-
-// Put pointer far enough on the stack that LSan has space to run in without
-// overwriting it.
-NOINLINE uptr PutPointerOnStaleStack(void *p) {
-  void *locals[2048];
-  locals[0] = p;
-  break_optimization(&locals[0]);
-  // Hide the result, just to suppress the compiler warning.
-  return (uptr)HIDE(&locals[0]);
-}
-
-// Local variables that have gone out of scope should be ignored by LSan.
-TEST(LeakSanitizer, StaleLocalsAreUnreachable) {
-  void *p = malloc(kSmallAllocSize);
-  void **stale_var = (void **)PEEK(PutPointerOnStaleStack(p));
-  p = HIDE(p);
-  EXPECT_LEAKED(PEEK(p), __lsan::kSourceAllAligned & ~__lsan::kSourceRegisters);
-  p = PEEK(p);
-  // Make sure LSan didn't overwrite the pointer at some point.
-  EXPECT_EQ(p, *stale_var);
-  free(p);
-}
-
-void *large_alloc;
-
-// Make sure LargeMmapAllocator's chunks aren't reachable via some internal data
-// structure.
-TEST(LeakSanitizer, SimpleLargeAllocationLeaked) {
-  large_alloc = HIDE(malloc(kLargeAllocSize));
-  EXPECT_TRUE(IsLeaked((void *)large_alloc,
-      __lsan::kSourceAllAligned & ~__lsan::kSourceRegisters));
-  large_alloc = PEEK(large_alloc);
-  EXPECT_FALSE(IsLeaked((void *)large_alloc,
-      __lsan::kSourceAllAligned & ~__lsan::kSourceRegisters));
-  free((void *)large_alloc);
-  large_alloc = NULL;
-}
-
-// Multi-threaded tests.
-struct ThreadArgument {
-  void sync_wait(uptr value) {
-    while (atomic_load(&sync, memory_order_seq_cst) != value)
-      pthread_yield();
-  }
-  void sync_store(uptr value) {
-    atomic_store(&sync, value, memory_order_seq_cst);
-  }
-
-  void *hidden_p;
-  atomic_uintptr_t sync;
-};
-
-void *StackThreadFunc(void *param) {
-  ThreadArgument *arg = reinterpret_cast<ThreadArgument *>(param);
-  void *p = malloc(kSmallAllocSize);
-  // Take p's address to ensure it's not optimized into a register.
-  void * volatile *pp = &p;
-  arg->hidden_p = HIDE(*pp);
-  arg->sync_store(1);
-  arg->sync_wait(2);
-  free(p);
-  return NULL;
-}
-
-void *RegistersThreadFunc(void *param) {
-  ThreadArgument *arg = reinterpret_cast<ThreadArgument *>(param);
-  // To store the pointer, choose a register which is unlikely to be reused by
-  // a function call.
-#if defined(__i386__)
-  register void* p asm("esi");
-#elif defined(__x86_64__)
-  register void* p asm("r15");
-#else
-  register void* p;
-#endif
-  p = malloc(kSmallAllocSize);
-  arg->hidden_p = HIDE(p);
-  arg->sync_store(1);
-  arg->sync_wait(2);
-  free(p);
-  return NULL;
-}
-
-void MultiThreadedTest(uptr source) {
-  uptr other_source;
-  void *(*func)(void *arg);
-  if (source == __lsan::kSourceStacks) {
-    func = StackThreadFunc;
-    other_source = __lsan::kSourceRegisters;
-  } else if (source == __lsan::kSourceRegisters) {
-    func = RegistersThreadFunc;
-    other_source = __lsan::kSourceStacks;
-  } else {
-    FAIL();
-  }
-  uptr baseline = __lsan::kSourceAllAligned & ~other_source;
-  ThreadArgument arg;
-  arg.sync_store(0);
-  pthread_t thread_id;
-  ASSERT_EQ(0, pthread_create(&thread_id, NULL, func, &arg));
-  arg.sync_wait(1);
-  EXPECT_NOT_LEAKED(PEEK(arg.hidden_p), baseline);
-  EXPECT_LEAKED(PEEK(arg.hidden_p), baseline & ~source);
-  EXPECT_NOT_LEAKED(PEEK(arg.hidden_p), baseline);
-  arg.sync_store(2);
-  ASSERT_EQ(0, pthread_join(thread_id, NULL));
-}
-
-TEST(LeakSanitizer, ThreadStacks) {
-  MultiThreadedTest(__lsan::kSourceStacks);
-}
-
-TEST(LeakSanitizer, ThreadRegisters) {
-  MultiThreadedTest(__lsan::kSourceRegisters);
-}
-
-// End of tests for pointer sources.
-
-TEST(LeakSanitizer, UnalignedPointers) {
-  // Static so we can disable stack.
-  static uptr arr[2];
-  char *char_arr = (char *)arr;
-  void *p = malloc(kSmallAllocSize);
-  memcpy(char_arr + 1, &p, sizeof(uptr));
-  EXPECT_LEAKED(p, kAllButStackAndRegisters);
-  EXPECT_NOT_LEAKED(p, kAllButStackAndRegisters | __lsan::kSourceUnaligned);
-  EXPECT_LEAKED(p, kAllButStackAndRegisters);
-  free(p);
-}
-
-}  // namespace
-
-int main(int argc, char **argv) {
-  global_argv = argv;
-  __lsan::Init();
-  ::testing::InitGoogleTest(&argc, argv);
-  return RUN_ALL_TESTS();
-}
-
-#endif  // SANITIZER_LINUX && defined(__x86_64__)

Removed: compiler-rt/trunk/lib/lsan/tests/lsan_tls_loadable.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/tests/lsan_tls_loadable.cc?rev=182729&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/tests/lsan_tls_loadable.cc (original)
+++ compiler-rt/trunk/lib/lsan/tests/lsan_tls_loadable.cc (removed)
@@ -1,24 +0,0 @@
-//=-- lsan_tls_loadable.cc ------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of LeakSanitizer.
-// A loadable module with a large thread local section, which would require
-// allocation of a new TLS storage chunk when loaded with dlopen(). We use it to
-// test reachability of such chunks in LSan tests.
-//
-//===----------------------------------------------------------------------===//
-
-// This must be large enough that it doesn't fit into preallocated static TLS
-// space (see STATIC_TLS_SURPLUS in glibc).
-__thread void *huge_thread_local_array[(1 << 20) / sizeof(void *)]; // NOLINT
-
-extern "C" void **StoreToTLS(void *p) {
-  huge_thread_local_array[0] = p;
-  return &huge_thread_local_array[0];
-}

Modified: compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh?rev=182730&r1=182729&r2=182730&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh (original)
+++ compiler-rt/trunk/lib/sanitizer_common/scripts/check_lint.sh Mon May 27 06:41:46 2013
@@ -31,6 +31,7 @@ TSAN_TEST_LINT_FILTER=${TSAN_RTL_LINT_FI
 TSAN_LIT_TEST_LINT_FILTER=${TSAN_TEST_LINT_FILTER},-whitespace/line_length
 MSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER}
 LSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER}
+LSAN_LIT_TEST_LINT_FILTER=${LSAN_RTL_LINT_FILTER},-whitespace/line_length
 COMMON_RTL_INC_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int,-runtime/sizeof,-runtime/printf
 SANITIZER_INCLUDES_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int
 
@@ -79,6 +80,7 @@ ${CPPLINT} --filter=${MSAN_RTL_LINT_FILT
 LSAN_RTL=${COMPILER_RT}/lib/lsan
 ${CPPLINT} --filter=${LSAN_RTL_LINT_FILTER} ${LSAN_RTL}/*.{cc,h}
 ${CPPLINT} --filter=${LSAN_RTL_LINT_FILTER} ${LSAN_RTL}/tests/*.{cc,h}
+${CPPLINT} --filter=${LSAN_LIT_TEST_LINT_FILTER} ${LSAN_RTL}/lit_tests/*.{cc,h}
 
 set +e
 





More information about the llvm-commits mailing list