[llvm-commits] [compiler-rt] r164022 - in /compiler-rt/trunk/lib/tsan: ./ lit_tests/ lit_tests/Unit/ rtl_tests/ tests/ tests/rtl/ tests/unit/ unit_tests/

David Blaikie dblaikie at gmail.com
Mon Sep 17 14:05:58 PDT 2012


On Mon, Sep 17, 2012 at 3:02 AM, Alexey Samsonov <samsonov at google.com> wrote:
> Author: samsonov
> Date: Mon Sep 17 05:02:17 2012
> New Revision: 164022
>
> URL: http://llvm.org/viewvc/llvm-project?rev=164022&view=rev
> Log:
> [TSan] move: rtl_tests->tests/rtl unit_tests->tests/unit to make a single root for gtest-based tests. Support running these tests from lit via check-tsan command.
>
> Added:
>     compiler-rt/trunk/lib/tsan/lit_tests/
>     compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/lit_tests/Unit/
>     compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.cfg
>     compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.site.cfg.in
>     compiler-rt/trunk/lib/tsan/tests/
>     compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/tests/rtl/
>     compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_bench.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mop.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mutex.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_posix.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_string.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util.h
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_linux.cc
>     compiler-rt/trunk/lib/tsan/tests/rtl/tsan_thread.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/
>     compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_clock_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_flags_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_mutex_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_platform_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_printf_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_shadow_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_stack_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_suppressions_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc
>     compiler-rt/trunk/lib/tsan/tests/unit/tsan_vector_test.cc
> Removed:
>     compiler-rt/trunk/lib/tsan/rtl_tests/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_bench.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mop.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mutex.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_posix.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_string.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util.h
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc
>     compiler-rt/trunk/lib/tsan/rtl_tests/tsan_thread.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_clock_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_mman_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_mutex_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_platform_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_printf_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_shadow_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_stack_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_sync_test.cc
>     compiler-rt/trunk/lib/tsan/unit_tests/tsan_vector_test.cc
> Modified:
>     compiler-rt/trunk/lib/tsan/CMakeLists.txt
>     compiler-rt/trunk/lib/tsan/Makefile.old
>
> Modified: compiler-rt/trunk/lib/tsan/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/CMakeLists.txt?rev=164022&r1=164021&r2=164022&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/tsan/CMakeLists.txt Mon Sep 17 05:02:17 2012
> @@ -17,31 +17,6 @@
>  add_subdirectory(rtl)
>
>  if(LLVM_INCLUDE_TESTS)
> -  add_custom_target(TsanUnitTests)
> -  set_target_properties(TsanUnitTests PROPERTIES
> -    FOLDER "TSan unittests")
> -
> -  function(add_tsan_unittest testname)
> -    # Build unit tests only on 64-bit Linux.
> -    if(UNIX AND NOT APPLE
> -            AND CAN_TARGET_X86_64
> -            AND CMAKE_SIZEOF_VOID_P EQUAL 8
> -            AND NOT LLVM_BUILD_32_BITS)
> -      add_unittest(TsanUnitTests ${testname} ${ARGN})
> -      # Link with TSan runtime.
> -      target_link_libraries(${testname} clang_rt.tsan-x86_64)
> -      # Build tests with PIE and debug info.
> -      set_property(TARGET ${testname} APPEND_STRING
> -        PROPERTY COMPILE_FLAGS " -fPIE -g")
> -      set_property(TARGET ${testname} APPEND_STRING
> -        PROPERTY LINK_FLAGS " -pie")
> -    endif()
> -  endfunction()
> -
> -  include_directories(rtl)
> -  # There are two groups of unit tests: rtl_tests and unit_tests.
> -  add_subdirectory(rtl_tests)
> -  add_subdirectory(unit_tests)
> +  add_subdirectory(tests)
>  endif()
> -
> -# FIXME: Support TSan runtime tests, unit tests and output tests.
> +add_subdirectory(lit_tests)
>
> Modified: compiler-rt/trunk/lib/tsan/Makefile.old
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=164022&r1=164021&r2=164022&view=diff
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/Makefile.old (original)
> +++ compiler-rt/trunk/lib/tsan/Makefile.old Mon Sep 17 05:02:17 2012
> @@ -19,9 +19,9 @@
>
>  SANITIZER_COMMON_TESTS_SRC=$(wildcard ../sanitizer_common/tests/*_test.cc)
>  SANITIZER_COMMON_TESTS_OBJ=$(patsubst %.cc,%.o,$(SANITIZER_COMMON_TESTS_SRC))
> -RTL_TEST_SRC=$(wildcard rtl_tests/*.cc)
> +RTL_TEST_SRC=$(wildcard tests/rtl/*.cc)
>  RTL_TEST_OBJ=$(patsubst %.cc,%.o,$(RTL_TEST_SRC))
> -UNIT_TEST_SRC=$(wildcard unit_tests/*_test.cc)
> +UNIT_TEST_SRC=$(wildcard tests/unit/*_test.cc)
>  UNIT_TEST_OBJ=$(patsubst %.cc,%.o,$(UNIT_TEST_SRC))
>  UNIT_TEST_HDR=$(wildcard rtl/*.h) $(wildcard ../sanitizer_common/*.h)
>
>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/CMakeLists.txt Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,12 @@
> +configure_lit_site_cfg(
> +  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
> +  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
> +  )
> +
> +# Run TSan unit tests.
> +if(LLVM_INCLUDE_TESTS)
> +  add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"
> +    ${CMAKE_CURRENT_BINARY_DIR}/Unit
> +    DEPENDS TsanUnitTests)
> +  set_target_properties(check-tsan PROPERTIES FOLDER "TSan unittests")
> +endif()
>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.cfg
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.cfg?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.cfg (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.cfg Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,29 @@
> +# -*- Python -*-
> +
> +import os
> +
> +def get_required_attr(config, attr_name):
> +  attr_value = getattr(config, attr_name, None)
> +  if not attr_value:
> +    lit.fatal("No attribute %r in test configuration! You may need to run "
> +              "tests from your build directory or add this attribute "
> +              "to lit.site.cfg " % attr_name)
> +  return attr_value
> +
> +# Setup attributes common for all compiler-rt projects.
> +llvm_src_root = get_required_attr(config, 'llvm_src_root')
> +compiler_rt_lit_unit_cfg = os.path.join(llvm_src_root, "projects",
> +                                        "compiler-rt", "lib",
> +                                        "lit.common.unit.cfg")
> +lit.load_config(config, compiler_rt_lit_unit_cfg)
> +
> +# Setup config name.
> +config.name = 'ThreadSanitizer-Unit'
> +
> +# Setup test source and exec root. For unit tests, we define
> +# it as build directory with TSan unit tests.
> +llvm_obj_root = get_required_attr(config, "llvm_obj_root")
> +config.test_exec_root = os.path.join(llvm_obj_root, "projects",
> +                                     "compiler-rt", "lib",
> +                                     "tsan", "tests")
> +config.test_source_root = config.test_exec_root
>
> Added: compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.site.cfg.in
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.site.cfg.in?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.site.cfg.in (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/Unit/lit.site.cfg.in Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,9 @@
> +## Autogenerated by LLVM/Clang configuration.
> +# Do not edit!
> +
> +config.build_type = "@CMAKE_BUILD_TYPE@"
> +config.llvm_obj_root = "@LLVM_BINARY_DIR@"
> +config.llvm_src_root = "@LLVM_SOURCE_DIR@"
> +
> +# Let the main config do the real work.
> +lit.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/Unit/lit.cfg")
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/CMakeLists.txt?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/CMakeLists.txt (removed)
> @@ -1,15 +0,0 @@
> -set(TSAN_RTL_TESTS
> -  tsan_bench.cc
> -  tsan_mop.cc
> -  tsan_mutex.cc
> -  tsan_posix.cc
> -  tsan_string.cc
> -  tsan_test.cc
> -  tsan_thread.cc
> -  )
> -
> -if(UNIX AND NOT APPLE)
> -  list(APPEND TSAN_RTL_TESTS tsan_test_util_linux.cc)
> -endif()
> -
> -add_tsan_unittest(TsanRtlTest ${TSAN_RTL_TESTS})
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_bench.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_bench.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_bench.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_bench.cc (removed)
> @@ -1,105 +0,0 @@
> -//===-- tsan_bench.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_test_util.h"
> -#include "tsan_interface.h"
> -#include "tsan_defs.h"
> -#include "gtest/gtest.h"
> -#include <stdint.h>
> -
> -const int kSize = 128;
> -const int kRepeat = 2*1024*1024;
> -
> -void noinstr(void *p) {}
> -
> -template<typename T, void(*__tsan_mop)(void *p)>
> -static void Benchmark() {
> -  volatile T data[kSize];
> -  for (int i = 0; i < kRepeat; i++) {
> -    for (int j = 0; j < kSize; j++) {
> -      __tsan_mop((void*)&data[j]);
> -      data[j]++;
> -    }
> -  }
> -}
> -
> -TEST(DISABLED_BENCH, Mop1) {
> -  Benchmark<uint8_t, noinstr>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop1Read) {
> -  Benchmark<uint8_t, __tsan_read1>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop1Write) {
> -  Benchmark<uint8_t, __tsan_write1>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop2) {
> -  Benchmark<uint16_t, noinstr>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop2Read) {
> -  Benchmark<uint16_t, __tsan_read2>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop2Write) {
> -  Benchmark<uint16_t, __tsan_write2>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop4) {
> -  Benchmark<uint32_t, noinstr>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop4Read) {
> -  Benchmark<uint32_t, __tsan_read4>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop4Write) {
> -  Benchmark<uint32_t, __tsan_write4>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop8) {
> -  Benchmark<uint8_t, noinstr>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop8Read) {
> -  Benchmark<uint64_t, __tsan_read8>();
> -}
> -
> -TEST(DISABLED_BENCH, Mop8Write) {
> -  Benchmark<uint64_t, __tsan_write8>();
> -}
> -
> -TEST(DISABLED_BENCH, FuncCall) {
> -  for (int i = 0; i < kRepeat; i++) {
> -    for (int j = 0; j < kSize; j++)
> -      __tsan_func_entry((void*)(uintptr_t)j);
> -    for (int j = 0; j < kSize; j++)
> -      __tsan_func_exit();
> -  }
> -}
> -
> -TEST(DISABLED_BENCH, MutexLocal) {
> -  Mutex m;
> -  ScopedThread().Create(m);
> -  for (int i = 0; i < 50; i++) {
> -    ScopedThread t;
> -    t.Lock(m);
> -    t.Unlock(m);
> -  }
> -  for (int i = 0; i < 16*1024*1024; i++) {
> -    m.Lock();
> -    m.Unlock();
> -  }
> -  ScopedThread().Destroy(m);
> -}
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mop.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mop.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mop.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mop.cc (removed)
> @@ -1,233 +0,0 @@
> -//===-- tsan_mop.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_interface.h"
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -#include <stddef.h>
> -#include <stdint.h>
> -
> -TEST(ThreadSanitizer, SimpleWrite) {
> -  ScopedThread t;
> -  MemLoc l;
> -  t.Write1(l);
> -}
> -
> -TEST(ThreadSanitizer, SimpleWriteWrite) {
> -  ScopedThread t1, t2;
> -  MemLoc l1, l2;
> -  t1.Write1(l1);
> -  t2.Write1(l2);
> -}
> -
> -TEST(ThreadSanitizer, WriteWriteRace) {
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Write1(l);
> -  t2.Write1(l, true);
> -}
> -
> -TEST(ThreadSanitizer, ReadWriteRace) {
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Read1(l);
> -  t2.Write1(l, true);
> -}
> -
> -TEST(ThreadSanitizer, WriteReadRace) {
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Write1(l);
> -  t2.Read1(l, true);
> -}
> -
> -TEST(ThreadSanitizer, ReadReadNoRace) {
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Read1(l);
> -  t2.Read1(l);
> -}
> -
> -TEST(ThreadSanitizer, WriteThenRead) {
> -  MemLoc l;
> -  ScopedThread t1, t2;
> -  t1.Write1(l);
> -  t1.Read1(l);
> -  t2.Read1(l, true);
> -}
> -
> -TEST(ThreadSanitizer, WriteThenLockedRead) {
> -  Mutex m(Mutex::RW);
> -  MainThread t0;
> -  t0.Create(m);
> -  MemLoc l;
> -  {
> -    ScopedThread t1, t2;
> -
> -    t1.Write8(l);
> -
> -    t1.Lock(m);
> -    t1.Read8(l);
> -    t1.Unlock(m);
> -
> -    t2.Read8(l, true);
> -  }
> -  t0.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, LockedWriteThenRead) {
> -  Mutex m(Mutex::RW);
> -  MainThread t0;
> -  t0.Create(m);
> -  MemLoc l;
> -  {
> -    ScopedThread t1, t2;
> -
> -    t1.Lock(m);
> -    t1.Write8(l);
> -    t1.Unlock(m);
> -
> -    t1.Read8(l);
> -
> -    t2.Read8(l, true);
> -  }
> -  t0.Destroy(m);
> -}
> -
> -
> -TEST(ThreadSanitizer, RaceWithOffset) {
> -  ScopedThread t1, t2;
> -  {
> -    MemLoc l;
> -    t1.Access(l.loc(), true, 8, false);
> -    t2.Access((char*)l.loc() + 4, true, 4, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access(l.loc(), true, 8, false);
> -    t2.Access((char*)l.loc() + 7, true, 1, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 4, true, 4, false);
> -    t2.Access((char*)l.loc() + 4, true, 2, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 4, true, 4, false);
> -    t2.Access((char*)l.loc() + 6, true, 2, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 3, true, 2, false);
> -    t2.Access((char*)l.loc() + 4, true, 1, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 1, true, 8, false);
> -    t2.Access((char*)l.loc() + 3, true, 1, true);
> -  }
> -}
> -
> -TEST(ThreadSanitizer, RaceWithOffset2) {
> -  ScopedThread t1, t2;
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc(), true, 4, false);
> -    t2.Access((char*)l.loc() + 2, true, 1, true);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 2, true, 1, false);
> -    t2.Access((char*)l.loc(), true, 4, true);
> -  }
> -}
> -
> -TEST(ThreadSanitizer, NoRaceWithOffset) {
> -  ScopedThread t1, t2;
> -  {
> -    MemLoc l;
> -    t1.Access(l.loc(), true, 4, false);
> -    t2.Access((char*)l.loc() + 4, true, 4, false);
> -  }
> -  {
> -    MemLoc l;
> -    t1.Access((char*)l.loc() + 3, true, 2, false);
> -    t2.Access((char*)l.loc() + 1, true, 2, false);
> -    t2.Access((char*)l.loc() + 5, true, 2, false);
> -  }
> -}
> -
> -TEST(ThreadSanitizer, RaceWithDeadThread) {
> -  MemLoc l;
> -  ScopedThread t;
> -  ScopedThread().Write1(l);
> -  t.Write1(l, true);
> -}
> -
> -TEST(ThreadSanitizer, BenignRaceOnVptr) {
> -  void *vptr_storage;
> -  MemLoc vptr(&vptr_storage), val;
> -  vptr_storage = val.loc();
> -  ScopedThread t1, t2;
> -  t1.VptrUpdate(vptr, val);
> -  t2.Read8(vptr);
> -}
> -
> -TEST(ThreadSanitizer, HarmfulRaceOnVptr) {
> -  void *vptr_storage;
> -  MemLoc vptr(&vptr_storage), val1, val2;
> -  vptr_storage = val1.loc();
> -  ScopedThread t1, t2;
> -  t1.VptrUpdate(vptr, val2);
> -  t2.Read8(vptr, true);
> -}
> -
> -static void foo() {
> -  volatile int x = 42;
> -  int x2 = x;
> -  (void)x2;
> -}
> -
> -static void bar() {
> -  volatile int x = 43;
> -  int x2 = x;
> -  (void)x2;
> -}
> -
> -TEST(ThreadSanitizer, ReportDeadThread) {
> -  MemLoc l;
> -  ScopedThread t1;
> -  {
> -    ScopedThread t2;
> -    t2.Call(&foo);
> -    t2.Call(&bar);
> -    t2.Write1(l);
> -  }
> -  t1.Write1(l, true);
> -}
> -
> -struct ClassWithStatic {
> -  static int Data[4];
> -};
> -
> -int ClassWithStatic::Data[4];
> -
> -static void foobarbaz() {}
> -
> -TEST(ThreadSanitizer, ReportRace) {
> -  ScopedThread t1;
> -  MainThread().Access(&ClassWithStatic::Data, true, 4, false);
> -  t1.Call(&foobarbaz);
> -  t1.Access(&ClassWithStatic::Data, true, 2, true);
> -  t1.Return();
> -}
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mutex.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mutex.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mutex.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_mutex.cc (removed)
> @@ -1,221 +0,0 @@
> -//===-- tsan_mutex.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "sanitizer_common/sanitizer_atomic.h"
> -#include "tsan_interface.h"
> -#include "tsan_interface_ann.h"
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -#include <stdint.h>
> -
> -namespace __tsan {
> -
> -TEST(ThreadSanitizer, BasicMutex) {
> -  ScopedThread t;
> -  Mutex m;
> -  t.Create(m);
> -
> -  t.Lock(m);
> -  t.Unlock(m);
> -
> -  CHECK(t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.Lock(m);
> -  CHECK(!t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, BasicSpinMutex) {
> -  ScopedThread t;
> -  Mutex m(Mutex::Spin);
> -  t.Create(m);
> -
> -  t.Lock(m);
> -  t.Unlock(m);
> -
> -  CHECK(t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.Lock(m);
> -  CHECK(!t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, BasicRwMutex) {
> -  ScopedThread t;
> -  Mutex m(Mutex::RW);
> -  t.Create(m);
> -
> -  t.Lock(m);
> -  t.Unlock(m);
> -
> -  CHECK(t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.Lock(m);
> -  CHECK(!t.TryLock(m));
> -  t.Unlock(m);
> -
> -  t.ReadLock(m);
> -  t.ReadUnlock(m);
> -
> -  CHECK(t.TryReadLock(m));
> -  t.ReadUnlock(m);
> -
> -  t.Lock(m);
> -  CHECK(!t.TryReadLock(m));
> -  t.Unlock(m);
> -
> -  t.ReadLock(m);
> -  CHECK(!t.TryLock(m));
> -  t.ReadUnlock(m);
> -
> -  t.ReadLock(m);
> -  CHECK(t.TryReadLock(m));
> -  t.ReadUnlock(m);
> -  t.ReadUnlock(m);
> -
> -  t.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, Mutex) {
> -  Mutex m;
> -  MainThread t0;
> -  t0.Create(m);
> -
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Lock(m);
> -  t1.Write1(l);
> -  t1.Unlock(m);
> -  t2.Lock(m);
> -  t2.Write1(l);
> -  t2.Unlock(m);
> -  t2.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, SpinMutex) {
> -  Mutex m(Mutex::Spin);
> -  MainThread t0;
> -  t0.Create(m);
> -
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Lock(m);
> -  t1.Write1(l);
> -  t1.Unlock(m);
> -  t2.Lock(m);
> -  t2.Write1(l);
> -  t2.Unlock(m);
> -  t2.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, RwMutex) {
> -  Mutex m(Mutex::RW);
> -  MainThread t0;
> -  t0.Create(m);
> -
> -  ScopedThread t1, t2, t3;
> -  MemLoc l;
> -  t1.Lock(m);
> -  t1.Write1(l);
> -  t1.Unlock(m);
> -  t2.Lock(m);
> -  t2.Write1(l);
> -  t2.Unlock(m);
> -  t1.ReadLock(m);
> -  t3.ReadLock(m);
> -  t1.Read1(l);
> -  t3.Read1(l);
> -  t1.ReadUnlock(m);
> -  t3.ReadUnlock(m);
> -  t2.Lock(m);
> -  t2.Write1(l);
> -  t2.Unlock(m);
> -  t2.Destroy(m);
> -}
> -
> -TEST(ThreadSanitizer, StaticMutex) {
> -  // Emulates statically initialized mutex.
> -  Mutex m;
> -  m.StaticInit();
> -  {
> -    ScopedThread t1, t2;
> -    t1.Lock(m);
> -    t1.Unlock(m);
> -    t2.Lock(m);
> -    t2.Unlock(m);
> -  }
> -  MainThread().Destroy(m);
> -}
> -
> -static void *singleton_thread(void *param) {
> -  atomic_uintptr_t *singleton = (atomic_uintptr_t *)param;
> -  for (int i = 0; i < 4*1024*1024; i++) {
> -    int *val = (int *)atomic_load(singleton, memory_order_acquire);
> -    __tsan_acquire(singleton);
> -    __tsan_read4(val);
> -    CHECK_EQ(*val, 42);
> -  }
> -  return 0;
> -}
> -
> -TEST(DISABLED_BENCH_ThreadSanitizer, Singleton) {
> -  const int kClockSize = 100;
> -  const int kThreadCount = 8;
> -
> -  // Puff off thread's clock.
> -  for (int i = 0; i < kClockSize; i++) {
> -    ScopedThread t1;
> -    (void)t1;
> -  }
> -  // Create the singleton.
> -  int val = 42;
> -  __tsan_write4(&val);
> -  atomic_uintptr_t singleton;
> -  __tsan_release(&singleton);
> -  atomic_store(&singleton, (uintptr_t)&val, memory_order_release);
> -  // Create reader threads.
> -  pthread_t threads[kThreadCount];
> -  for (int t = 0; t < kThreadCount; t++)
> -    pthread_create(&threads[t], 0, singleton_thread, &singleton);
> -  for (int t = 0; t < kThreadCount; t++)
> -    pthread_join(threads[t], 0);
> -}
> -
> -TEST(DISABLED_BENCH_ThreadSanitizer, StopFlag) {
> -  const int kClockSize = 100;
> -  const int kIters = 16*1024*1024;
> -
> -  // Puff off thread's clock.
> -  for (int i = 0; i < kClockSize; i++) {
> -    ScopedThread t1;
> -    (void)t1;
> -  }
> -  // Create the stop flag.
> -  atomic_uintptr_t flag;
> -  __tsan_release(&flag);
> -  atomic_store(&flag, 0, memory_order_release);
> -  // Read it a lot.
> -  for (int i = 0; i < kIters; i++) {
> -    uptr v = atomic_load(&flag, memory_order_acquire);
> -    __tsan_acquire(&flag);
> -    CHECK_EQ(v, 0);
> -  }
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_posix.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_posix.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_posix.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_posix.cc (removed)
> @@ -1,146 +0,0 @@
> -//===-- tsan_posix.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_interface.h"
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -#include <pthread.h>
> -
> -struct thread_key {
> -  pthread_key_t key;
> -  pthread_mutex_t *mtx;
> -  int val;
> -  int *cnt;
> -  thread_key(pthread_key_t key, pthread_mutex_t *mtx, int val, int *cnt)
> -    : key(key)
> -    , mtx(mtx)
> -    , val(val)
> -    , cnt(cnt) {
> -  }
> -};
> -
> -static void thread_secific_dtor(void *v) {
> -  thread_key *k = (thread_key *)v;
> -  EXPECT_EQ(pthread_mutex_lock(k->mtx), 0);
> -  (*k->cnt)++;
> -  __tsan_write4(&k->cnt);
> -  EXPECT_EQ(pthread_mutex_unlock(k->mtx), 0);
> -  if (k->val == 42) {
> -    delete k;
> -  } else if (k->val == 43 || k->val == 44) {
> -    k->val--;
> -    EXPECT_EQ(pthread_setspecific(k->key, k), 0);
> -  } else {
> -    ASSERT_TRUE(false);
> -  }
> -}
> -
> -static void *dtors_thread(void *p) {
> -  thread_key *k = (thread_key *)p;
> -  EXPECT_EQ(pthread_setspecific(k->key, k), 0);
> -  return 0;
> -}
> -
> -TEST(Posix, ThreadSpecificDtors) {
> -  int cnt = 0;
> -  pthread_key_t key;
> -  EXPECT_EQ(pthread_key_create(&key, thread_secific_dtor), 0);
> -  pthread_mutex_t mtx;
> -  EXPECT_EQ(pthread_mutex_init(&mtx, 0), 0);
> -  pthread_t th[3];
> -  thread_key *k[3];
> -  k[0] = new thread_key(key, &mtx, 42, &cnt);
> -  k[1] = new thread_key(key, &mtx, 43, &cnt);
> -  k[2] = new thread_key(key, &mtx, 44, &cnt);
> -  EXPECT_EQ(pthread_create(&th[0], 0, dtors_thread, k[0]), 0);
> -  EXPECT_EQ(pthread_create(&th[1], 0, dtors_thread, k[1]), 0);
> -  EXPECT_EQ(pthread_join(th[0], 0), 0);
> -  EXPECT_EQ(pthread_create(&th[2], 0, dtors_thread, k[2]), 0);
> -  EXPECT_EQ(pthread_join(th[1], 0), 0);
> -  EXPECT_EQ(pthread_join(th[2], 0), 0);
> -  EXPECT_EQ(pthread_key_delete(key), 0);
> -  EXPECT_EQ(6, cnt);
> -}
> -
> -static __thread int local_var;
> -
> -static void *local_thread(void *p) {
> -  __tsan_write1(&local_var);
> -  __tsan_write1(&p);
> -  if (p == 0)
> -    return 0;
> -  const int kThreads = 4;
> -  pthread_t th[kThreads];
> -  for (int i = 0; i < kThreads; i++)
> -    EXPECT_EQ(pthread_create(&th[i], 0, local_thread,
> -              (void*)((long)p - 1)), 0);  // NOLINT
> -  for (int i = 0; i < kThreads; i++)
> -    EXPECT_EQ(pthread_join(th[i], 0), 0);
> -  return 0;
> -}
> -
> -TEST(Posix, ThreadLocalAccesses) {
> -  local_thread((void*)2);
> -}
> -
> -struct CondContext {
> -  pthread_mutex_t m;
> -  pthread_cond_t c;
> -  int data;
> -};
> -
> -static void *cond_thread(void *p) {
> -  CondContext &ctx = *static_cast<CondContext*>(p);
> -
> -  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> -  EXPECT_EQ(ctx.data, 0);
> -  ctx.data = 1;
> -  EXPECT_EQ(pthread_cond_signal(&ctx.c), 0);
> -  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> -
> -  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> -  while (ctx.data != 2)
> -    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> -  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> -
> -  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> -  ctx.data = 3;
> -  EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
> -  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> -
> -  return 0;
> -}
> -
> -TEST(Posix, CondBasic) {
> -  CondContext ctx;
> -  EXPECT_EQ(pthread_mutex_init(&ctx.m, 0), 0);
> -  EXPECT_EQ(pthread_cond_init(&ctx.c, 0), 0);
> -  ctx.data = 0;
> -  pthread_t th;
> -  EXPECT_EQ(pthread_create(&th, 0, cond_thread, &ctx), 0);
> -
> -  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> -  while (ctx.data != 1)
> -    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> -  ctx.data = 2;
> -  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> -  EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
> -
> -  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> -  while (ctx.data != 3)
> -    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> -  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> -
> -  EXPECT_EQ(pthread_join(th, 0), 0);
> -  EXPECT_EQ(pthread_cond_destroy(&ctx.c), 0);
> -  EXPECT_EQ(pthread_mutex_destroy(&ctx.m), 0);
> -}
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_string.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_string.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_string.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_string.cc (removed)
> @@ -1,82 +0,0 @@
> -//===-- tsan_string.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -#include <string.h>
> -
> -namespace __tsan {
> -
> -TEST(ThreadSanitizer, Memcpy) {
> -  char data0[7] = {1, 2, 3, 4, 5, 6, 7};
> -  char data[7] = {42, 42, 42, 42, 42, 42, 42};
> -  MainThread().Memcpy(data+1, data0+1, 5);
> -  EXPECT_EQ(data[0], 42);
> -  EXPECT_EQ(data[1], 2);
> -  EXPECT_EQ(data[2], 3);
> -  EXPECT_EQ(data[3], 4);
> -  EXPECT_EQ(data[4], 5);
> -  EXPECT_EQ(data[5], 6);
> -  EXPECT_EQ(data[6], 42);
> -  MainThread().Memset(data+1, 13, 5);
> -  EXPECT_EQ(data[0], 42);
> -  EXPECT_EQ(data[1], 13);
> -  EXPECT_EQ(data[2], 13);
> -  EXPECT_EQ(data[3], 13);
> -  EXPECT_EQ(data[4], 13);
> -  EXPECT_EQ(data[5], 13);
> -  EXPECT_EQ(data[6], 42);
> -}
> -
> -TEST(ThreadSanitizer, MemcpyRace1) {
> -  char *data = new char[10];
> -  char *data1 = new char[10];
> -  char *data2 = new char[10];
> -  ScopedThread t1, t2;
> -  t1.Memcpy(data, data1, 10);
> -  t2.Memcpy(data, data2, 10, true);
> -}
> -
> -TEST(ThreadSanitizer, MemcpyRace2) {
> -  char *data = new char[10];
> -  char *data1 = new char[10];
> -  char *data2 = new char[10];
> -  ScopedThread t1, t2;
> -  t1.Memcpy(data+5, data1, 1);
> -  t2.Memcpy(data+3, data2, 4, true);
> -}
> -
> -TEST(ThreadSanitizer, MemcpyRace3) {
> -  char *data = new char[10];
> -  char *data1 = new char[10];
> -  char *data2 = new char[10];
> -  ScopedThread t1, t2;
> -  t1.Memcpy(data, data1, 10);
> -  t2.Memcpy(data1, data2, 10, true);
> -}
> -
> -TEST(ThreadSanitizer, MemcpyStack) {
> -  char *data = new char[10];
> -  char *data1 = new char[10];
> -  ScopedThread t1, t2;
> -  t1.Memcpy(data, data1, 10);
> -  t2.Memcpy(data, data1, 10, true);
> -}
> -
> -TEST(ThreadSanitizer, MemsetRace1) {
> -  char *data = new char[10];
> -  ScopedThread t1, t2;
> -  t1.Memset(data, 1, 10);
> -  t2.Memset(data, 2, 10, true);
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test.cc (removed)
> @@ -1,44 +0,0 @@
> -//===-- tsan_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_interface.h"
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -
> -static void foo() {}
> -static void bar() {}
> -
> -TEST(ThreadSanitizer, FuncCall) {
> -  ScopedThread t1, t2;
> -  MemLoc l;
> -  t1.Write1(l);
> -  t2.Call(foo);
> -  t2.Call(bar);
> -  t2.Write1(l, true);
> -  t2.Return();
> -  t2.Return();
> -}
> -
> -int main(int argc, char **argv) {
> -  TestMutexBeforeInit();  // Mutexes must be usable before __tsan_init();
> -  __tsan_init();
> -  __tsan_func_entry(__builtin_return_address(0));
> -  __tsan_func_entry((char*)&main + 1);
> -
> -  testing::GTEST_FLAG(death_test_style) = "threadsafe";
> -  testing::InitGoogleTest(&argc, argv);
> -  int res = RUN_ALL_TESTS();
> -
> -  __tsan_func_exit();
> -  __tsan_func_exit();
> -  return res;
> -}
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util.h?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util.h (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util.h (removed)
> @@ -1,122 +0,0 @@
> -//===-- tsan_test_util.h ----------------------------------------*- C++ -*-===//
> -//
> -//                     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 ThreadSanitizer (TSan), a race detector.
> -//
> -// Test utils.
> -//===----------------------------------------------------------------------===//
> -#ifndef TSAN_TEST_UTIL_H
> -#define TSAN_TEST_UTIL_H
> -
> -void TestMutexBeforeInit();
> -
> -// A location of memory on which a race may be detected.
> -class MemLoc {
> - public:
> -  explicit MemLoc(int offset_from_aligned = 0);
> -  explicit MemLoc(void *const real_addr) : loc_(real_addr) { }
> -  ~MemLoc();
> -  void *loc() const { return loc_; }
> - private:
> -  void *const loc_;
> -  MemLoc(const MemLoc&);
> -  void operator = (const MemLoc&);
> -};
> -
> -class Mutex {
> - public:
> -  enum Type { Normal, Spin, RW };
> -
> -  explicit Mutex(Type type = Normal);
> -  ~Mutex();
> -
> -  void Init();
> -  void StaticInit();  // Emulates static initalization (tsan invisible).
> -  void Destroy();
> -  void Lock();
> -  bool TryLock();
> -  void Unlock();
> -  void ReadLock();
> -  bool TryReadLock();
> -  void ReadUnlock();
> -
> - private:
> -  // Placeholder for pthread_mutex_t, CRITICAL_SECTION or whatever.
> -  void *mtx_[128];
> -  bool alive_;
> -  const Type type_;
> -
> -  Mutex(const Mutex&);
> -  void operator = (const Mutex&);
> -};
> -
> -// A thread is started in CTOR and joined in DTOR.
> -class ScopedThread {
> - public:
> -  explicit ScopedThread(bool detached = false, bool main = false);
> -  ~ScopedThread();
> -  void Detach();
> -
> -  void Access(void *addr, bool is_write, int size, bool expect_race);
> -  void Read(const MemLoc &ml, int size, bool expect_race = false) {
> -    Access(ml.loc(), false, size, expect_race);
> -  }
> -  void Write(const MemLoc &ml, int size, bool expect_race = false) {
> -    Access(ml.loc(), true, size, expect_race);
> -  }
> -  void Read1(const MemLoc &ml, bool expect_race = false) {
> -    Read(ml, 1, expect_race); }
> -  void Read2(const MemLoc &ml, bool expect_race = false) {
> -    Read(ml, 2, expect_race); }
> -  void Read4(const MemLoc &ml, bool expect_race = false) {
> -    Read(ml, 4, expect_race); }
> -  void Read8(const MemLoc &ml, bool expect_race = false) {
> -    Read(ml, 8, expect_race); }
> -  void Write1(const MemLoc &ml, bool expect_race = false) {
> -    Write(ml, 1, expect_race); }
> -  void Write2(const MemLoc &ml, bool expect_race = false) {
> -    Write(ml, 2, expect_race); }
> -  void Write4(const MemLoc &ml, bool expect_race = false) {
> -    Write(ml, 4, expect_race); }
> -  void Write8(const MemLoc &ml, bool expect_race = false) {
> -    Write(ml, 8, expect_race); }
> -
> -  void VptrUpdate(const MemLoc &vptr, const MemLoc &new_val,
> -                  bool expect_race = false);
> -
> -  void Call(void(*pc)());
> -  void Return();
> -
> -  void Create(const Mutex &m);
> -  void Destroy(const Mutex &m);
> -  void Lock(const Mutex &m);
> -  bool TryLock(const Mutex &m);
> -  void Unlock(const Mutex &m);
> -  void ReadLock(const Mutex &m);
> -  bool TryReadLock(const Mutex &m);
> -  void ReadUnlock(const Mutex &m);
> -
> -  void Memcpy(void *dst, const void *src, int size, bool expect_race = false);
> -  void Memset(void *dst, int val, int size, bool expect_race = false);
> -
> - private:
> -  struct Impl;
> -  Impl *impl_;
> -  ScopedThread(const ScopedThread&);  // Not implemented.
> -  void operator = (const ScopedThread&);  // Not implemented.
> -};
> -
> -class MainThread : public ScopedThread {
> - public:
> -  MainThread()
> -    : ScopedThread(false, true) {
> -  }
> -};
> -
> -#endif  // #ifndef TSAN_TEST_UTIL_H
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_test_util_linux.cc (removed)
> @@ -1,465 +0,0 @@
> -
> -//===-- tsan_test_util_linux.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 ThreadSanitizer (TSan), a race detector.
> -//
> -// Test utils, linux implementation.
> -//===----------------------------------------------------------------------===//
> -
> -#include "sanitizer_common/sanitizer_atomic.h"
> -#include "tsan_interface.h"
> -#include "tsan_test_util.h"
> -#include "tsan_report.h"
> -
> -#include "gtest/gtest.h"
> -
> -#include <assert.h>
> -#include <pthread.h>
> -#include <stdio.h>
> -#include <stdint.h>
> -#include <string.h>
> -#include <unistd.h>
> -#include <errno.h>
> -
> -using namespace __tsan;  // NOLINT
> -
> -static __thread bool expect_report;
> -static __thread bool expect_report_reported;
> -static __thread ReportType expect_report_type;
> -
> -extern "C" void *__interceptor_memcpy(void*, const void*, uptr);
> -extern "C" void *__interceptor_memset(void*, int, uptr);
> -
> -static void *BeforeInitThread(void *param) {
> -  (void)param;
> -  return 0;
> -}
> -
> -static void AtExit() {
> -}
> -
> -void TestMutexBeforeInit() {
> -  // Mutexes must be usable before __tsan_init();
> -  pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
> -  pthread_mutex_lock(&mtx);
> -  pthread_mutex_unlock(&mtx);
> -  pthread_mutex_destroy(&mtx);
> -  pthread_t thr;
> -  pthread_create(&thr, 0, BeforeInitThread, 0);
> -  pthread_join(thr, 0);
> -  atexit(AtExit);
> -}
> -
> -namespace __tsan {
> -bool OnReport(const ReportDesc *rep, bool suppressed) {
> -  if (expect_report) {
> -    if (rep->typ != expect_report_type) {
> -      printf("Expected report of type %d, got type %d\n",
> -             (int)expect_report_type, (int)rep->typ);
> -      EXPECT_FALSE("Wrong report type");
> -      return false;
> -    }
> -  } else {
> -    EXPECT_FALSE("Unexpected report");
> -    return false;
> -  }
> -  expect_report_reported = true;
> -  return true;
> -}
> -}
> -
> -static void* allocate_addr(int size, int offset_from_aligned = 0) {
> -  static uintptr_t foo;
> -  static atomic_uintptr_t uniq = {(uintptr_t)&foo};  // Some real address.
> -  const int kAlign = 16;
> -  CHECK(offset_from_aligned < kAlign);
> -  size = (size + 2 * kAlign) & ~(kAlign - 1);
> -  uintptr_t addr = atomic_fetch_add(&uniq, size, memory_order_relaxed);
> -  return (void*)(addr + offset_from_aligned);
> -}
> -
> -MemLoc::MemLoc(int offset_from_aligned)
> -  : loc_(allocate_addr(16, offset_from_aligned)) {
> -}
> -
> -MemLoc::~MemLoc() {
> -}
> -
> -Mutex::Mutex(Type type)
> -  : alive_()
> -  , type_(type) {
> -}
> -
> -Mutex::~Mutex() {
> -  CHECK(!alive_);
> -}
> -
> -void Mutex::Init() {
> -  CHECK(!alive_);
> -  alive_ = true;
> -  if (type_ == Normal)
> -    CHECK_EQ(pthread_mutex_init((pthread_mutex_t*)mtx_, 0), 0);
> -  else if (type_ == Spin)
> -    CHECK_EQ(pthread_spin_init((pthread_spinlock_t*)mtx_, 0), 0);
> -  else if (type_ == RW)
> -    CHECK_EQ(pthread_rwlock_init((pthread_rwlock_t*)mtx_, 0), 0);
> -  else
> -    CHECK(0);
> -}
> -
> -void Mutex::StaticInit() {
> -  CHECK(!alive_);
> -  CHECK(type_ == Normal);
> -  alive_ = true;
> -  pthread_mutex_t tmp = PTHREAD_MUTEX_INITIALIZER;
> -  memcpy(mtx_, &tmp, sizeof(tmp));
> -}
> -
> -void Mutex::Destroy() {
> -  CHECK(alive_);
> -  alive_ = false;
> -  if (type_ == Normal)
> -    CHECK_EQ(pthread_mutex_destroy((pthread_mutex_t*)mtx_), 0);
> -  else if (type_ == Spin)
> -    CHECK_EQ(pthread_spin_destroy((pthread_spinlock_t*)mtx_), 0);
> -  else if (type_ == RW)
> -    CHECK_EQ(pthread_rwlock_destroy((pthread_rwlock_t*)mtx_), 0);
> -}
> -
> -void Mutex::Lock() {
> -  CHECK(alive_);
> -  if (type_ == Normal)
> -    CHECK_EQ(pthread_mutex_lock((pthread_mutex_t*)mtx_), 0);
> -  else if (type_ == Spin)
> -    CHECK_EQ(pthread_spin_lock((pthread_spinlock_t*)mtx_), 0);
> -  else if (type_ == RW)
> -    CHECK_EQ(pthread_rwlock_wrlock((pthread_rwlock_t*)mtx_), 0);
> -}
> -
> -bool Mutex::TryLock() {
> -  CHECK(alive_);
> -  if (type_ == Normal)
> -    return pthread_mutex_trylock((pthread_mutex_t*)mtx_) == 0;
> -  else if (type_ == Spin)
> -    return pthread_spin_trylock((pthread_spinlock_t*)mtx_) == 0;
> -  else if (type_ == RW)
> -    return pthread_rwlock_trywrlock((pthread_rwlock_t*)mtx_) == 0;
> -  return false;
> -}
> -
> -void Mutex::Unlock() {
> -  CHECK(alive_);
> -  if (type_ == Normal)
> -    CHECK_EQ(pthread_mutex_unlock((pthread_mutex_t*)mtx_), 0);
> -  else if (type_ == Spin)
> -    CHECK_EQ(pthread_spin_unlock((pthread_spinlock_t*)mtx_), 0);
> -  else if (type_ == RW)
> -    CHECK_EQ(pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
> -}
> -
> -void Mutex::ReadLock() {
> -  CHECK(alive_);
> -  CHECK(type_ == RW);
> -  CHECK_EQ(pthread_rwlock_rdlock((pthread_rwlock_t*)mtx_), 0);
> -}
> -
> -bool Mutex::TryReadLock() {
> -  CHECK(alive_);
> -  CHECK(type_ == RW);
> -  return pthread_rwlock_tryrdlock((pthread_rwlock_t*)mtx_) ==  0;
> -}
> -
> -void Mutex::ReadUnlock() {
> -  CHECK(alive_);
> -  CHECK(type_ == RW);
> -  CHECK_EQ(pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
> -}
> -
> -struct Event {
> -  enum Type {
> -    SHUTDOWN,
> -    READ,
> -    WRITE,
> -    VPTR_UPDATE,
> -    CALL,
> -    RETURN,
> -    MUTEX_CREATE,
> -    MUTEX_DESTROY,
> -    MUTEX_LOCK,
> -    MUTEX_TRYLOCK,
> -    MUTEX_UNLOCK,
> -    MUTEX_READLOCK,
> -    MUTEX_TRYREADLOCK,
> -    MUTEX_READUNLOCK,
> -    MEMCPY,
> -    MEMSET
> -  };
> -  Type type;
> -  void *ptr;
> -  uptr arg;
> -  uptr arg2;
> -  bool res;
> -  bool expect_report;
> -  ReportType report_type;
> -
> -  Event(Type type, const void *ptr = 0, uptr arg = 0, uptr arg2 = 0)
> -    : type(type)
> -    , ptr(const_cast<void*>(ptr))
> -    , arg(arg)
> -    , arg2(arg2)
> -    , res()
> -    , expect_report()
> -    , report_type() {
> -  }
> -
> -  void ExpectReport(ReportType type) {
> -    expect_report = true;
> -    report_type = type;
> -  }
> -};
> -
> -struct ScopedThread::Impl {
> -  pthread_t thread;
> -  bool main;
> -  bool detached;
> -  atomic_uintptr_t event;  // Event*
> -
> -  static void *ScopedThreadCallback(void *arg);
> -  void send(Event *ev);
> -  void HandleEvent(Event *ev);
> -};
> -
> -void ScopedThread::Impl::HandleEvent(Event *ev) {
> -  CHECK_EQ(expect_report, false);
> -  expect_report = ev->expect_report;
> -  expect_report_reported = false;
> -  expect_report_type = ev->report_type;
> -  switch (ev->type) {
> -  case Event::READ:
> -  case Event::WRITE: {
> -    void (*tsan_mop)(void *addr) = 0;
> -    if (ev->type == Event::READ) {
> -      switch (ev->arg /*size*/) {
> -        case 1: tsan_mop = __tsan_read1; break;
> -        case 2: tsan_mop = __tsan_read2; break;
> -        case 4: tsan_mop = __tsan_read4; break;
> -        case 8: tsan_mop = __tsan_read8; break;
> -        case 16: tsan_mop = __tsan_read16; break;
> -      }
> -    } else {
> -      switch (ev->arg /*size*/) {
> -        case 1: tsan_mop = __tsan_write1; break;
> -        case 2: tsan_mop = __tsan_write2; break;
> -        case 4: tsan_mop = __tsan_write4; break;
> -        case 8: tsan_mop = __tsan_write8; break;
> -        case 16: tsan_mop = __tsan_write16; break;
> -      }
> -    }
> -    CHECK_NE(tsan_mop, 0);
> -    errno = ECHRNG;
> -    tsan_mop(ev->ptr);
> -    CHECK_EQ(errno, ECHRNG);  // In no case must errno be changed.
> -    break;
> -  }
> -  case Event::VPTR_UPDATE:
> -    __tsan_vptr_update((void**)ev->ptr, (void*)ev->arg);
> -    break;
> -  case Event::CALL:
> -    __tsan_func_entry((void*)((uptr)ev->ptr));
> -    break;
> -  case Event::RETURN:
> -    __tsan_func_exit();
> -    break;
> -  case Event::MUTEX_CREATE:
> -    static_cast<Mutex*>(ev->ptr)->Init();
> -    break;
> -  case Event::MUTEX_DESTROY:
> -    static_cast<Mutex*>(ev->ptr)->Destroy();
> -    break;
> -  case Event::MUTEX_LOCK:
> -    static_cast<Mutex*>(ev->ptr)->Lock();
> -    break;
> -  case Event::MUTEX_TRYLOCK:
> -    ev->res = static_cast<Mutex*>(ev->ptr)->TryLock();
> -    break;
> -  case Event::MUTEX_UNLOCK:
> -    static_cast<Mutex*>(ev->ptr)->Unlock();
> -    break;
> -  case Event::MUTEX_READLOCK:
> -    static_cast<Mutex*>(ev->ptr)->ReadLock();
> -    break;
> -  case Event::MUTEX_TRYREADLOCK:
> -    ev->res = static_cast<Mutex*>(ev->ptr)->TryReadLock();
> -    break;
> -  case Event::MUTEX_READUNLOCK:
> -    static_cast<Mutex*>(ev->ptr)->ReadUnlock();
> -    break;
> -  case Event::MEMCPY:
> -    __interceptor_memcpy(ev->ptr, (void*)ev->arg, ev->arg2);
> -    break;
> -  case Event::MEMSET:
> -    __interceptor_memset(ev->ptr, ev->arg, ev->arg2);
> -    break;
> -  default: CHECK(0);
> -  }
> -  if (expect_report && !expect_report_reported) {
> -    printf("Missed expected report of type %d\n", (int)ev->report_type);
> -    EXPECT_FALSE("Missed expected race");
> -  }
> -  expect_report = false;
> -}
> -
> -void *ScopedThread::Impl::ScopedThreadCallback(void *arg) {
> -  __tsan_func_entry(__builtin_return_address(0));
> -  Impl *impl = (Impl*)arg;
> -  for (;;) {
> -    Event* ev = (Event*)atomic_load(&impl->event, memory_order_acquire);
> -    if (ev == 0) {
> -      pthread_yield();
> -      continue;
> -    }
> -    if (ev->type == Event::SHUTDOWN) {
> -      atomic_store(&impl->event, 0, memory_order_release);
> -      break;
> -    }
> -    impl->HandleEvent(ev);
> -    atomic_store(&impl->event, 0, memory_order_release);
> -  }
> -  __tsan_func_exit();
> -  return 0;
> -}
> -
> -void ScopedThread::Impl::send(Event *e) {
> -  if (main) {
> -    HandleEvent(e);
> -  } else {
> -    CHECK_EQ(atomic_load(&event, memory_order_relaxed), 0);
> -    atomic_store(&event, (uintptr_t)e, memory_order_release);
> -    while (atomic_load(&event, memory_order_acquire) != 0)
> -      pthread_yield();
> -  }
> -}
> -
> -ScopedThread::ScopedThread(bool detached, bool main) {
> -  impl_ = new Impl;
> -  impl_->main = main;
> -  impl_->detached = detached;
> -  atomic_store(&impl_->event, 0, memory_order_relaxed);
> -  if (!main) {
> -    pthread_attr_t attr;
> -    pthread_attr_init(&attr);
> -    pthread_attr_setdetachstate(&attr, detached);
> -    pthread_attr_setstacksize(&attr, 64*1024);
> -    pthread_create(&impl_->thread, &attr,
> -        ScopedThread::Impl::ScopedThreadCallback, impl_);
> -  }
> -}
> -
> -ScopedThread::~ScopedThread() {
> -  if (!impl_->main) {
> -    Event event(Event::SHUTDOWN);
> -    impl_->send(&event);
> -    if (!impl_->detached)
> -      pthread_join(impl_->thread, 0);
> -  }
> -  delete impl_;
> -}
> -
> -void ScopedThread::Detach() {
> -  CHECK(!impl_->main);
> -  CHECK(!impl_->detached);
> -  impl_->detached = true;
> -  pthread_detach(impl_->thread);
> -}
> -
> -void ScopedThread::Access(void *addr, bool is_write,
> -                          int size, bool expect_race) {
> -  Event event(is_write ? Event::WRITE : Event::READ, addr, size);
> -  if (expect_race)
> -    event.ExpectReport(ReportTypeRace);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::VptrUpdate(const MemLoc &vptr,
> -                              const MemLoc &new_val,
> -                              bool expect_race) {
> -  Event event(Event::VPTR_UPDATE, vptr.loc(), (uptr)new_val.loc());
> -  if (expect_race)
> -    event.ExpectReport(ReportTypeRace);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Call(void(*pc)()) {
> -  Event event(Event::CALL, (void*)pc);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Return() {
> -  Event event(Event::RETURN);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Create(const Mutex &m) {
> -  Event event(Event::MUTEX_CREATE, &m);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Destroy(const Mutex &m) {
> -  Event event(Event::MUTEX_DESTROY, &m);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Lock(const Mutex &m) {
> -  Event event(Event::MUTEX_LOCK, &m);
> -  impl_->send(&event);
> -}
> -
> -bool ScopedThread::TryLock(const Mutex &m) {
> -  Event event(Event::MUTEX_TRYLOCK, &m);
> -  impl_->send(&event);
> -  return event.res;
> -}
> -
> -void ScopedThread::Unlock(const Mutex &m) {
> -  Event event(Event::MUTEX_UNLOCK, &m);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::ReadLock(const Mutex &m) {
> -  Event event(Event::MUTEX_READLOCK, &m);
> -  impl_->send(&event);
> -}
> -
> -bool ScopedThread::TryReadLock(const Mutex &m) {
> -  Event event(Event::MUTEX_TRYREADLOCK, &m);
> -  impl_->send(&event);
> -  return event.res;
> -}
> -
> -void ScopedThread::ReadUnlock(const Mutex &m) {
> -  Event event(Event::MUTEX_READUNLOCK, &m);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Memcpy(void *dst, const void *src, int size,
> -                          bool expect_race) {
> -  Event event(Event::MEMCPY, dst, (uptr)src, size);
> -  if (expect_race)
> -    event.ExpectReport(ReportTypeRace);
> -  impl_->send(&event);
> -}
> -
> -void ScopedThread::Memset(void *dst, int val, int size,
> -                          bool expect_race) {
> -  Event event(Event::MEMSET, dst, val, size);
> -  if (expect_race)
> -    event.ExpectReport(ReportTypeRace);
> -  impl_->send(&event);
> -}
>
> Removed: compiler-rt/trunk/lib/tsan/rtl_tests/tsan_thread.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl_tests/tsan_thread.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/rtl_tests/tsan_thread.cc (original)
> +++ compiler-rt/trunk/lib/tsan/rtl_tests/tsan_thread.cc (removed)
> @@ -1,59 +0,0 @@
> -//===-- tsan_thread.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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_test_util.h"
> -#include "gtest/gtest.h"
> -
> -TEST(ThreadSanitizer, ThreadSync) {
> -  MainThread t0;
> -  MemLoc l;
> -  t0.Write1(l);
> -  {
> -    ScopedThread t1;
> -    t1.Write1(l);
> -  }
> -  t0.Write1(l);
> -}
> -
> -TEST(ThreadSanitizer, ThreadDetach1) {
> -  ScopedThread t1(true);
> -  MemLoc l;
> -  t1.Write1(l);
> -}
> -
> -TEST(ThreadSanitizer, ThreadDetach2) {
> -  ScopedThread t1;
> -  MemLoc l;
> -  t1.Write1(l);
> -  t1.Detach();
> -}
> -
> -static void *thread_alot_func(void *arg) {
> -  (void)arg;
> -  int usleep(unsigned);
> -  usleep(50);
> -  return 0;
> -}
> -
> -TEST(DISABLED_SLOW_ThreadSanitizer, ThreadALot) {
> -  const int kThreads = 70000;
> -  const int kAlive = 1000;
> -  pthread_t threads[kAlive] = {};
> -  for (int i = 0; i < kThreads; i++) {
> -    if (threads[i % kAlive])
> -      pthread_join(threads[i % kAlive], 0);
> -    pthread_create(&threads[i % kAlive], 0, thread_alot_func, 0);
> -  }
> -  for (int i = 0; i < kAlive; i++) {
> -    pthread_join(threads[i], 0);
> -  }
> -}
>
> Added: compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt (added)
> +++ compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,24 @@
> +include_directories(../rtl)
> +
> +add_custom_target(TsanUnitTests)
> +set_target_properties(TsanUnitTests PROPERTIES
> +  FOLDER "TSan unittests")
> +function(add_tsan_unittest testname)
> +  # Build unit tests only on 64-bit Linux.
> +  if(UNIX AND NOT APPLE
> +      AND CAN_TARGET_X86_64
> +      AND CMAKE_SIZEOF_VOID_P EQUAL 8
> +      AND NOT LLVM_BUILD_32_BITS)
> +    add_unittest(TsanUnitTests ${testname} ${ARGN})
> +    # Link with TSan runtime.
> +    target_link_libraries(${testname} clang_rt.tsan-x86_64)
> +    # Build tests with PIE and debug info.
> +    set_property(TARGET ${testname} APPEND_STRING
> +      PROPERTY COMPILE_FLAGS " -fPIE -g")
> +    set_property(TARGET ${testname} APPEND_STRING
> +      PROPERTY LINK_FLAGS " -pie")
> +  endif()
> +endfunction()
> +
> +add_subdirectory(rtl)
> +add_subdirectory(unit)
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/CMakeLists.txt Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,15 @@
> +set(TSAN_RTL_TESTS
> +  tsan_bench.cc
> +  tsan_mop.cc
> +  tsan_mutex.cc
> +  tsan_posix.cc
> +  tsan_string.cc
> +  tsan_test.cc
> +  tsan_thread.cc
> +  )
> +
> +if(UNIX AND NOT APPLE)
> +  list(APPEND TSAN_RTL_TESTS tsan_test_util_linux.cc)
> +endif()
> +
> +add_tsan_unittest(TsanRtlTest ${TSAN_RTL_TESTS})
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_bench.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_bench.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_bench.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_bench.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,105 @@
> +//===-- tsan_bench.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_test_util.h"
> +#include "tsan_interface.h"
> +#include "tsan_defs.h"
> +#include "gtest/gtest.h"
> +#include <stdint.h>
> +
> +const int kSize = 128;
> +const int kRepeat = 2*1024*1024;
> +
> +void noinstr(void *p) {}
> +
> +template<typename T, void(*__tsan_mop)(void *p)>
> +static void Benchmark() {
> +  volatile T data[kSize];
> +  for (int i = 0; i < kRepeat; i++) {
> +    for (int j = 0; j < kSize; j++) {
> +      __tsan_mop((void*)&data[j]);
> +      data[j]++;
> +    }
> +  }
> +}
> +
> +TEST(DISABLED_BENCH, Mop1) {
> +  Benchmark<uint8_t, noinstr>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop1Read) {
> +  Benchmark<uint8_t, __tsan_read1>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop1Write) {
> +  Benchmark<uint8_t, __tsan_write1>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop2) {
> +  Benchmark<uint16_t, noinstr>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop2Read) {
> +  Benchmark<uint16_t, __tsan_read2>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop2Write) {
> +  Benchmark<uint16_t, __tsan_write2>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop4) {
> +  Benchmark<uint32_t, noinstr>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop4Read) {
> +  Benchmark<uint32_t, __tsan_read4>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop4Write) {
> +  Benchmark<uint32_t, __tsan_write4>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop8) {
> +  Benchmark<uint8_t, noinstr>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop8Read) {
> +  Benchmark<uint64_t, __tsan_read8>();
> +}
> +
> +TEST(DISABLED_BENCH, Mop8Write) {
> +  Benchmark<uint64_t, __tsan_write8>();
> +}
> +
> +TEST(DISABLED_BENCH, FuncCall) {
> +  for (int i = 0; i < kRepeat; i++) {
> +    for (int j = 0; j < kSize; j++)
> +      __tsan_func_entry((void*)(uintptr_t)j);
> +    for (int j = 0; j < kSize; j++)
> +      __tsan_func_exit();
> +  }
> +}
> +
> +TEST(DISABLED_BENCH, MutexLocal) {
> +  Mutex m;
> +  ScopedThread().Create(m);
> +  for (int i = 0; i < 50; i++) {
> +    ScopedThread t;
> +    t.Lock(m);
> +    t.Unlock(m);
> +  }
> +  for (int i = 0; i < 16*1024*1024; i++) {
> +    m.Lock();
> +    m.Unlock();
> +  }
> +  ScopedThread().Destroy(m);
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mop.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mop.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mop.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mop.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,233 @@
> +//===-- tsan_mop.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_interface.h"
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +#include <stddef.h>
> +#include <stdint.h>
> +
> +TEST(ThreadSanitizer, SimpleWrite) {
> +  ScopedThread t;
> +  MemLoc l;
> +  t.Write1(l);
> +}
> +
> +TEST(ThreadSanitizer, SimpleWriteWrite) {
> +  ScopedThread t1, t2;
> +  MemLoc l1, l2;
> +  t1.Write1(l1);
> +  t2.Write1(l2);
> +}
> +
> +TEST(ThreadSanitizer, WriteWriteRace) {
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Write1(l);
> +  t2.Write1(l, true);
> +}
> +
> +TEST(ThreadSanitizer, ReadWriteRace) {
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Read1(l);
> +  t2.Write1(l, true);
> +}
> +
> +TEST(ThreadSanitizer, WriteReadRace) {
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Write1(l);
> +  t2.Read1(l, true);
> +}
> +
> +TEST(ThreadSanitizer, ReadReadNoRace) {
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Read1(l);
> +  t2.Read1(l);
> +}
> +
> +TEST(ThreadSanitizer, WriteThenRead) {
> +  MemLoc l;
> +  ScopedThread t1, t2;
> +  t1.Write1(l);
> +  t1.Read1(l);
> +  t2.Read1(l, true);
> +}
> +
> +TEST(ThreadSanitizer, WriteThenLockedRead) {
> +  Mutex m(Mutex::RW);
> +  MainThread t0;
> +  t0.Create(m);
> +  MemLoc l;
> +  {
> +    ScopedThread t1, t2;
> +
> +    t1.Write8(l);
> +
> +    t1.Lock(m);
> +    t1.Read8(l);
> +    t1.Unlock(m);
> +
> +    t2.Read8(l, true);
> +  }
> +  t0.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, LockedWriteThenRead) {
> +  Mutex m(Mutex::RW);
> +  MainThread t0;
> +  t0.Create(m);
> +  MemLoc l;
> +  {
> +    ScopedThread t1, t2;
> +
> +    t1.Lock(m);
> +    t1.Write8(l);
> +    t1.Unlock(m);
> +
> +    t1.Read8(l);
> +
> +    t2.Read8(l, true);
> +  }
> +  t0.Destroy(m);
> +}
> +
> +
> +TEST(ThreadSanitizer, RaceWithOffset) {
> +  ScopedThread t1, t2;
> +  {
> +    MemLoc l;
> +    t1.Access(l.loc(), true, 8, false);
> +    t2.Access((char*)l.loc() + 4, true, 4, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access(l.loc(), true, 8, false);
> +    t2.Access((char*)l.loc() + 7, true, 1, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 4, true, 4, false);
> +    t2.Access((char*)l.loc() + 4, true, 2, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 4, true, 4, false);
> +    t2.Access((char*)l.loc() + 6, true, 2, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 3, true, 2, false);
> +    t2.Access((char*)l.loc() + 4, true, 1, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 1, true, 8, false);
> +    t2.Access((char*)l.loc() + 3, true, 1, true);
> +  }
> +}
> +
> +TEST(ThreadSanitizer, RaceWithOffset2) {
> +  ScopedThread t1, t2;
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc(), true, 4, false);
> +    t2.Access((char*)l.loc() + 2, true, 1, true);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 2, true, 1, false);
> +    t2.Access((char*)l.loc(), true, 4, true);
> +  }
> +}
> +
> +TEST(ThreadSanitizer, NoRaceWithOffset) {
> +  ScopedThread t1, t2;
> +  {
> +    MemLoc l;
> +    t1.Access(l.loc(), true, 4, false);
> +    t2.Access((char*)l.loc() + 4, true, 4, false);
> +  }
> +  {
> +    MemLoc l;
> +    t1.Access((char*)l.loc() + 3, true, 2, false);
> +    t2.Access((char*)l.loc() + 1, true, 2, false);
> +    t2.Access((char*)l.loc() + 5, true, 2, false);
> +  }
> +}
> +
> +TEST(ThreadSanitizer, RaceWithDeadThread) {
> +  MemLoc l;
> +  ScopedThread t;
> +  ScopedThread().Write1(l);
> +  t.Write1(l, true);
> +}
> +
> +TEST(ThreadSanitizer, BenignRaceOnVptr) {
> +  void *vptr_storage;
> +  MemLoc vptr(&vptr_storage), val;
> +  vptr_storage = val.loc();
> +  ScopedThread t1, t2;
> +  t1.VptrUpdate(vptr, val);
> +  t2.Read8(vptr);
> +}
> +
> +TEST(ThreadSanitizer, HarmfulRaceOnVptr) {
> +  void *vptr_storage;
> +  MemLoc vptr(&vptr_storage), val1, val2;
> +  vptr_storage = val1.loc();
> +  ScopedThread t1, t2;
> +  t1.VptrUpdate(vptr, val2);
> +  t2.Read8(vptr, true);
> +}
> +
> +static void foo() {
> +  volatile int x = 42;
> +  int x2 = x;
> +  (void)x2;
> +}
> +
> +static void bar() {
> +  volatile int x = 43;
> +  int x2 = x;
> +  (void)x2;
> +}
> +
> +TEST(ThreadSanitizer, ReportDeadThread) {
> +  MemLoc l;
> +  ScopedThread t1;
> +  {
> +    ScopedThread t2;
> +    t2.Call(&foo);
> +    t2.Call(&bar);
> +    t2.Write1(l);
> +  }
> +  t1.Write1(l, true);
> +}
> +
> +struct ClassWithStatic {
> +  static int Data[4];
> +};
> +
> +int ClassWithStatic::Data[4];
> +
> +static void foobarbaz() {}
> +
> +TEST(ThreadSanitizer, ReportRace) {
> +  ScopedThread t1;
> +  MainThread().Access(&ClassWithStatic::Data, true, 4, false);
> +  t1.Call(&foobarbaz);
> +  t1.Access(&ClassWithStatic::Data, true, 2, true);
> +  t1.Return();
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mutex.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mutex.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mutex.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_mutex.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,221 @@
> +//===-- tsan_mutex.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "sanitizer_common/sanitizer_atomic.h"
> +#include "tsan_interface.h"
> +#include "tsan_interface_ann.h"
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +#include <stdint.h>
> +
> +namespace __tsan {
> +
> +TEST(ThreadSanitizer, BasicMutex) {
> +  ScopedThread t;
> +  Mutex m;
> +  t.Create(m);
> +
> +  t.Lock(m);
> +  t.Unlock(m);
> +
> +  CHECK(t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.Lock(m);
> +  CHECK(!t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, BasicSpinMutex) {
> +  ScopedThread t;
> +  Mutex m(Mutex::Spin);
> +  t.Create(m);
> +
> +  t.Lock(m);
> +  t.Unlock(m);
> +
> +  CHECK(t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.Lock(m);
> +  CHECK(!t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, BasicRwMutex) {
> +  ScopedThread t;
> +  Mutex m(Mutex::RW);
> +  t.Create(m);
> +
> +  t.Lock(m);
> +  t.Unlock(m);
> +
> +  CHECK(t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.Lock(m);
> +  CHECK(!t.TryLock(m));
> +  t.Unlock(m);
> +
> +  t.ReadLock(m);
> +  t.ReadUnlock(m);
> +
> +  CHECK(t.TryReadLock(m));
> +  t.ReadUnlock(m);
> +
> +  t.Lock(m);
> +  CHECK(!t.TryReadLock(m));
> +  t.Unlock(m);
> +
> +  t.ReadLock(m);
> +  CHECK(!t.TryLock(m));
> +  t.ReadUnlock(m);
> +
> +  t.ReadLock(m);
> +  CHECK(t.TryReadLock(m));
> +  t.ReadUnlock(m);
> +  t.ReadUnlock(m);
> +
> +  t.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, Mutex) {
> +  Mutex m;
> +  MainThread t0;
> +  t0.Create(m);
> +
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Lock(m);
> +  t1.Write1(l);
> +  t1.Unlock(m);
> +  t2.Lock(m);
> +  t2.Write1(l);
> +  t2.Unlock(m);
> +  t2.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, SpinMutex) {
> +  Mutex m(Mutex::Spin);
> +  MainThread t0;
> +  t0.Create(m);
> +
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Lock(m);
> +  t1.Write1(l);
> +  t1.Unlock(m);
> +  t2.Lock(m);
> +  t2.Write1(l);
> +  t2.Unlock(m);
> +  t2.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, RwMutex) {
> +  Mutex m(Mutex::RW);
> +  MainThread t0;
> +  t0.Create(m);
> +
> +  ScopedThread t1, t2, t3;
> +  MemLoc l;
> +  t1.Lock(m);
> +  t1.Write1(l);
> +  t1.Unlock(m);
> +  t2.Lock(m);
> +  t2.Write1(l);
> +  t2.Unlock(m);
> +  t1.ReadLock(m);
> +  t3.ReadLock(m);
> +  t1.Read1(l);
> +  t3.Read1(l);
> +  t1.ReadUnlock(m);
> +  t3.ReadUnlock(m);
> +  t2.Lock(m);
> +  t2.Write1(l);
> +  t2.Unlock(m);
> +  t2.Destroy(m);
> +}
> +
> +TEST(ThreadSanitizer, StaticMutex) {
> +  // Emulates statically initialized mutex.
> +  Mutex m;
> +  m.StaticInit();
> +  {
> +    ScopedThread t1, t2;
> +    t1.Lock(m);
> +    t1.Unlock(m);
> +    t2.Lock(m);
> +    t2.Unlock(m);
> +  }
> +  MainThread().Destroy(m);
> +}
> +
> +static void *singleton_thread(void *param) {
> +  atomic_uintptr_t *singleton = (atomic_uintptr_t *)param;
> +  for (int i = 0; i < 4*1024*1024; i++) {
> +    int *val = (int *)atomic_load(singleton, memory_order_acquire);
> +    __tsan_acquire(singleton);
> +    __tsan_read4(val);
> +    CHECK_EQ(*val, 42);
> +  }
> +  return 0;
> +}
> +
> +TEST(DISABLED_BENCH_ThreadSanitizer, Singleton) {
> +  const int kClockSize = 100;
> +  const int kThreadCount = 8;
> +
> +  // Puff off thread's clock.
> +  for (int i = 0; i < kClockSize; i++) {
> +    ScopedThread t1;
> +    (void)t1;
> +  }
> +  // Create the singleton.
> +  int val = 42;
> +  __tsan_write4(&val);
> +  atomic_uintptr_t singleton;
> +  __tsan_release(&singleton);
> +  atomic_store(&singleton, (uintptr_t)&val, memory_order_release);
> +  // Create reader threads.
> +  pthread_t threads[kThreadCount];
> +  for (int t = 0; t < kThreadCount; t++)
> +    pthread_create(&threads[t], 0, singleton_thread, &singleton);
> +  for (int t = 0; t < kThreadCount; t++)
> +    pthread_join(threads[t], 0);
> +}
> +
> +TEST(DISABLED_BENCH_ThreadSanitizer, StopFlag) {
> +  const int kClockSize = 100;
> +  const int kIters = 16*1024*1024;
> +
> +  // Puff off thread's clock.
> +  for (int i = 0; i < kClockSize; i++) {
> +    ScopedThread t1;
> +    (void)t1;
> +  }
> +  // Create the stop flag.
> +  atomic_uintptr_t flag;
> +  __tsan_release(&flag);
> +  atomic_store(&flag, 0, memory_order_release);
> +  // Read it a lot.
> +  for (int i = 0; i < kIters; i++) {
> +    uptr v = atomic_load(&flag, memory_order_acquire);
> +    __tsan_acquire(&flag);
> +    CHECK_EQ(v, 0);
> +  }
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_posix.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_posix.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_posix.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_posix.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,146 @@
> +//===-- tsan_posix.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_interface.h"
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +#include <pthread.h>
> +
> +struct thread_key {
> +  pthread_key_t key;
> +  pthread_mutex_t *mtx;
> +  int val;
> +  int *cnt;
> +  thread_key(pthread_key_t key, pthread_mutex_t *mtx, int val, int *cnt)
> +    : key(key)
> +    , mtx(mtx)
> +    , val(val)
> +    , cnt(cnt) {
> +  }
> +};
> +
> +static void thread_secific_dtor(void *v) {
> +  thread_key *k = (thread_key *)v;
> +  EXPECT_EQ(pthread_mutex_lock(k->mtx), 0);
> +  (*k->cnt)++;
> +  __tsan_write4(&k->cnt);
> +  EXPECT_EQ(pthread_mutex_unlock(k->mtx), 0);
> +  if (k->val == 42) {
> +    delete k;
> +  } else if (k->val == 43 || k->val == 44) {
> +    k->val--;
> +    EXPECT_EQ(pthread_setspecific(k->key, k), 0);
> +  } else {
> +    ASSERT_TRUE(false);
> +  }
> +}
> +
> +static void *dtors_thread(void *p) {
> +  thread_key *k = (thread_key *)p;
> +  EXPECT_EQ(pthread_setspecific(k->key, k), 0);
> +  return 0;
> +}
> +
> +TEST(Posix, ThreadSpecificDtors) {
> +  int cnt = 0;
> +  pthread_key_t key;
> +  EXPECT_EQ(pthread_key_create(&key, thread_secific_dtor), 0);
> +  pthread_mutex_t mtx;
> +  EXPECT_EQ(pthread_mutex_init(&mtx, 0), 0);
> +  pthread_t th[3];
> +  thread_key *k[3];
> +  k[0] = new thread_key(key, &mtx, 42, &cnt);
> +  k[1] = new thread_key(key, &mtx, 43, &cnt);
> +  k[2] = new thread_key(key, &mtx, 44, &cnt);
> +  EXPECT_EQ(pthread_create(&th[0], 0, dtors_thread, k[0]), 0);
> +  EXPECT_EQ(pthread_create(&th[1], 0, dtors_thread, k[1]), 0);
> +  EXPECT_EQ(pthread_join(th[0], 0), 0);
> +  EXPECT_EQ(pthread_create(&th[2], 0, dtors_thread, k[2]), 0);
> +  EXPECT_EQ(pthread_join(th[1], 0), 0);
> +  EXPECT_EQ(pthread_join(th[2], 0), 0);
> +  EXPECT_EQ(pthread_key_delete(key), 0);
> +  EXPECT_EQ(6, cnt);
> +}
> +
> +static __thread int local_var;
> +
> +static void *local_thread(void *p) {
> +  __tsan_write1(&local_var);
> +  __tsan_write1(&p);
> +  if (p == 0)
> +    return 0;
> +  const int kThreads = 4;
> +  pthread_t th[kThreads];
> +  for (int i = 0; i < kThreads; i++)
> +    EXPECT_EQ(pthread_create(&th[i], 0, local_thread,
> +              (void*)((long)p - 1)), 0);  // NOLINT
> +  for (int i = 0; i < kThreads; i++)
> +    EXPECT_EQ(pthread_join(th[i], 0), 0);
> +  return 0;
> +}
> +
> +TEST(Posix, ThreadLocalAccesses) {
> +  local_thread((void*)2);
> +}
> +
> +struct CondContext {
> +  pthread_mutex_t m;
> +  pthread_cond_t c;
> +  int data;
> +};
> +
> +static void *cond_thread(void *p) {
> +  CondContext &ctx = *static_cast<CondContext*>(p);
> +
> +  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> +  EXPECT_EQ(ctx.data, 0);
> +  ctx.data = 1;
> +  EXPECT_EQ(pthread_cond_signal(&ctx.c), 0);
> +  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> +
> +  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> +  while (ctx.data != 2)
> +    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> +  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> +
> +  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> +  ctx.data = 3;
> +  EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
> +  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> +
> +  return 0;
> +}
> +
> +TEST(Posix, CondBasic) {
> +  CondContext ctx;
> +  EXPECT_EQ(pthread_mutex_init(&ctx.m, 0), 0);
> +  EXPECT_EQ(pthread_cond_init(&ctx.c, 0), 0);
> +  ctx.data = 0;
> +  pthread_t th;
> +  EXPECT_EQ(pthread_create(&th, 0, cond_thread, &ctx), 0);
> +
> +  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> +  while (ctx.data != 1)
> +    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> +  ctx.data = 2;
> +  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> +  EXPECT_EQ(pthread_cond_broadcast(&ctx.c), 0);
> +
> +  EXPECT_EQ(pthread_mutex_lock(&ctx.m), 0);
> +  while (ctx.data != 3)
> +    EXPECT_EQ(pthread_cond_wait(&ctx.c, &ctx.m), 0);
> +  EXPECT_EQ(pthread_mutex_unlock(&ctx.m), 0);
> +
> +  EXPECT_EQ(pthread_join(th, 0), 0);
> +  EXPECT_EQ(pthread_cond_destroy(&ctx.c), 0);
> +  EXPECT_EQ(pthread_mutex_destroy(&ctx.m), 0);
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_string.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_string.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_string.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_string.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,82 @@
> +//===-- tsan_string.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +#include <string.h>
> +
> +namespace __tsan {
> +
> +TEST(ThreadSanitizer, Memcpy) {
> +  char data0[7] = {1, 2, 3, 4, 5, 6, 7};
> +  char data[7] = {42, 42, 42, 42, 42, 42, 42};
> +  MainThread().Memcpy(data+1, data0+1, 5);
> +  EXPECT_EQ(data[0], 42);
> +  EXPECT_EQ(data[1], 2);
> +  EXPECT_EQ(data[2], 3);
> +  EXPECT_EQ(data[3], 4);
> +  EXPECT_EQ(data[4], 5);
> +  EXPECT_EQ(data[5], 6);
> +  EXPECT_EQ(data[6], 42);
> +  MainThread().Memset(data+1, 13, 5);
> +  EXPECT_EQ(data[0], 42);
> +  EXPECT_EQ(data[1], 13);
> +  EXPECT_EQ(data[2], 13);
> +  EXPECT_EQ(data[3], 13);
> +  EXPECT_EQ(data[4], 13);
> +  EXPECT_EQ(data[5], 13);
> +  EXPECT_EQ(data[6], 42);
> +}
> +
> +TEST(ThreadSanitizer, MemcpyRace1) {
> +  char *data = new char[10];
> +  char *data1 = new char[10];
> +  char *data2 = new char[10];
> +  ScopedThread t1, t2;
> +  t1.Memcpy(data, data1, 10);
> +  t2.Memcpy(data, data2, 10, true);
> +}
> +
> +TEST(ThreadSanitizer, MemcpyRace2) {
> +  char *data = new char[10];
> +  char *data1 = new char[10];
> +  char *data2 = new char[10];
> +  ScopedThread t1, t2;
> +  t1.Memcpy(data+5, data1, 1);
> +  t2.Memcpy(data+3, data2, 4, true);
> +}
> +
> +TEST(ThreadSanitizer, MemcpyRace3) {
> +  char *data = new char[10];
> +  char *data1 = new char[10];
> +  char *data2 = new char[10];
> +  ScopedThread t1, t2;
> +  t1.Memcpy(data, data1, 10);
> +  t2.Memcpy(data1, data2, 10, true);
> +}
> +
> +TEST(ThreadSanitizer, MemcpyStack) {
> +  char *data = new char[10];
> +  char *data1 = new char[10];
> +  ScopedThread t1, t2;
> +  t1.Memcpy(data, data1, 10);
> +  t2.Memcpy(data, data1, 10, true);
> +}
> +
> +TEST(ThreadSanitizer, MemsetRace1) {
> +  char *data = new char[10];
> +  ScopedThread t1, t2;
> +  t1.Memset(data, 1, 10);
> +  t2.Memset(data, 2, 10, true);
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,44 @@
> +//===-- tsan_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_interface.h"
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +
> +static void foo() {}
> +static void bar() {}
> +
> +TEST(ThreadSanitizer, FuncCall) {
> +  ScopedThread t1, t2;
> +  MemLoc l;
> +  t1.Write1(l);
> +  t2.Call(foo);
> +  t2.Call(bar);
> +  t2.Write1(l, true);
> +  t2.Return();
> +  t2.Return();
> +}
> +
> +int main(int argc, char **argv) {
> +  TestMutexBeforeInit();  // Mutexes must be usable before __tsan_init();
> +  __tsan_init();
> +  __tsan_func_entry(__builtin_return_address(0));
> +  __tsan_func_entry((char*)&main + 1);

This seems to break the CMake build:

llvm/projects/compiler-rt/lib/tsan/tests/rtl/tsan_test.cc:35:21:
error: cast between pointer-to-function and pointer-to-object is an
extension [-Werror,-Wpedantic]
  __tsan_func_entry((char*)&main + 1);
                    ^~~~~~~~~~~~
1 error generated.

I'm not sure what, if anything, is the right fix for this.

> +
> +  testing::GTEST_FLAG(death_test_style) = "threadsafe";
> +  testing::InitGoogleTest(&argc, argv);
> +  int res = RUN_ALL_TESTS();
> +
> +  __tsan_func_exit();
> +  __tsan_func_exit();
> +  return res;
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util.h
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util.h?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util.h (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util.h Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,122 @@
> +//===-- tsan_test_util.h ----------------------------------------*- C++ -*-===//
> +//
> +//                     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 ThreadSanitizer (TSan), a race detector.
> +//
> +// Test utils.
> +//===----------------------------------------------------------------------===//
> +#ifndef TSAN_TEST_UTIL_H
> +#define TSAN_TEST_UTIL_H
> +
> +void TestMutexBeforeInit();
> +
> +// A location of memory on which a race may be detected.
> +class MemLoc {
> + public:
> +  explicit MemLoc(int offset_from_aligned = 0);
> +  explicit MemLoc(void *const real_addr) : loc_(real_addr) { }
> +  ~MemLoc();
> +  void *loc() const { return loc_; }
> + private:
> +  void *const loc_;
> +  MemLoc(const MemLoc&);
> +  void operator = (const MemLoc&);
> +};
> +
> +class Mutex {
> + public:
> +  enum Type { Normal, Spin, RW };
> +
> +  explicit Mutex(Type type = Normal);
> +  ~Mutex();
> +
> +  void Init();
> +  void StaticInit();  // Emulates static initalization (tsan invisible).
> +  void Destroy();
> +  void Lock();
> +  bool TryLock();
> +  void Unlock();
> +  void ReadLock();
> +  bool TryReadLock();
> +  void ReadUnlock();
> +
> + private:
> +  // Placeholder for pthread_mutex_t, CRITICAL_SECTION or whatever.
> +  void *mtx_[128];
> +  bool alive_;
> +  const Type type_;
> +
> +  Mutex(const Mutex&);
> +  void operator = (const Mutex&);
> +};
> +
> +// A thread is started in CTOR and joined in DTOR.
> +class ScopedThread {
> + public:
> +  explicit ScopedThread(bool detached = false, bool main = false);
> +  ~ScopedThread();
> +  void Detach();
> +
> +  void Access(void *addr, bool is_write, int size, bool expect_race);
> +  void Read(const MemLoc &ml, int size, bool expect_race = false) {
> +    Access(ml.loc(), false, size, expect_race);
> +  }
> +  void Write(const MemLoc &ml, int size, bool expect_race = false) {
> +    Access(ml.loc(), true, size, expect_race);
> +  }
> +  void Read1(const MemLoc &ml, bool expect_race = false) {
> +    Read(ml, 1, expect_race); }
> +  void Read2(const MemLoc &ml, bool expect_race = false) {
> +    Read(ml, 2, expect_race); }
> +  void Read4(const MemLoc &ml, bool expect_race = false) {
> +    Read(ml, 4, expect_race); }
> +  void Read8(const MemLoc &ml, bool expect_race = false) {
> +    Read(ml, 8, expect_race); }
> +  void Write1(const MemLoc &ml, bool expect_race = false) {
> +    Write(ml, 1, expect_race); }
> +  void Write2(const MemLoc &ml, bool expect_race = false) {
> +    Write(ml, 2, expect_race); }
> +  void Write4(const MemLoc &ml, bool expect_race = false) {
> +    Write(ml, 4, expect_race); }
> +  void Write8(const MemLoc &ml, bool expect_race = false) {
> +    Write(ml, 8, expect_race); }
> +
> +  void VptrUpdate(const MemLoc &vptr, const MemLoc &new_val,
> +                  bool expect_race = false);
> +
> +  void Call(void(*pc)());
> +  void Return();
> +
> +  void Create(const Mutex &m);
> +  void Destroy(const Mutex &m);
> +  void Lock(const Mutex &m);
> +  bool TryLock(const Mutex &m);
> +  void Unlock(const Mutex &m);
> +  void ReadLock(const Mutex &m);
> +  bool TryReadLock(const Mutex &m);
> +  void ReadUnlock(const Mutex &m);
> +
> +  void Memcpy(void *dst, const void *src, int size, bool expect_race = false);
> +  void Memset(void *dst, int val, int size, bool expect_race = false);
> +
> + private:
> +  struct Impl;
> +  Impl *impl_;
> +  ScopedThread(const ScopedThread&);  // Not implemented.
> +  void operator = (const ScopedThread&);  // Not implemented.
> +};
> +
> +class MainThread : public ScopedThread {
> + public:
> +  MainThread()
> +    : ScopedThread(false, true) {
> +  }
> +};
> +
> +#endif  // #ifndef TSAN_TEST_UTIL_H
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_linux.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_linux.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_linux.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_test_util_linux.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,465 @@
> +
> +//===-- tsan_test_util_linux.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 ThreadSanitizer (TSan), a race detector.
> +//
> +// Test utils, linux implementation.
> +//===----------------------------------------------------------------------===//
> +
> +#include "sanitizer_common/sanitizer_atomic.h"
> +#include "tsan_interface.h"
> +#include "tsan_test_util.h"
> +#include "tsan_report.h"
> +
> +#include "gtest/gtest.h"
> +
> +#include <assert.h>
> +#include <pthread.h>
> +#include <stdio.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +
> +using namespace __tsan;  // NOLINT
> +
> +static __thread bool expect_report;
> +static __thread bool expect_report_reported;
> +static __thread ReportType expect_report_type;
> +
> +extern "C" void *__interceptor_memcpy(void*, const void*, uptr);
> +extern "C" void *__interceptor_memset(void*, int, uptr);
> +
> +static void *BeforeInitThread(void *param) {
> +  (void)param;
> +  return 0;
> +}
> +
> +static void AtExit() {
> +}
> +
> +void TestMutexBeforeInit() {
> +  // Mutexes must be usable before __tsan_init();
> +  pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
> +  pthread_mutex_lock(&mtx);
> +  pthread_mutex_unlock(&mtx);
> +  pthread_mutex_destroy(&mtx);
> +  pthread_t thr;
> +  pthread_create(&thr, 0, BeforeInitThread, 0);
> +  pthread_join(thr, 0);
> +  atexit(AtExit);
> +}
> +
> +namespace __tsan {
> +bool OnReport(const ReportDesc *rep, bool suppressed) {
> +  if (expect_report) {
> +    if (rep->typ != expect_report_type) {
> +      printf("Expected report of type %d, got type %d\n",
> +             (int)expect_report_type, (int)rep->typ);
> +      EXPECT_FALSE("Wrong report type");
> +      return false;
> +    }
> +  } else {
> +    EXPECT_FALSE("Unexpected report");
> +    return false;
> +  }
> +  expect_report_reported = true;
> +  return true;
> +}
> +}
> +
> +static void* allocate_addr(int size, int offset_from_aligned = 0) {
> +  static uintptr_t foo;
> +  static atomic_uintptr_t uniq = {(uintptr_t)&foo};  // Some real address.
> +  const int kAlign = 16;
> +  CHECK(offset_from_aligned < kAlign);
> +  size = (size + 2 * kAlign) & ~(kAlign - 1);
> +  uintptr_t addr = atomic_fetch_add(&uniq, size, memory_order_relaxed);
> +  return (void*)(addr + offset_from_aligned);
> +}
> +
> +MemLoc::MemLoc(int offset_from_aligned)
> +  : loc_(allocate_addr(16, offset_from_aligned)) {
> +}
> +
> +MemLoc::~MemLoc() {
> +}
> +
> +Mutex::Mutex(Type type)
> +  : alive_()
> +  , type_(type) {
> +}
> +
> +Mutex::~Mutex() {
> +  CHECK(!alive_);
> +}
> +
> +void Mutex::Init() {
> +  CHECK(!alive_);
> +  alive_ = true;
> +  if (type_ == Normal)
> +    CHECK_EQ(pthread_mutex_init((pthread_mutex_t*)mtx_, 0), 0);
> +  else if (type_ == Spin)
> +    CHECK_EQ(pthread_spin_init((pthread_spinlock_t*)mtx_, 0), 0);
> +  else if (type_ == RW)
> +    CHECK_EQ(pthread_rwlock_init((pthread_rwlock_t*)mtx_, 0), 0);
> +  else
> +    CHECK(0);
> +}
> +
> +void Mutex::StaticInit() {
> +  CHECK(!alive_);
> +  CHECK(type_ == Normal);
> +  alive_ = true;
> +  pthread_mutex_t tmp = PTHREAD_MUTEX_INITIALIZER;
> +  memcpy(mtx_, &tmp, sizeof(tmp));
> +}
> +
> +void Mutex::Destroy() {
> +  CHECK(alive_);
> +  alive_ = false;
> +  if (type_ == Normal)
> +    CHECK_EQ(pthread_mutex_destroy((pthread_mutex_t*)mtx_), 0);
> +  else if (type_ == Spin)
> +    CHECK_EQ(pthread_spin_destroy((pthread_spinlock_t*)mtx_), 0);
> +  else if (type_ == RW)
> +    CHECK_EQ(pthread_rwlock_destroy((pthread_rwlock_t*)mtx_), 0);
> +}
> +
> +void Mutex::Lock() {
> +  CHECK(alive_);
> +  if (type_ == Normal)
> +    CHECK_EQ(pthread_mutex_lock((pthread_mutex_t*)mtx_), 0);
> +  else if (type_ == Spin)
> +    CHECK_EQ(pthread_spin_lock((pthread_spinlock_t*)mtx_), 0);
> +  else if (type_ == RW)
> +    CHECK_EQ(pthread_rwlock_wrlock((pthread_rwlock_t*)mtx_), 0);
> +}
> +
> +bool Mutex::TryLock() {
> +  CHECK(alive_);
> +  if (type_ == Normal)
> +    return pthread_mutex_trylock((pthread_mutex_t*)mtx_) == 0;
> +  else if (type_ == Spin)
> +    return pthread_spin_trylock((pthread_spinlock_t*)mtx_) == 0;
> +  else if (type_ == RW)
> +    return pthread_rwlock_trywrlock((pthread_rwlock_t*)mtx_) == 0;
> +  return false;
> +}
> +
> +void Mutex::Unlock() {
> +  CHECK(alive_);
> +  if (type_ == Normal)
> +    CHECK_EQ(pthread_mutex_unlock((pthread_mutex_t*)mtx_), 0);
> +  else if (type_ == Spin)
> +    CHECK_EQ(pthread_spin_unlock((pthread_spinlock_t*)mtx_), 0);
> +  else if (type_ == RW)
> +    CHECK_EQ(pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
> +}
> +
> +void Mutex::ReadLock() {
> +  CHECK(alive_);
> +  CHECK(type_ == RW);
> +  CHECK_EQ(pthread_rwlock_rdlock((pthread_rwlock_t*)mtx_), 0);
> +}
> +
> +bool Mutex::TryReadLock() {
> +  CHECK(alive_);
> +  CHECK(type_ == RW);
> +  return pthread_rwlock_tryrdlock((pthread_rwlock_t*)mtx_) ==  0;
> +}
> +
> +void Mutex::ReadUnlock() {
> +  CHECK(alive_);
> +  CHECK(type_ == RW);
> +  CHECK_EQ(pthread_rwlock_unlock((pthread_rwlock_t*)mtx_), 0);
> +}
> +
> +struct Event {
> +  enum Type {
> +    SHUTDOWN,
> +    READ,
> +    WRITE,
> +    VPTR_UPDATE,
> +    CALL,
> +    RETURN,
> +    MUTEX_CREATE,
> +    MUTEX_DESTROY,
> +    MUTEX_LOCK,
> +    MUTEX_TRYLOCK,
> +    MUTEX_UNLOCK,
> +    MUTEX_READLOCK,
> +    MUTEX_TRYREADLOCK,
> +    MUTEX_READUNLOCK,
> +    MEMCPY,
> +    MEMSET
> +  };
> +  Type type;
> +  void *ptr;
> +  uptr arg;
> +  uptr arg2;
> +  bool res;
> +  bool expect_report;
> +  ReportType report_type;
> +
> +  Event(Type type, const void *ptr = 0, uptr arg = 0, uptr arg2 = 0)
> +    : type(type)
> +    , ptr(const_cast<void*>(ptr))
> +    , arg(arg)
> +    , arg2(arg2)
> +    , res()
> +    , expect_report()
> +    , report_type() {
> +  }
> +
> +  void ExpectReport(ReportType type) {
> +    expect_report = true;
> +    report_type = type;
> +  }
> +};
> +
> +struct ScopedThread::Impl {
> +  pthread_t thread;
> +  bool main;
> +  bool detached;
> +  atomic_uintptr_t event;  // Event*
> +
> +  static void *ScopedThreadCallback(void *arg);
> +  void send(Event *ev);
> +  void HandleEvent(Event *ev);
> +};
> +
> +void ScopedThread::Impl::HandleEvent(Event *ev) {
> +  CHECK_EQ(expect_report, false);
> +  expect_report = ev->expect_report;
> +  expect_report_reported = false;
> +  expect_report_type = ev->report_type;
> +  switch (ev->type) {
> +  case Event::READ:
> +  case Event::WRITE: {
> +    void (*tsan_mop)(void *addr) = 0;
> +    if (ev->type == Event::READ) {
> +      switch (ev->arg /*size*/) {
> +        case 1: tsan_mop = __tsan_read1; break;
> +        case 2: tsan_mop = __tsan_read2; break;
> +        case 4: tsan_mop = __tsan_read4; break;
> +        case 8: tsan_mop = __tsan_read8; break;
> +        case 16: tsan_mop = __tsan_read16; break;
> +      }
> +    } else {
> +      switch (ev->arg /*size*/) {
> +        case 1: tsan_mop = __tsan_write1; break;
> +        case 2: tsan_mop = __tsan_write2; break;
> +        case 4: tsan_mop = __tsan_write4; break;
> +        case 8: tsan_mop = __tsan_write8; break;
> +        case 16: tsan_mop = __tsan_write16; break;
> +      }
> +    }
> +    CHECK_NE(tsan_mop, 0);
> +    errno = ECHRNG;
> +    tsan_mop(ev->ptr);
> +    CHECK_EQ(errno, ECHRNG);  // In no case must errno be changed.
> +    break;
> +  }
> +  case Event::VPTR_UPDATE:
> +    __tsan_vptr_update((void**)ev->ptr, (void*)ev->arg);
> +    break;
> +  case Event::CALL:
> +    __tsan_func_entry((void*)((uptr)ev->ptr));
> +    break;
> +  case Event::RETURN:
> +    __tsan_func_exit();
> +    break;
> +  case Event::MUTEX_CREATE:
> +    static_cast<Mutex*>(ev->ptr)->Init();
> +    break;
> +  case Event::MUTEX_DESTROY:
> +    static_cast<Mutex*>(ev->ptr)->Destroy();
> +    break;
> +  case Event::MUTEX_LOCK:
> +    static_cast<Mutex*>(ev->ptr)->Lock();
> +    break;
> +  case Event::MUTEX_TRYLOCK:
> +    ev->res = static_cast<Mutex*>(ev->ptr)->TryLock();
> +    break;
> +  case Event::MUTEX_UNLOCK:
> +    static_cast<Mutex*>(ev->ptr)->Unlock();
> +    break;
> +  case Event::MUTEX_READLOCK:
> +    static_cast<Mutex*>(ev->ptr)->ReadLock();
> +    break;
> +  case Event::MUTEX_TRYREADLOCK:
> +    ev->res = static_cast<Mutex*>(ev->ptr)->TryReadLock();
> +    break;
> +  case Event::MUTEX_READUNLOCK:
> +    static_cast<Mutex*>(ev->ptr)->ReadUnlock();
> +    break;
> +  case Event::MEMCPY:
> +    __interceptor_memcpy(ev->ptr, (void*)ev->arg, ev->arg2);
> +    break;
> +  case Event::MEMSET:
> +    __interceptor_memset(ev->ptr, ev->arg, ev->arg2);
> +    break;
> +  default: CHECK(0);
> +  }
> +  if (expect_report && !expect_report_reported) {
> +    printf("Missed expected report of type %d\n", (int)ev->report_type);
> +    EXPECT_FALSE("Missed expected race");
> +  }
> +  expect_report = false;
> +}
> +
> +void *ScopedThread::Impl::ScopedThreadCallback(void *arg) {
> +  __tsan_func_entry(__builtin_return_address(0));
> +  Impl *impl = (Impl*)arg;
> +  for (;;) {
> +    Event* ev = (Event*)atomic_load(&impl->event, memory_order_acquire);
> +    if (ev == 0) {
> +      pthread_yield();
> +      continue;
> +    }
> +    if (ev->type == Event::SHUTDOWN) {
> +      atomic_store(&impl->event, 0, memory_order_release);
> +      break;
> +    }
> +    impl->HandleEvent(ev);
> +    atomic_store(&impl->event, 0, memory_order_release);
> +  }
> +  __tsan_func_exit();
> +  return 0;
> +}
> +
> +void ScopedThread::Impl::send(Event *e) {
> +  if (main) {
> +    HandleEvent(e);
> +  } else {
> +    CHECK_EQ(atomic_load(&event, memory_order_relaxed), 0);
> +    atomic_store(&event, (uintptr_t)e, memory_order_release);
> +    while (atomic_load(&event, memory_order_acquire) != 0)
> +      pthread_yield();
> +  }
> +}
> +
> +ScopedThread::ScopedThread(bool detached, bool main) {
> +  impl_ = new Impl;
> +  impl_->main = main;
> +  impl_->detached = detached;
> +  atomic_store(&impl_->event, 0, memory_order_relaxed);
> +  if (!main) {
> +    pthread_attr_t attr;
> +    pthread_attr_init(&attr);
> +    pthread_attr_setdetachstate(&attr, detached);
> +    pthread_attr_setstacksize(&attr, 64*1024);
> +    pthread_create(&impl_->thread, &attr,
> +        ScopedThread::Impl::ScopedThreadCallback, impl_);
> +  }
> +}
> +
> +ScopedThread::~ScopedThread() {
> +  if (!impl_->main) {
> +    Event event(Event::SHUTDOWN);
> +    impl_->send(&event);
> +    if (!impl_->detached)
> +      pthread_join(impl_->thread, 0);
> +  }
> +  delete impl_;
> +}
> +
> +void ScopedThread::Detach() {
> +  CHECK(!impl_->main);
> +  CHECK(!impl_->detached);
> +  impl_->detached = true;
> +  pthread_detach(impl_->thread);
> +}
> +
> +void ScopedThread::Access(void *addr, bool is_write,
> +                          int size, bool expect_race) {
> +  Event event(is_write ? Event::WRITE : Event::READ, addr, size);
> +  if (expect_race)
> +    event.ExpectReport(ReportTypeRace);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::VptrUpdate(const MemLoc &vptr,
> +                              const MemLoc &new_val,
> +                              bool expect_race) {
> +  Event event(Event::VPTR_UPDATE, vptr.loc(), (uptr)new_val.loc());
> +  if (expect_race)
> +    event.ExpectReport(ReportTypeRace);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Call(void(*pc)()) {
> +  Event event(Event::CALL, (void*)pc);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Return() {
> +  Event event(Event::RETURN);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Create(const Mutex &m) {
> +  Event event(Event::MUTEX_CREATE, &m);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Destroy(const Mutex &m) {
> +  Event event(Event::MUTEX_DESTROY, &m);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Lock(const Mutex &m) {
> +  Event event(Event::MUTEX_LOCK, &m);
> +  impl_->send(&event);
> +}
> +
> +bool ScopedThread::TryLock(const Mutex &m) {
> +  Event event(Event::MUTEX_TRYLOCK, &m);
> +  impl_->send(&event);
> +  return event.res;
> +}
> +
> +void ScopedThread::Unlock(const Mutex &m) {
> +  Event event(Event::MUTEX_UNLOCK, &m);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::ReadLock(const Mutex &m) {
> +  Event event(Event::MUTEX_READLOCK, &m);
> +  impl_->send(&event);
> +}
> +
> +bool ScopedThread::TryReadLock(const Mutex &m) {
> +  Event event(Event::MUTEX_TRYREADLOCK, &m);
> +  impl_->send(&event);
> +  return event.res;
> +}
> +
> +void ScopedThread::ReadUnlock(const Mutex &m) {
> +  Event event(Event::MUTEX_READUNLOCK, &m);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Memcpy(void *dst, const void *src, int size,
> +                          bool expect_race) {
> +  Event event(Event::MEMCPY, dst, (uptr)src, size);
> +  if (expect_race)
> +    event.ExpectReport(ReportTypeRace);
> +  impl_->send(&event);
> +}
> +
> +void ScopedThread::Memset(void *dst, int val, int size,
> +                          bool expect_race) {
> +  Event event(Event::MEMSET, dst, val, size);
> +  if (expect_race)
> +    event.ExpectReport(ReportTypeRace);
> +  impl_->send(&event);
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/rtl/tsan_thread.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/rtl/tsan_thread.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/rtl/tsan_thread.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/rtl/tsan_thread.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,59 @@
> +//===-- tsan_thread.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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_test_util.h"
> +#include "gtest/gtest.h"
> +
> +TEST(ThreadSanitizer, ThreadSync) {
> +  MainThread t0;
> +  MemLoc l;
> +  t0.Write1(l);
> +  {
> +    ScopedThread t1;
> +    t1.Write1(l);
> +  }
> +  t0.Write1(l);
> +}
> +
> +TEST(ThreadSanitizer, ThreadDetach1) {
> +  ScopedThread t1(true);
> +  MemLoc l;
> +  t1.Write1(l);
> +}
> +
> +TEST(ThreadSanitizer, ThreadDetach2) {
> +  ScopedThread t1;
> +  MemLoc l;
> +  t1.Write1(l);
> +  t1.Detach();
> +}
> +
> +static void *thread_alot_func(void *arg) {
> +  (void)arg;
> +  int usleep(unsigned);
> +  usleep(50);
> +  return 0;
> +}
> +
> +TEST(DISABLED_SLOW_ThreadSanitizer, ThreadALot) {
> +  const int kThreads = 70000;
> +  const int kAlive = 1000;
> +  pthread_t threads[kAlive] = {};
> +  for (int i = 0; i < kThreads; i++) {
> +    if (threads[i % kAlive])
> +      pthread_join(threads[i % kAlive], 0);
> +    pthread_create(&threads[i % kAlive], 0, thread_alot_func, 0);
> +  }
> +  for (int i = 0; i < kAlive; i++) {
> +    pthread_join(threads[i], 0);
> +  }
> +}
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/CMakeLists.txt Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,15 @@
> +set(TSAN_UNIT_TESTS
> +  tsan_clock_test.cc
> +  tsan_flags_test.cc
> +  tsan_mman_test.cc
> +  tsan_mutex_test.cc
> +  tsan_platform_test.cc
> +  tsan_printf_test.cc
> +  tsan_shadow_test.cc
> +  tsan_stack_test.cc
> +  tsan_suppressions_test.cc
> +  tsan_sync_test.cc
> +  tsan_vector_test.cc
> +  )
> +
> +add_tsan_unittest(TsanUnitTest ${TSAN_UNIT_TESTS})
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_clock_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_clock_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_clock_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_clock_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,123 @@
> +//===-- tsan_clock_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_clock.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +TEST(Clock, VectorBasic) {
> +  ScopedInRtl in_rtl;
> +  ThreadClock clk;
> +  CHECK_EQ(clk.size(), 0);
> +  clk.tick(0);
> +  CHECK_EQ(clk.size(), 1);
> +  CHECK_EQ(clk.get(0), 1);
> +  clk.tick(3);
> +  CHECK_EQ(clk.size(), 4);
> +  CHECK_EQ(clk.get(0), 1);
> +  CHECK_EQ(clk.get(1), 0);
> +  CHECK_EQ(clk.get(2), 0);
> +  CHECK_EQ(clk.get(3), 1);
> +  clk.tick(3);
> +  CHECK_EQ(clk.get(3), 2);
> +}
> +
> +TEST(Clock, ChunkedBasic) {
> +  ScopedInRtl in_rtl;
> +  ThreadClock vector;
> +  SyncClock chunked;
> +  CHECK_EQ(vector.size(), 0);
> +  CHECK_EQ(chunked.size(), 0);
> +  vector.acquire(&chunked);
> +  CHECK_EQ(vector.size(), 0);
> +  CHECK_EQ(chunked.size(), 0);
> +  vector.release(&chunked);
> +  CHECK_EQ(vector.size(), 0);
> +  CHECK_EQ(chunked.size(), 0);
> +  vector.acq_rel(&chunked);
> +  CHECK_EQ(vector.size(), 0);
> +  CHECK_EQ(chunked.size(), 0);
> +}
> +
> +TEST(Clock, AcquireRelease) {
> +  ScopedInRtl in_rtl;
> +  ThreadClock vector1;
> +  vector1.tick(100);
> +  SyncClock chunked;
> +  vector1.release(&chunked);
> +  CHECK_EQ(chunked.size(), 101);
> +  ThreadClock vector2;
> +  vector2.acquire(&chunked);
> +  CHECK_EQ(vector2.size(), 101);
> +  CHECK_EQ(vector2.get(0), 0);
> +  CHECK_EQ(vector2.get(1), 0);
> +  CHECK_EQ(vector2.get(99), 0);
> +  CHECK_EQ(vector2.get(100), 1);
> +}
> +
> +TEST(Clock, ManyThreads) {
> +  ScopedInRtl in_rtl;
> +  SyncClock chunked;
> +  for (int i = 0; i < 100; i++) {
> +    ThreadClock vector;
> +    vector.tick(i);
> +    vector.release(&chunked);
> +    CHECK_EQ(chunked.size(), i + 1);
> +    vector.acquire(&chunked);
> +    CHECK_EQ(vector.size(), i + 1);
> +  }
> +  ThreadClock vector;
> +  vector.acquire(&chunked);
> +  CHECK_EQ(vector.size(), 100);
> +  for (int i = 0; i < 100; i++)
> +    CHECK_EQ(vector.get(i), 1);
> +}
> +
> +TEST(Clock, DifferentSizes) {
> +  ScopedInRtl in_rtl;
> +  {
> +    ThreadClock vector1;
> +    vector1.tick(10);
> +    ThreadClock vector2;
> +    vector2.tick(20);
> +    {
> +      SyncClock chunked;
> +      vector1.release(&chunked);
> +      CHECK_EQ(chunked.size(), 11);
> +      vector2.release(&chunked);
> +      CHECK_EQ(chunked.size(), 21);
> +    }
> +    {
> +      SyncClock chunked;
> +      vector2.release(&chunked);
> +      CHECK_EQ(chunked.size(), 21);
> +      vector1.release(&chunked);
> +      CHECK_EQ(chunked.size(), 21);
> +    }
> +    {
> +      SyncClock chunked;
> +      vector1.release(&chunked);
> +      vector2.acquire(&chunked);
> +      CHECK_EQ(vector2.size(), 21);
> +    }
> +    {
> +      SyncClock chunked;
> +      vector2.release(&chunked);
> +      vector1.acquire(&chunked);
> +      CHECK_EQ(vector1.size(), 21);
> +    }
> +  }
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_flags_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_flags_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_flags_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_flags_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,38 @@
> +//===-- tsan_flags_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_flags.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +TEST(Flags, Basic) {
> +  ScopedInRtl in_rtl;
> +  // At least should not crash.
> +  Flags f = {};
> +  InitializeFlags(&f, 0);
> +  InitializeFlags(&f, "");
> +}
> +
> +TEST(Flags, DefaultValues) {
> +  ScopedInRtl in_rtl;
> +  Flags f = {};
> +
> +  f.enable_annotations = false;
> +  f.exitcode = -11;
> +  InitializeFlags(&f, "");
> +  EXPECT_EQ(66, f.exitcode);
> +  EXPECT_EQ(true, f.enable_annotations);
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,109 @@
> +//===-- tsan_mman_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_mman.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +TEST(Mman, Internal) {
> +  ScopedInRtl in_rtl;
> +  char *p = (char*)internal_alloc(MBlockScopedBuf, 10);
> +  EXPECT_NE(p, (char*)0);
> +  char *p2 = (char*)internal_alloc(MBlockScopedBuf, 20);
> +  EXPECT_NE(p2, (char*)0);
> +  EXPECT_NE(p2, p);
> +  for (int i = 0; i < 10; i++) {
> +    p[i] = 42;
> +  }
> +  for (int i = 0; i < 20; i++) {
> +    ((char*)p2)[i] = 42;
> +  }
> +  internal_free(p);
> +  internal_free(p2);
> +}
> +
> +TEST(Mman, User) {
> +  ScopedInRtl in_rtl;
> +  ThreadState *thr = cur_thread();
> +  uptr pc = 0;
> +  char *p = (char*)user_alloc(thr, pc, 10);
> +  EXPECT_NE(p, (char*)0);
> +  char *p2 = (char*)user_alloc(thr, pc, 20);
> +  EXPECT_NE(p2, (char*)0);
> +  EXPECT_NE(p2, p);
> +  MBlock *b = user_mblock(thr, p);
> +  EXPECT_NE(b, (MBlock*)0);
> +  EXPECT_EQ(b->size, (uptr)10);
> +  MBlock *b2 = user_mblock(thr, p2);
> +  EXPECT_NE(b2, (MBlock*)0);
> +  EXPECT_EQ(b2->size, (uptr)20);
> +  for (int i = 0; i < 10; i++) {
> +    p[i] = 42;
> +    EXPECT_EQ(b, user_mblock(thr, p + i));
> +  }
> +  for (int i = 0; i < 20; i++) {
> +    ((char*)p2)[i] = 42;
> +    EXPECT_EQ(b2, user_mblock(thr, p2 + i));
> +  }
> +  user_free(thr, pc, p);
> +  user_free(thr, pc, p2);
> +}
> +
> +TEST(Mman, UserRealloc) {
> +  ScopedInRtl in_rtl;
> +  ThreadState *thr = cur_thread();
> +  uptr pc = 0;
> +  {
> +    void *p = user_realloc(thr, pc, 0, 0);
> +    // Strictly saying this is incorrect, realloc(NULL, N) is equivalent to
> +    // malloc(N), thus must return non-NULL pointer.
> +    EXPECT_EQ(p, (void*)0);
> +  }
> +  {
> +    void *p = user_realloc(thr, pc, 0, 100);
> +    EXPECT_NE(p, (void*)0);
> +    memset(p, 0xde, 100);
> +    user_free(thr, pc, p);
> +  }
> +  {
> +    void *p = user_alloc(thr, pc, 100);
> +    EXPECT_NE(p, (void*)0);
> +    memset(p, 0xde, 100);
> +    void *p2 = user_realloc(thr, pc, p, 0);
> +    EXPECT_EQ(p2, (void*)0);
> +  }
> +  {
> +    void *p = user_realloc(thr, pc, 0, 100);
> +    EXPECT_NE(p, (void*)0);
> +    memset(p, 0xde, 100);
> +    void *p2 = user_realloc(thr, pc, p, 10000);
> +    EXPECT_NE(p2, (void*)0);
> +    for (int i = 0; i < 100; i++)
> +      EXPECT_EQ(((char*)p2)[i], (char)0xde);
> +    memset(p2, 0xde, 10000);
> +    user_free(thr, pc, p2);
> +  }
> +  {
> +    void *p = user_realloc(thr, pc, 0, 10000);
> +    EXPECT_NE(p, (void*)0);
> +    memset(p, 0xde, 10000);
> +    void *p2 = user_realloc(thr, pc, p, 10);
> +    EXPECT_NE(p2, (void*)0);
> +    for (int i = 0; i < 10; i++)
> +      EXPECT_EQ(((char*)p2)[i], (char)0xde);
> +    user_free(thr, pc, p2);
> +  }
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_mutex_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_mutex_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_mutex_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_mutex_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,126 @@
> +//===-- tsan_mutex_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "sanitizer_common/sanitizer_internal_defs.h"
> +#include "sanitizer_common/sanitizer_atomic.h"
> +#include "sanitizer_common/sanitizer_common.h"
> +#include "sanitizer_common/sanitizer_mutex.h"
> +#include "tsan_mutex.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +template<typename MutexType>
> +class TestData {
> + public:
> +  explicit TestData(MutexType *mtx)
> +    : mtx_(mtx) {
> +    for (int i = 0; i < kSize; i++)
> +      data_[i] = 0;
> +  }
> +
> +  void Write() {
> +    Lock l(mtx_);
> +    T v0 = data_[0];
> +    for (int i = 0; i < kSize; i++) {
> +      CHECK_EQ(data_[i], v0);
> +      data_[i]++;
> +    }
> +  }
> +
> +  void Read() {
> +    ReadLock l(mtx_);
> +    T v0 = data_[0];
> +    for (int i = 0; i < kSize; i++) {
> +      CHECK_EQ(data_[i], v0);
> +    }
> +  }
> +
> +  void Backoff() {
> +    volatile T data[kSize] = {};
> +    for (int i = 0; i < kSize; i++) {
> +      data[i]++;
> +      CHECK_EQ(data[i], 1);
> +    }
> +  }
> +
> + private:
> +  typedef GenericScopedLock<MutexType> Lock;
> +  static const int kSize = 64;
> +  typedef u64 T;
> +  MutexType *mtx_;
> +  char pad_[kCacheLineSize];
> +  T data_[kSize];
> +};
> +
> +const int kThreads = 8;
> +const int kWriteRate = 1024;
> +#if TSAN_DEBUG
> +const int kIters = 16*1024;
> +#else
> +const int kIters = 64*1024;
> +#endif
> +
> +template<typename MutexType>
> +static void *write_mutex_thread(void *param) {
> +  TestData<MutexType> *data = (TestData<MutexType>*)param;
> +  for (int i = 0; i < kIters; i++) {
> +    data->Write();
> +    data->Backoff();
> +  }
> +  return 0;
> +}
> +
> +template<typename MutexType>
> +static void *read_mutex_thread(void *param) {
> +  TestData<MutexType> *data = (TestData<MutexType>*)param;
> +  for (int i = 0; i < kIters; i++) {
> +    if ((i % kWriteRate) == 0)
> +      data->Write();
> +    else
> +      data->Read();
> +    data->Backoff();
> +  }
> +  return 0;
> +}
> +
> +TEST(Mutex, Write) {
> +  Mutex mtx(MutexTypeAnnotations, StatMtxAnnotations);
> +  TestData<Mutex> data(&mtx);
> +  pthread_t threads[kThreads];
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_create(&threads[i], 0, write_mutex_thread<Mutex>, &data);
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_join(threads[i], 0);
> +}
> +
> +TEST(Mutex, ReadWrite) {
> +  Mutex mtx(MutexTypeAnnotations, StatMtxAnnotations);
> +  TestData<Mutex> data(&mtx);
> +  pthread_t threads[kThreads];
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_create(&threads[i], 0, read_mutex_thread<Mutex>, &data);
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_join(threads[i], 0);
> +}
> +
> +TEST(Mutex, SpinWrite) {
> +  SpinMutex mtx;
> +  TestData<SpinMutex> data(&mtx);
> +  pthread_t threads[kThreads];
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_create(&threads[i], 0, write_mutex_thread<SpinMutex>, &data);
> +  for (int i = 0; i < kThreads; i++)
> +    pthread_join(threads[i], 0);
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_platform_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_platform_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_platform_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_platform_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,88 @@
> +//===-- tsan_platform_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "sanitizer_common/sanitizer_libc.h"
> +#include "tsan_platform.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +static void TestThreadInfo(bool main) {
> +  ScopedInRtl in_rtl;
> +  uptr stk_addr = 0;
> +  uptr stk_size = 0;
> +  uptr tls_addr = 0;
> +  uptr tls_size = 0;
> +  GetThreadStackAndTls(main, &stk_addr, &stk_size, &tls_addr, &tls_size);
> +  // Printf("stk=%zx-%zx(%zu)\n", stk_addr, stk_addr + stk_size, stk_size);
> +  // Printf("tls=%zx-%zx(%zu)\n", tls_addr, tls_addr + tls_size, tls_size);
> +
> +  int stack_var;
> +  EXPECT_NE(stk_addr, (uptr)0);
> +  EXPECT_NE(stk_size, (uptr)0);
> +  EXPECT_GT((uptr)&stack_var, stk_addr);
> +  EXPECT_LT((uptr)&stack_var, stk_addr + stk_size);
> +
> +  static __thread int thread_var;
> +  EXPECT_NE(tls_addr, (uptr)0);
> +  EXPECT_NE(tls_size, (uptr)0);
> +  EXPECT_GT((uptr)&thread_var, tls_addr);
> +  EXPECT_LT((uptr)&thread_var, tls_addr + tls_size);
> +
> +  // Ensure that tls and stack do not intersect.
> +  uptr tls_end = tls_addr + tls_size;
> +  EXPECT_TRUE(tls_addr < stk_addr || tls_addr >= stk_addr + stk_size);
> +  EXPECT_TRUE(tls_end  < stk_addr || tls_end  >=  stk_addr + stk_size);
> +  EXPECT_TRUE((tls_addr < stk_addr) == (tls_end  < stk_addr));
> +}
> +
> +static void *WorkerThread(void *arg) {
> +  TestThreadInfo(false);
> +  return 0;
> +}
> +
> +TEST(Platform, ThreadInfoMain) {
> +  TestThreadInfo(true);
> +}
> +
> +TEST(Platform, ThreadInfoWorker) {
> +  pthread_t t;
> +  pthread_create(&t, 0, WorkerThread, 0);
> +  pthread_join(t, 0);
> +}
> +
> +TEST(Platform, FileOps) {
> +  const char *str1 = "qwerty";
> +  uptr len1 = internal_strlen(str1);
> +  const char *str2 = "zxcv";
> +  uptr len2 = internal_strlen(str2);
> +
> +  fd_t fd = internal_open("./tsan_test.tmp", true);
> +  EXPECT_NE(fd, kInvalidFd);
> +  EXPECT_EQ(len1, internal_write(fd, str1, len1));
> +  EXPECT_EQ(len2, internal_write(fd, str2, len2));
> +  internal_close(fd);
> +
> +  fd = internal_open("./tsan_test.tmp", false);
> +  EXPECT_NE(fd, kInvalidFd);
> +  EXPECT_EQ(len1 + len2, internal_filesize(fd));
> +  char buf[64] = {};
> +  EXPECT_EQ(len1, internal_read(fd, buf, len1));
> +  EXPECT_EQ(0, internal_memcmp(buf, str1, len1));
> +  EXPECT_EQ((char)0, buf[len1 + 1]);
> +  internal_memset(buf, 0, len1);
> +  EXPECT_EQ(len2, internal_read(fd, buf, len2));
> +  EXPECT_EQ(0, internal_memcmp(buf, str2, len2));
> +  internal_close(fd);
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_printf_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_printf_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_printf_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_printf_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,106 @@
> +//===-- tsan_printf_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +#include <string.h>
> +#include <limits.h>
> +
> +namespace __tsan {
> +
> +TEST(Printf, Basic) {
> +  char buf[1024];
> +  uptr len = internal_snprintf(buf, sizeof(buf),
> +      "a%db%zdc%ue%zuf%xh%zxq%pe%sr",
> +      (int)-1, (long)-2, // NOLINT
> +      (unsigned)-4, (unsigned long)5, // NOLINT
> +      (unsigned)10, (unsigned long)11, // NOLINT
> +      (void*)0x123, "_string_");
> +  EXPECT_EQ(len, strlen(buf));
> +  EXPECT_EQ(0, strcmp(buf, "a-1b-2c4294967292e5fahbq"
> +                           "0x000000000123e_string_r"));
> +}
> +
> +TEST(Printf, OverflowStr) {
> +  char buf[] = "123456789";
> +  uptr len = internal_snprintf(buf, 4, "%s", "abcdef");  // NOLINT
> +  EXPECT_EQ(len, (uptr)6);
> +  EXPECT_EQ(0, strcmp(buf, "abc"));
> +  EXPECT_EQ(buf[3], 0);
> +  EXPECT_EQ(buf[4], '5');
> +  EXPECT_EQ(buf[5], '6');
> +  EXPECT_EQ(buf[6], '7');
> +  EXPECT_EQ(buf[7], '8');
> +  EXPECT_EQ(buf[8], '9');
> +  EXPECT_EQ(buf[9], 0);
> +}
> +
> +TEST(Printf, OverflowInt) {
> +  char buf[] = "123456789";
> +  internal_snprintf(buf, 4, "%d", -123456789);  // NOLINT
> +  EXPECT_EQ(0, strcmp(buf, "-12"));
> +  EXPECT_EQ(buf[3], 0);
> +  EXPECT_EQ(buf[4], '5');
> +  EXPECT_EQ(buf[5], '6');
> +  EXPECT_EQ(buf[6], '7');
> +  EXPECT_EQ(buf[7], '8');
> +  EXPECT_EQ(buf[8], '9');
> +  EXPECT_EQ(buf[9], 0);
> +}
> +
> +TEST(Printf, OverflowUint) {
> +  char buf[] = "123456789";
> +  internal_snprintf(buf, 4, "a%zx", (unsigned long)0x123456789);  // NOLINT
> +  EXPECT_EQ(0, strcmp(buf, "a12"));
> +  EXPECT_EQ(buf[3], 0);
> +  EXPECT_EQ(buf[4], '5');
> +  EXPECT_EQ(buf[5], '6');
> +  EXPECT_EQ(buf[6], '7');
> +  EXPECT_EQ(buf[7], '8');
> +  EXPECT_EQ(buf[8], '9');
> +  EXPECT_EQ(buf[9], 0);
> +}
> +
> +TEST(Printf, OverflowPtr) {
> +  char buf[] = "123456789";
> +  internal_snprintf(buf, 4, "%p", (void*)0x123456789);  // NOLINT
> +  EXPECT_EQ(0, strcmp(buf, "0x0"));
> +  EXPECT_EQ(buf[3], 0);
> +  EXPECT_EQ(buf[4], '5');
> +  EXPECT_EQ(buf[5], '6');
> +  EXPECT_EQ(buf[6], '7');
> +  EXPECT_EQ(buf[7], '8');
> +  EXPECT_EQ(buf[8], '9');
> +  EXPECT_EQ(buf[9], 0);
> +}
> +
> +template<typename T>
> +static void TestMinMax(const char *fmt, T min, T max) {
> +  char buf[1024];
> +  uptr len = internal_snprintf(buf, sizeof(buf), fmt, min, max);
> +  char buf2[1024];
> +  snprintf(buf2, sizeof(buf2), fmt, min, max);
> +  EXPECT_EQ(len, strlen(buf));
> +  EXPECT_EQ(0, strcmp(buf, buf2));
> +}
> +
> +TEST(Printf, MinMax) {
> +  TestMinMax<int>("%d-%d", INT_MIN, INT_MAX);  // NOLINT
> +  TestMinMax<long>("%zd-%zd", LONG_MIN, LONG_MAX);  // NOLINT
> +  TestMinMax<unsigned>("%u-%u", 0, UINT_MAX);  // NOLINT
> +  TestMinMax<unsigned long>("%zu-%zu", 0, ULONG_MAX);  // NOLINT
> +  TestMinMax<unsigned>("%x-%x", 0, UINT_MAX);  // NOLINT
> +  TestMinMax<unsigned long>("%zx-%zx", 0, ULONG_MAX);  // NOLINT
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_shadow_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_shadow_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_shadow_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_shadow_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,47 @@
> +//===-- tsan_shadow_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_platform.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +TEST(Shadow, Mapping) {
> +  static int global;
> +  int stack;
> +  void *heap = malloc(0);
> +  free(heap);
> +
> +  CHECK(IsAppMem((uptr)&global));
> +  CHECK(IsAppMem((uptr)&stack));
> +  CHECK(IsAppMem((uptr)heap));
> +
> +  CHECK(IsShadowMem(MemToShadow((uptr)&global)));
> +  CHECK(IsShadowMem(MemToShadow((uptr)&stack)));
> +  CHECK(IsShadowMem(MemToShadow((uptr)heap)));
> +}
> +
> +TEST(Shadow, Celling) {
> +  u64 aligned_data[4];
> +  char *data = (char*)aligned_data;
> +  CHECK_EQ((uptr)data % kShadowSize, 0);
> +  uptr s0 = MemToShadow((uptr)&data[0]);
> +  CHECK_EQ(s0 % kShadowSize, 0);
> +  for (unsigned i = 1; i < kShadowCell; i++)
> +    CHECK_EQ(s0, MemToShadow((uptr)&data[i]));
> +  for (unsigned i = kShadowCell; i < 2*kShadowCell; i++)
> +    CHECK_EQ(s0 + kShadowSize*kShadowCnt, MemToShadow((uptr)&data[i]));
> +  for (unsigned i = 2*kShadowCell; i < 3*kShadowCell; i++)
> +    CHECK_EQ(s0 + 2*kShadowSize*kShadowCnt, MemToShadow((uptr)&data[i]));
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_stack_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_stack_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_stack_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_stack_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,80 @@
> +//===-- tsan_stack_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_sync.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +#include <string.h>
> +
> +namespace __tsan {
> +
> +static void TestStackTrace(StackTrace *trace) {
> +  ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0);
> +
> +  trace->ObtainCurrent(&thr, 0);
> +  EXPECT_EQ(trace->Size(), (uptr)0);
> +
> +  trace->ObtainCurrent(&thr, 42);
> +  EXPECT_EQ(trace->Size(), (uptr)1);
> +  EXPECT_EQ(trace->Get(0), (uptr)42);
> +
> +  *thr.shadow_stack_pos++ = 100;
> +  *thr.shadow_stack_pos++ = 101;
> +  trace->ObtainCurrent(&thr, 0);
> +  EXPECT_EQ(trace->Size(), (uptr)2);
> +  EXPECT_EQ(trace->Get(0), (uptr)100);
> +  EXPECT_EQ(trace->Get(1), (uptr)101);
> +
> +  trace->ObtainCurrent(&thr, 42);
> +  EXPECT_EQ(trace->Size(), (uptr)3);
> +  EXPECT_EQ(trace->Get(0), (uptr)100);
> +  EXPECT_EQ(trace->Get(1), (uptr)101);
> +  EXPECT_EQ(trace->Get(2), (uptr)42);
> +}
> +
> +TEST(StackTrace, Basic) {
> +  ScopedInRtl in_rtl;
> +  StackTrace trace;
> +  TestStackTrace(&trace);
> +}
> +
> +TEST(StackTrace, StaticBasic) {
> +  ScopedInRtl in_rtl;
> +  uptr buf[10];
> +  StackTrace trace1(buf, 10);
> +  TestStackTrace(&trace1);
> +  StackTrace trace2(buf, 3);
> +  TestStackTrace(&trace2);
> +}
> +
> +TEST(StackTrace, StaticTrim) {
> +  ScopedInRtl in_rtl;
> +  uptr buf[2];
> +  StackTrace trace(buf, 2);
> +  ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0);
> +
> +  *thr.shadow_stack_pos++ = 100;
> +  *thr.shadow_stack_pos++ = 101;
> +  *thr.shadow_stack_pos++ = 102;
> +  trace.ObtainCurrent(&thr, 0);
> +  EXPECT_EQ(trace.Size(), (uptr)2);
> +  EXPECT_EQ(trace.Get(0), (uptr)101);
> +  EXPECT_EQ(trace.Get(1), (uptr)102);
> +
> +  trace.ObtainCurrent(&thr, 42);
> +  EXPECT_EQ(trace.Size(), (uptr)2);
> +  EXPECT_EQ(trace.Get(0), (uptr)102);
> +  EXPECT_EQ(trace.Get(1), (uptr)42);
> +}
> +
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_suppressions_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_suppressions_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_suppressions_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_suppressions_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,128 @@
> +//===-- tsan_suppressions_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_suppressions.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +#include <string.h>
> +
> +namespace __tsan {
> +
> +TEST(Suppressions, Parse) {
> +  ScopedInRtl in_rtl;
> +  Suppression *supp0 = SuppressionParse(
> +    "race:foo\n"
> +    "  race:bar\n"  // NOLINT
> +    "race:baz   \n"  // NOLINT
> +    "# a comment\n"
> +    "race:quz\n"
> +  );  // NOLINT
> +  Suppression *supp = supp0;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "quz"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "baz"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> +  supp = supp->next;
> +  EXPECT_EQ((Suppression*)0, supp);
> +}
> +
> +TEST(Suppressions, Parse2) {
> +  ScopedInRtl in_rtl;
> +  Suppression *supp0 = SuppressionParse(
> +    "          # first line comment\n"  // NOLINT
> +    "  race:bar        \n"  // NOLINT
> +    "race:baz* *baz\n"
> +    "# a comment\n"
> +    "# last line comment\n"
> +  );  // NOLINT
> +  Suppression *supp = supp0;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "baz* *baz"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> +  supp = supp->next;
> +  EXPECT_EQ((Suppression*)0, supp);
> +}
> +
> +TEST(Suppressions, Parse3) {
> +  ScopedInRtl in_rtl;
> +  Suppression *supp0 = SuppressionParse(
> +    "# last suppression w/o line-feed\n"
> +    "race:foo\n"
> +    "race:bar"
> +  );  // NOLINT
> +  Suppression *supp = supp0;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> +  supp = supp->next;
> +  EXPECT_EQ((Suppression*)0, supp);
> +}
> +
> +TEST(Suppressions, ParseType) {
> +  ScopedInRtl in_rtl;
> +  Suppression *supp0 = SuppressionParse(
> +    "race:foo\n"
> +    "thread:bar\n"
> +    "mutex:baz\n"
> +    "signal:quz\n"
> +  );  // NOLINT
> +  Suppression *supp = supp0;
> +  EXPECT_EQ(supp->type, SuppressionSignal);
> +  EXPECT_EQ(0, strcmp(supp->templ, "quz"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionMutex);
> +  EXPECT_EQ(0, strcmp(supp->templ, "baz"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionThread);
> +  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> +  supp = supp->next;
> +  EXPECT_EQ(supp->type, SuppressionRace);
> +  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> +  supp = supp->next;
> +  EXPECT_EQ((Suppression*)0, supp);
> +}
> +
> +static bool MyMatch(const char *templ, const char *func) {
> +  char tmp[1024];
> +  strcpy(tmp, templ);  // NOLINT
> +  return SuppressionMatch(tmp, func);
> +}
> +
> +TEST(Suppressions, Match) {
> +  EXPECT_TRUE(MyMatch("foobar", "foobar"));
> +  EXPECT_TRUE(MyMatch("foobar", "prefix_foobar_postfix"));
> +  EXPECT_TRUE(MyMatch("*foobar*", "prefix_foobar_postfix"));
> +  EXPECT_TRUE(MyMatch("foo*bar", "foo_middle_bar"));
> +  EXPECT_TRUE(MyMatch("foo*bar", "foobar"));
> +  EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_bar_another_baz"));
> +  EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_barbaz"));
> +
> +  EXPECT_FALSE(MyMatch("foo", "baz"));
> +  EXPECT_FALSE(MyMatch("foobarbaz", "foobar"));
> +  EXPECT_FALSE(MyMatch("foobarbaz", "barbaz"));
> +  EXPECT_FALSE(MyMatch("foo*bar", "foobaz"));
> +  EXPECT_FALSE(MyMatch("foo*bar", "foo_baz"));
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_sync_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,65 @@
> +//===-- tsan_sync_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_sync.h"
> +#include "tsan_rtl.h"
> +#include "tsan_mman.h"
> +#include "gtest/gtest.h"
> +
> +#include <stdlib.h>
> +#include <stdint.h>
> +#include <map>
> +
> +namespace __tsan {
> +
> +TEST(Sync, Table) {
> +  const uintptr_t kIters = 512*1024;
> +  const uintptr_t kRange = 10000;
> +
> +  ScopedInRtl in_rtl;
> +  ThreadState *thr = cur_thread();
> +  uptr pc = 0;
> +
> +  SyncTab tab;
> +  SyncVar *golden[kRange] = {};
> +  unsigned seed = 0;
> +  for (uintptr_t i = 0; i < kIters; i++) {
> +    uintptr_t addr = rand_r(&seed) % (kRange - 1) + 1;
> +    if (rand_r(&seed) % 2) {
> +      // Get or add.
> +      SyncVar *v = tab.GetAndLock(thr, pc, addr, true);
> +      EXPECT_TRUE(golden[addr] == 0 || golden[addr] == v);
> +      EXPECT_EQ(v->addr, addr);
> +      golden[addr] = v;
> +      v->mtx.Unlock();
> +    } else {
> +      // Remove.
> +      SyncVar *v = tab.GetAndRemove(thr, pc, addr);
> +      EXPECT_EQ(golden[addr], v);
> +      if (v) {
> +        EXPECT_EQ(v->addr, addr);
> +        golden[addr] = 0;
> +        DestroyAndFree(v);
> +      }
> +    }
> +  }
> +  for (uintptr_t addr = 0; addr < kRange; addr++) {
> +    if (golden[addr] == 0)
> +      continue;
> +    SyncVar *v = tab.GetAndRemove(thr, pc, addr);
> +    EXPECT_EQ(v, golden[addr]);
> +    EXPECT_EQ(v->addr, addr);
> +    DestroyAndFree(v);
> +  }
> +}
> +
> +}  // namespace __tsan
>
> Added: compiler-rt/trunk/lib/tsan/tests/unit/tsan_vector_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/unit/tsan_vector_test.cc?rev=164022&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/tests/unit/tsan_vector_test.cc (added)
> +++ compiler-rt/trunk/lib/tsan/tests/unit/tsan_vector_test.cc Mon Sep 17 05:02:17 2012
> @@ -0,0 +1,45 @@
> +//===-- tsan_vector_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 ThreadSanitizer (TSan), a race detector.
> +//
> +//===----------------------------------------------------------------------===//
> +#include "tsan_vector.h"
> +#include "tsan_rtl.h"
> +#include "gtest/gtest.h"
> +
> +namespace __tsan {
> +
> +TEST(Vector, Basic) {
> +  ScopedInRtl in_rtl;
> +  Vector<int> v(MBlockScopedBuf);
> +  EXPECT_EQ(v.Size(), (uptr)0);
> +  v.PushBack(42);
> +  EXPECT_EQ(v.Size(), (uptr)1);
> +  EXPECT_EQ(v[0], 42);
> +  v.PushBack(43);
> +  EXPECT_EQ(v.Size(), (uptr)2);
> +  EXPECT_EQ(v[0], 42);
> +  EXPECT_EQ(v[1], 43);
> +}
> +
> +TEST(Vector, Stride) {
> +  ScopedInRtl in_rtl;
> +  Vector<int> v(MBlockScopedBuf);
> +  for (int i = 0; i < 1000; i++) {
> +    v.PushBack(i);
> +    EXPECT_EQ(v.Size(), (uptr)(i + 1));
> +    EXPECT_EQ(v[i], i);
> +  }
> +  for (int i = 0; i < 1000; i++) {
> +    EXPECT_EQ(v[i], i);
> +  }
> +}
> +
> +}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/CMakeLists.txt?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/CMakeLists.txt (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/CMakeLists.txt (removed)
> @@ -1,15 +0,0 @@
> -set(TSAN_UNIT_TESTS
> -  tsan_clock_test.cc
> -  tsan_flags_test.cc
> -  tsan_mman_test.cc
> -  tsan_mutex_test.cc
> -  tsan_platform_test.cc
> -  tsan_printf_test.cc
> -  tsan_shadow_test.cc
> -  tsan_stack_test.cc
> -  tsan_suppressions_test.cc
> -  tsan_sync_test.cc
> -  tsan_vector_test.cc
> -  )
> -
> -add_tsan_unittest(TsanUnitTest ${TSAN_UNIT_TESTS})
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_clock_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_clock_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_clock_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_clock_test.cc (removed)
> @@ -1,123 +0,0 @@
> -//===-- tsan_clock_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_clock.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -TEST(Clock, VectorBasic) {
> -  ScopedInRtl in_rtl;
> -  ThreadClock clk;
> -  CHECK_EQ(clk.size(), 0);
> -  clk.tick(0);
> -  CHECK_EQ(clk.size(), 1);
> -  CHECK_EQ(clk.get(0), 1);
> -  clk.tick(3);
> -  CHECK_EQ(clk.size(), 4);
> -  CHECK_EQ(clk.get(0), 1);
> -  CHECK_EQ(clk.get(1), 0);
> -  CHECK_EQ(clk.get(2), 0);
> -  CHECK_EQ(clk.get(3), 1);
> -  clk.tick(3);
> -  CHECK_EQ(clk.get(3), 2);
> -}
> -
> -TEST(Clock, ChunkedBasic) {
> -  ScopedInRtl in_rtl;
> -  ThreadClock vector;
> -  SyncClock chunked;
> -  CHECK_EQ(vector.size(), 0);
> -  CHECK_EQ(chunked.size(), 0);
> -  vector.acquire(&chunked);
> -  CHECK_EQ(vector.size(), 0);
> -  CHECK_EQ(chunked.size(), 0);
> -  vector.release(&chunked);
> -  CHECK_EQ(vector.size(), 0);
> -  CHECK_EQ(chunked.size(), 0);
> -  vector.acq_rel(&chunked);
> -  CHECK_EQ(vector.size(), 0);
> -  CHECK_EQ(chunked.size(), 0);
> -}
> -
> -TEST(Clock, AcquireRelease) {
> -  ScopedInRtl in_rtl;
> -  ThreadClock vector1;
> -  vector1.tick(100);
> -  SyncClock chunked;
> -  vector1.release(&chunked);
> -  CHECK_EQ(chunked.size(), 101);
> -  ThreadClock vector2;
> -  vector2.acquire(&chunked);
> -  CHECK_EQ(vector2.size(), 101);
> -  CHECK_EQ(vector2.get(0), 0);
> -  CHECK_EQ(vector2.get(1), 0);
> -  CHECK_EQ(vector2.get(99), 0);
> -  CHECK_EQ(vector2.get(100), 1);
> -}
> -
> -TEST(Clock, ManyThreads) {
> -  ScopedInRtl in_rtl;
> -  SyncClock chunked;
> -  for (int i = 0; i < 100; i++) {
> -    ThreadClock vector;
> -    vector.tick(i);
> -    vector.release(&chunked);
> -    CHECK_EQ(chunked.size(), i + 1);
> -    vector.acquire(&chunked);
> -    CHECK_EQ(vector.size(), i + 1);
> -  }
> -  ThreadClock vector;
> -  vector.acquire(&chunked);
> -  CHECK_EQ(vector.size(), 100);
> -  for (int i = 0; i < 100; i++)
> -    CHECK_EQ(vector.get(i), 1);
> -}
> -
> -TEST(Clock, DifferentSizes) {
> -  ScopedInRtl in_rtl;
> -  {
> -    ThreadClock vector1;
> -    vector1.tick(10);
> -    ThreadClock vector2;
> -    vector2.tick(20);
> -    {
> -      SyncClock chunked;
> -      vector1.release(&chunked);
> -      CHECK_EQ(chunked.size(), 11);
> -      vector2.release(&chunked);
> -      CHECK_EQ(chunked.size(), 21);
> -    }
> -    {
> -      SyncClock chunked;
> -      vector2.release(&chunked);
> -      CHECK_EQ(chunked.size(), 21);
> -      vector1.release(&chunked);
> -      CHECK_EQ(chunked.size(), 21);
> -    }
> -    {
> -      SyncClock chunked;
> -      vector1.release(&chunked);
> -      vector2.acquire(&chunked);
> -      CHECK_EQ(vector2.size(), 21);
> -    }
> -    {
> -      SyncClock chunked;
> -      vector2.release(&chunked);
> -      vector1.acquire(&chunked);
> -      CHECK_EQ(vector1.size(), 21);
> -    }
> -  }
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_flags_test.cc (removed)
> @@ -1,38 +0,0 @@
> -//===-- tsan_flags_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_flags.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -TEST(Flags, Basic) {
> -  ScopedInRtl in_rtl;
> -  // At least should not crash.
> -  Flags f = {};
> -  InitializeFlags(&f, 0);
> -  InitializeFlags(&f, "");
> -}
> -
> -TEST(Flags, DefaultValues) {
> -  ScopedInRtl in_rtl;
> -  Flags f = {};
> -
> -  f.enable_annotations = false;
> -  f.exitcode = -11;
> -  InitializeFlags(&f, "");
> -  EXPECT_EQ(66, f.exitcode);
> -  EXPECT_EQ(true, f.enable_annotations);
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_mman_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_mman_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_mman_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_mman_test.cc (removed)
> @@ -1,109 +0,0 @@
> -//===-- tsan_mman_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_mman.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -TEST(Mman, Internal) {
> -  ScopedInRtl in_rtl;
> -  char *p = (char*)internal_alloc(MBlockScopedBuf, 10);
> -  EXPECT_NE(p, (char*)0);
> -  char *p2 = (char*)internal_alloc(MBlockScopedBuf, 20);
> -  EXPECT_NE(p2, (char*)0);
> -  EXPECT_NE(p2, p);
> -  for (int i = 0; i < 10; i++) {
> -    p[i] = 42;
> -  }
> -  for (int i = 0; i < 20; i++) {
> -    ((char*)p2)[i] = 42;
> -  }
> -  internal_free(p);
> -  internal_free(p2);
> -}
> -
> -TEST(Mman, User) {
> -  ScopedInRtl in_rtl;
> -  ThreadState *thr = cur_thread();
> -  uptr pc = 0;
> -  char *p = (char*)user_alloc(thr, pc, 10);
> -  EXPECT_NE(p, (char*)0);
> -  char *p2 = (char*)user_alloc(thr, pc, 20);
> -  EXPECT_NE(p2, (char*)0);
> -  EXPECT_NE(p2, p);
> -  MBlock *b = user_mblock(thr, p);
> -  EXPECT_NE(b, (MBlock*)0);
> -  EXPECT_EQ(b->size, (uptr)10);
> -  MBlock *b2 = user_mblock(thr, p2);
> -  EXPECT_NE(b2, (MBlock*)0);
> -  EXPECT_EQ(b2->size, (uptr)20);
> -  for (int i = 0; i < 10; i++) {
> -    p[i] = 42;
> -    EXPECT_EQ(b, user_mblock(thr, p + i));
> -  }
> -  for (int i = 0; i < 20; i++) {
> -    ((char*)p2)[i] = 42;
> -    EXPECT_EQ(b2, user_mblock(thr, p2 + i));
> -  }
> -  user_free(thr, pc, p);
> -  user_free(thr, pc, p2);
> -}
> -
> -TEST(Mman, UserRealloc) {
> -  ScopedInRtl in_rtl;
> -  ThreadState *thr = cur_thread();
> -  uptr pc = 0;
> -  {
> -    void *p = user_realloc(thr, pc, 0, 0);
> -    // Strictly saying this is incorrect, realloc(NULL, N) is equivalent to
> -    // malloc(N), thus must return non-NULL pointer.
> -    EXPECT_EQ(p, (void*)0);
> -  }
> -  {
> -    void *p = user_realloc(thr, pc, 0, 100);
> -    EXPECT_NE(p, (void*)0);
> -    memset(p, 0xde, 100);
> -    user_free(thr, pc, p);
> -  }
> -  {
> -    void *p = user_alloc(thr, pc, 100);
> -    EXPECT_NE(p, (void*)0);
> -    memset(p, 0xde, 100);
> -    void *p2 = user_realloc(thr, pc, p, 0);
> -    EXPECT_EQ(p2, (void*)0);
> -  }
> -  {
> -    void *p = user_realloc(thr, pc, 0, 100);
> -    EXPECT_NE(p, (void*)0);
> -    memset(p, 0xde, 100);
> -    void *p2 = user_realloc(thr, pc, p, 10000);
> -    EXPECT_NE(p2, (void*)0);
> -    for (int i = 0; i < 100; i++)
> -      EXPECT_EQ(((char*)p2)[i], (char)0xde);
> -    memset(p2, 0xde, 10000);
> -    user_free(thr, pc, p2);
> -  }
> -  {
> -    void *p = user_realloc(thr, pc, 0, 10000);
> -    EXPECT_NE(p, (void*)0);
> -    memset(p, 0xde, 10000);
> -    void *p2 = user_realloc(thr, pc, p, 10);
> -    EXPECT_NE(p2, (void*)0);
> -    for (int i = 0; i < 10; i++)
> -      EXPECT_EQ(((char*)p2)[i], (char)0xde);
> -    user_free(thr, pc, p2);
> -  }
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_mutex_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_mutex_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_mutex_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_mutex_test.cc (removed)
> @@ -1,126 +0,0 @@
> -//===-- tsan_mutex_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "sanitizer_common/sanitizer_internal_defs.h"
> -#include "sanitizer_common/sanitizer_atomic.h"
> -#include "sanitizer_common/sanitizer_common.h"
> -#include "sanitizer_common/sanitizer_mutex.h"
> -#include "tsan_mutex.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -template<typename MutexType>
> -class TestData {
> - public:
> -  explicit TestData(MutexType *mtx)
> -    : mtx_(mtx) {
> -    for (int i = 0; i < kSize; i++)
> -      data_[i] = 0;
> -  }
> -
> -  void Write() {
> -    Lock l(mtx_);
> -    T v0 = data_[0];
> -    for (int i = 0; i < kSize; i++) {
> -      CHECK_EQ(data_[i], v0);
> -      data_[i]++;
> -    }
> -  }
> -
> -  void Read() {
> -    ReadLock l(mtx_);
> -    T v0 = data_[0];
> -    for (int i = 0; i < kSize; i++) {
> -      CHECK_EQ(data_[i], v0);
> -    }
> -  }
> -
> -  void Backoff() {
> -    volatile T data[kSize] = {};
> -    for (int i = 0; i < kSize; i++) {
> -      data[i]++;
> -      CHECK_EQ(data[i], 1);
> -    }
> -  }
> -
> - private:
> -  typedef GenericScopedLock<MutexType> Lock;
> -  static const int kSize = 64;
> -  typedef u64 T;
> -  MutexType *mtx_;
> -  char pad_[kCacheLineSize];
> -  T data_[kSize];
> -};
> -
> -const int kThreads = 8;
> -const int kWriteRate = 1024;
> -#if TSAN_DEBUG
> -const int kIters = 16*1024;
> -#else
> -const int kIters = 64*1024;
> -#endif
> -
> -template<typename MutexType>
> -static void *write_mutex_thread(void *param) {
> -  TestData<MutexType> *data = (TestData<MutexType>*)param;
> -  for (int i = 0; i < kIters; i++) {
> -    data->Write();
> -    data->Backoff();
> -  }
> -  return 0;
> -}
> -
> -template<typename MutexType>
> -static void *read_mutex_thread(void *param) {
> -  TestData<MutexType> *data = (TestData<MutexType>*)param;
> -  for (int i = 0; i < kIters; i++) {
> -    if ((i % kWriteRate) == 0)
> -      data->Write();
> -    else
> -      data->Read();
> -    data->Backoff();
> -  }
> -  return 0;
> -}
> -
> -TEST(Mutex, Write) {
> -  Mutex mtx(MutexTypeAnnotations, StatMtxAnnotations);
> -  TestData<Mutex> data(&mtx);
> -  pthread_t threads[kThreads];
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_create(&threads[i], 0, write_mutex_thread<Mutex>, &data);
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_join(threads[i], 0);
> -}
> -
> -TEST(Mutex, ReadWrite) {
> -  Mutex mtx(MutexTypeAnnotations, StatMtxAnnotations);
> -  TestData<Mutex> data(&mtx);
> -  pthread_t threads[kThreads];
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_create(&threads[i], 0, read_mutex_thread<Mutex>, &data);
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_join(threads[i], 0);
> -}
> -
> -TEST(Mutex, SpinWrite) {
> -  SpinMutex mtx;
> -  TestData<SpinMutex> data(&mtx);
> -  pthread_t threads[kThreads];
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_create(&threads[i], 0, write_mutex_thread<SpinMutex>, &data);
> -  for (int i = 0; i < kThreads; i++)
> -    pthread_join(threads[i], 0);
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_platform_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_platform_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_platform_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_platform_test.cc (removed)
> @@ -1,88 +0,0 @@
> -//===-- tsan_platform_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "sanitizer_common/sanitizer_libc.h"
> -#include "tsan_platform.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -static void TestThreadInfo(bool main) {
> -  ScopedInRtl in_rtl;
> -  uptr stk_addr = 0;
> -  uptr stk_size = 0;
> -  uptr tls_addr = 0;
> -  uptr tls_size = 0;
> -  GetThreadStackAndTls(main, &stk_addr, &stk_size, &tls_addr, &tls_size);
> -  // Printf("stk=%zx-%zx(%zu)\n", stk_addr, stk_addr + stk_size, stk_size);
> -  // Printf("tls=%zx-%zx(%zu)\n", tls_addr, tls_addr + tls_size, tls_size);
> -
> -  int stack_var;
> -  EXPECT_NE(stk_addr, (uptr)0);
> -  EXPECT_NE(stk_size, (uptr)0);
> -  EXPECT_GT((uptr)&stack_var, stk_addr);
> -  EXPECT_LT((uptr)&stack_var, stk_addr + stk_size);
> -
> -  static __thread int thread_var;
> -  EXPECT_NE(tls_addr, (uptr)0);
> -  EXPECT_NE(tls_size, (uptr)0);
> -  EXPECT_GT((uptr)&thread_var, tls_addr);
> -  EXPECT_LT((uptr)&thread_var, tls_addr + tls_size);
> -
> -  // Ensure that tls and stack do not intersect.
> -  uptr tls_end = tls_addr + tls_size;
> -  EXPECT_TRUE(tls_addr < stk_addr || tls_addr >= stk_addr + stk_size);
> -  EXPECT_TRUE(tls_end  < stk_addr || tls_end  >=  stk_addr + stk_size);
> -  EXPECT_TRUE((tls_addr < stk_addr) == (tls_end  < stk_addr));
> -}
> -
> -static void *WorkerThread(void *arg) {
> -  TestThreadInfo(false);
> -  return 0;
> -}
> -
> -TEST(Platform, ThreadInfoMain) {
> -  TestThreadInfo(true);
> -}
> -
> -TEST(Platform, ThreadInfoWorker) {
> -  pthread_t t;
> -  pthread_create(&t, 0, WorkerThread, 0);
> -  pthread_join(t, 0);
> -}
> -
> -TEST(Platform, FileOps) {
> -  const char *str1 = "qwerty";
> -  uptr len1 = internal_strlen(str1);
> -  const char *str2 = "zxcv";
> -  uptr len2 = internal_strlen(str2);
> -
> -  fd_t fd = internal_open("./tsan_test.tmp", true);
> -  EXPECT_NE(fd, kInvalidFd);
> -  EXPECT_EQ(len1, internal_write(fd, str1, len1));
> -  EXPECT_EQ(len2, internal_write(fd, str2, len2));
> -  internal_close(fd);
> -
> -  fd = internal_open("./tsan_test.tmp", false);
> -  EXPECT_NE(fd, kInvalidFd);
> -  EXPECT_EQ(len1 + len2, internal_filesize(fd));
> -  char buf[64] = {};
> -  EXPECT_EQ(len1, internal_read(fd, buf, len1));
> -  EXPECT_EQ(0, internal_memcmp(buf, str1, len1));
> -  EXPECT_EQ((char)0, buf[len1 + 1]);
> -  internal_memset(buf, 0, len1);
> -  EXPECT_EQ(len2, internal_read(fd, buf, len2));
> -  EXPECT_EQ(0, internal_memcmp(buf, str2, len2));
> -  internal_close(fd);
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_printf_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_printf_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_printf_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_printf_test.cc (removed)
> @@ -1,106 +0,0 @@
> -//===-- tsan_printf_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -#include <string.h>
> -#include <limits.h>
> -
> -namespace __tsan {
> -
> -TEST(Printf, Basic) {
> -  char buf[1024];
> -  uptr len = internal_snprintf(buf, sizeof(buf),
> -      "a%db%zdc%ue%zuf%xh%zxq%pe%sr",
> -      (int)-1, (long)-2, // NOLINT
> -      (unsigned)-4, (unsigned long)5, // NOLINT
> -      (unsigned)10, (unsigned long)11, // NOLINT
> -      (void*)0x123, "_string_");
> -  EXPECT_EQ(len, strlen(buf));
> -  EXPECT_EQ(0, strcmp(buf, "a-1b-2c4294967292e5fahbq"
> -                           "0x000000000123e_string_r"));
> -}
> -
> -TEST(Printf, OverflowStr) {
> -  char buf[] = "123456789";
> -  uptr len = internal_snprintf(buf, 4, "%s", "abcdef");  // NOLINT
> -  EXPECT_EQ(len, (uptr)6);
> -  EXPECT_EQ(0, strcmp(buf, "abc"));
> -  EXPECT_EQ(buf[3], 0);
> -  EXPECT_EQ(buf[4], '5');
> -  EXPECT_EQ(buf[5], '6');
> -  EXPECT_EQ(buf[6], '7');
> -  EXPECT_EQ(buf[7], '8');
> -  EXPECT_EQ(buf[8], '9');
> -  EXPECT_EQ(buf[9], 0);
> -}
> -
> -TEST(Printf, OverflowInt) {
> -  char buf[] = "123456789";
> -  internal_snprintf(buf, 4, "%d", -123456789);  // NOLINT
> -  EXPECT_EQ(0, strcmp(buf, "-12"));
> -  EXPECT_EQ(buf[3], 0);
> -  EXPECT_EQ(buf[4], '5');
> -  EXPECT_EQ(buf[5], '6');
> -  EXPECT_EQ(buf[6], '7');
> -  EXPECT_EQ(buf[7], '8');
> -  EXPECT_EQ(buf[8], '9');
> -  EXPECT_EQ(buf[9], 0);
> -}
> -
> -TEST(Printf, OverflowUint) {
> -  char buf[] = "123456789";
> -  internal_snprintf(buf, 4, "a%zx", (unsigned long)0x123456789);  // NOLINT
> -  EXPECT_EQ(0, strcmp(buf, "a12"));
> -  EXPECT_EQ(buf[3], 0);
> -  EXPECT_EQ(buf[4], '5');
> -  EXPECT_EQ(buf[5], '6');
> -  EXPECT_EQ(buf[6], '7');
> -  EXPECT_EQ(buf[7], '8');
> -  EXPECT_EQ(buf[8], '9');
> -  EXPECT_EQ(buf[9], 0);
> -}
> -
> -TEST(Printf, OverflowPtr) {
> -  char buf[] = "123456789";
> -  internal_snprintf(buf, 4, "%p", (void*)0x123456789);  // NOLINT
> -  EXPECT_EQ(0, strcmp(buf, "0x0"));
> -  EXPECT_EQ(buf[3], 0);
> -  EXPECT_EQ(buf[4], '5');
> -  EXPECT_EQ(buf[5], '6');
> -  EXPECT_EQ(buf[6], '7');
> -  EXPECT_EQ(buf[7], '8');
> -  EXPECT_EQ(buf[8], '9');
> -  EXPECT_EQ(buf[9], 0);
> -}
> -
> -template<typename T>
> -static void TestMinMax(const char *fmt, T min, T max) {
> -  char buf[1024];
> -  uptr len = internal_snprintf(buf, sizeof(buf), fmt, min, max);
> -  char buf2[1024];
> -  snprintf(buf2, sizeof(buf2), fmt, min, max);
> -  EXPECT_EQ(len, strlen(buf));
> -  EXPECT_EQ(0, strcmp(buf, buf2));
> -}
> -
> -TEST(Printf, MinMax) {
> -  TestMinMax<int>("%d-%d", INT_MIN, INT_MAX);  // NOLINT
> -  TestMinMax<long>("%zd-%zd", LONG_MIN, LONG_MAX);  // NOLINT
> -  TestMinMax<unsigned>("%u-%u", 0, UINT_MAX);  // NOLINT
> -  TestMinMax<unsigned long>("%zu-%zu", 0, ULONG_MAX);  // NOLINT
> -  TestMinMax<unsigned>("%x-%x", 0, UINT_MAX);  // NOLINT
> -  TestMinMax<unsigned long>("%zx-%zx", 0, ULONG_MAX);  // NOLINT
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_shadow_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_shadow_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_shadow_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_shadow_test.cc (removed)
> @@ -1,47 +0,0 @@
> -//===-- tsan_shadow_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_platform.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -TEST(Shadow, Mapping) {
> -  static int global;
> -  int stack;
> -  void *heap = malloc(0);
> -  free(heap);
> -
> -  CHECK(IsAppMem((uptr)&global));
> -  CHECK(IsAppMem((uptr)&stack));
> -  CHECK(IsAppMem((uptr)heap));
> -
> -  CHECK(IsShadowMem(MemToShadow((uptr)&global)));
> -  CHECK(IsShadowMem(MemToShadow((uptr)&stack)));
> -  CHECK(IsShadowMem(MemToShadow((uptr)heap)));
> -}
> -
> -TEST(Shadow, Celling) {
> -  u64 aligned_data[4];
> -  char *data = (char*)aligned_data;
> -  CHECK_EQ((uptr)data % kShadowSize, 0);
> -  uptr s0 = MemToShadow((uptr)&data[0]);
> -  CHECK_EQ(s0 % kShadowSize, 0);
> -  for (unsigned i = 1; i < kShadowCell; i++)
> -    CHECK_EQ(s0, MemToShadow((uptr)&data[i]));
> -  for (unsigned i = kShadowCell; i < 2*kShadowCell; i++)
> -    CHECK_EQ(s0 + kShadowSize*kShadowCnt, MemToShadow((uptr)&data[i]));
> -  for (unsigned i = 2*kShadowCell; i < 3*kShadowCell; i++)
> -    CHECK_EQ(s0 + 2*kShadowSize*kShadowCnt, MemToShadow((uptr)&data[i]));
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_stack_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_stack_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_stack_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_stack_test.cc (removed)
> @@ -1,80 +0,0 @@
> -//===-- tsan_stack_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_sync.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -#include <string.h>
> -
> -namespace __tsan {
> -
> -static void TestStackTrace(StackTrace *trace) {
> -  ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0);
> -
> -  trace->ObtainCurrent(&thr, 0);
> -  EXPECT_EQ(trace->Size(), (uptr)0);
> -
> -  trace->ObtainCurrent(&thr, 42);
> -  EXPECT_EQ(trace->Size(), (uptr)1);
> -  EXPECT_EQ(trace->Get(0), (uptr)42);
> -
> -  *thr.shadow_stack_pos++ = 100;
> -  *thr.shadow_stack_pos++ = 101;
> -  trace->ObtainCurrent(&thr, 0);
> -  EXPECT_EQ(trace->Size(), (uptr)2);
> -  EXPECT_EQ(trace->Get(0), (uptr)100);
> -  EXPECT_EQ(trace->Get(1), (uptr)101);
> -
> -  trace->ObtainCurrent(&thr, 42);
> -  EXPECT_EQ(trace->Size(), (uptr)3);
> -  EXPECT_EQ(trace->Get(0), (uptr)100);
> -  EXPECT_EQ(trace->Get(1), (uptr)101);
> -  EXPECT_EQ(trace->Get(2), (uptr)42);
> -}
> -
> -TEST(StackTrace, Basic) {
> -  ScopedInRtl in_rtl;
> -  StackTrace trace;
> -  TestStackTrace(&trace);
> -}
> -
> -TEST(StackTrace, StaticBasic) {
> -  ScopedInRtl in_rtl;
> -  uptr buf[10];
> -  StackTrace trace1(buf, 10);
> -  TestStackTrace(&trace1);
> -  StackTrace trace2(buf, 3);
> -  TestStackTrace(&trace2);
> -}
> -
> -TEST(StackTrace, StaticTrim) {
> -  ScopedInRtl in_rtl;
> -  uptr buf[2];
> -  StackTrace trace(buf, 2);
> -  ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0);
> -
> -  *thr.shadow_stack_pos++ = 100;
> -  *thr.shadow_stack_pos++ = 101;
> -  *thr.shadow_stack_pos++ = 102;
> -  trace.ObtainCurrent(&thr, 0);
> -  EXPECT_EQ(trace.Size(), (uptr)2);
> -  EXPECT_EQ(trace.Get(0), (uptr)101);
> -  EXPECT_EQ(trace.Get(1), (uptr)102);
> -
> -  trace.ObtainCurrent(&thr, 42);
> -  EXPECT_EQ(trace.Size(), (uptr)2);
> -  EXPECT_EQ(trace.Get(0), (uptr)102);
> -  EXPECT_EQ(trace.Get(1), (uptr)42);
> -}
> -
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_suppressions_test.cc (removed)
> @@ -1,128 +0,0 @@
> -//===-- tsan_suppressions_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_suppressions.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -#include <string.h>
> -
> -namespace __tsan {
> -
> -TEST(Suppressions, Parse) {
> -  ScopedInRtl in_rtl;
> -  Suppression *supp0 = SuppressionParse(
> -    "race:foo\n"
> -    "  race:bar\n"  // NOLINT
> -    "race:baz   \n"  // NOLINT
> -    "# a comment\n"
> -    "race:quz\n"
> -  );  // NOLINT
> -  Suppression *supp = supp0;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "quz"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "baz"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> -  supp = supp->next;
> -  EXPECT_EQ((Suppression*)0, supp);
> -}
> -
> -TEST(Suppressions, Parse2) {
> -  ScopedInRtl in_rtl;
> -  Suppression *supp0 = SuppressionParse(
> -    "          # first line comment\n"  // NOLINT
> -    "  race:bar        \n"  // NOLINT
> -    "race:baz* *baz\n"
> -    "# a comment\n"
> -    "# last line comment\n"
> -  );  // NOLINT
> -  Suppression *supp = supp0;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "baz* *baz"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> -  supp = supp->next;
> -  EXPECT_EQ((Suppression*)0, supp);
> -}
> -
> -TEST(Suppressions, Parse3) {
> -  ScopedInRtl in_rtl;
> -  Suppression *supp0 = SuppressionParse(
> -    "# last suppression w/o line-feed\n"
> -    "race:foo\n"
> -    "race:bar"
> -  );  // NOLINT
> -  Suppression *supp = supp0;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> -  supp = supp->next;
> -  EXPECT_EQ((Suppression*)0, supp);
> -}
> -
> -TEST(Suppressions, ParseType) {
> -  ScopedInRtl in_rtl;
> -  Suppression *supp0 = SuppressionParse(
> -    "race:foo\n"
> -    "thread:bar\n"
> -    "mutex:baz\n"
> -    "signal:quz\n"
> -  );  // NOLINT
> -  Suppression *supp = supp0;
> -  EXPECT_EQ(supp->type, SuppressionSignal);
> -  EXPECT_EQ(0, strcmp(supp->templ, "quz"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionMutex);
> -  EXPECT_EQ(0, strcmp(supp->templ, "baz"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionThread);
> -  EXPECT_EQ(0, strcmp(supp->templ, "bar"));
> -  supp = supp->next;
> -  EXPECT_EQ(supp->type, SuppressionRace);
> -  EXPECT_EQ(0, strcmp(supp->templ, "foo"));
> -  supp = supp->next;
> -  EXPECT_EQ((Suppression*)0, supp);
> -}
> -
> -static bool MyMatch(const char *templ, const char *func) {
> -  char tmp[1024];
> -  strcpy(tmp, templ);  // NOLINT
> -  return SuppressionMatch(tmp, func);
> -}
> -
> -TEST(Suppressions, Match) {
> -  EXPECT_TRUE(MyMatch("foobar", "foobar"));
> -  EXPECT_TRUE(MyMatch("foobar", "prefix_foobar_postfix"));
> -  EXPECT_TRUE(MyMatch("*foobar*", "prefix_foobar_postfix"));
> -  EXPECT_TRUE(MyMatch("foo*bar", "foo_middle_bar"));
> -  EXPECT_TRUE(MyMatch("foo*bar", "foobar"));
> -  EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_bar_another_baz"));
> -  EXPECT_TRUE(MyMatch("foo*bar*baz", "foo_middle_barbaz"));
> -
> -  EXPECT_FALSE(MyMatch("foo", "baz"));
> -  EXPECT_FALSE(MyMatch("foobarbaz", "foobar"));
> -  EXPECT_FALSE(MyMatch("foobarbaz", "barbaz"));
> -  EXPECT_FALSE(MyMatch("foo*bar", "foobaz"));
> -  EXPECT_FALSE(MyMatch("foo*bar", "foo_baz"));
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_sync_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_sync_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_sync_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_sync_test.cc (removed)
> @@ -1,65 +0,0 @@
> -//===-- tsan_sync_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_sync.h"
> -#include "tsan_rtl.h"
> -#include "tsan_mman.h"
> -#include "gtest/gtest.h"
> -
> -#include <stdlib.h>
> -#include <stdint.h>
> -#include <map>
> -
> -namespace __tsan {
> -
> -TEST(Sync, Table) {
> -  const uintptr_t kIters = 512*1024;
> -  const uintptr_t kRange = 10000;
> -
> -  ScopedInRtl in_rtl;
> -  ThreadState *thr = cur_thread();
> -  uptr pc = 0;
> -
> -  SyncTab tab;
> -  SyncVar *golden[kRange] = {};
> -  unsigned seed = 0;
> -  for (uintptr_t i = 0; i < kIters; i++) {
> -    uintptr_t addr = rand_r(&seed) % (kRange - 1) + 1;
> -    if (rand_r(&seed) % 2) {
> -      // Get or add.
> -      SyncVar *v = tab.GetAndLock(thr, pc, addr, true);
> -      EXPECT_TRUE(golden[addr] == 0 || golden[addr] == v);
> -      EXPECT_EQ(v->addr, addr);
> -      golden[addr] = v;
> -      v->mtx.Unlock();
> -    } else {
> -      // Remove.
> -      SyncVar *v = tab.GetAndRemove(thr, pc, addr);
> -      EXPECT_EQ(golden[addr], v);
> -      if (v) {
> -        EXPECT_EQ(v->addr, addr);
> -        golden[addr] = 0;
> -        DestroyAndFree(v);
> -      }
> -    }
> -  }
> -  for (uintptr_t addr = 0; addr < kRange; addr++) {
> -    if (golden[addr] == 0)
> -      continue;
> -    SyncVar *v = tab.GetAndRemove(thr, pc, addr);
> -    EXPECT_EQ(v, golden[addr]);
> -    EXPECT_EQ(v->addr, addr);
> -    DestroyAndFree(v);
> -  }
> -}
> -
> -}  // namespace __tsan
>
> Removed: compiler-rt/trunk/lib/tsan/unit_tests/tsan_vector_test.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/unit_tests/tsan_vector_test.cc?rev=164021&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/unit_tests/tsan_vector_test.cc (original)
> +++ compiler-rt/trunk/lib/tsan/unit_tests/tsan_vector_test.cc (removed)
> @@ -1,45 +0,0 @@
> -//===-- tsan_vector_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 ThreadSanitizer (TSan), a race detector.
> -//
> -//===----------------------------------------------------------------------===//
> -#include "tsan_vector.h"
> -#include "tsan_rtl.h"
> -#include "gtest/gtest.h"
> -
> -namespace __tsan {
> -
> -TEST(Vector, Basic) {
> -  ScopedInRtl in_rtl;
> -  Vector<int> v(MBlockScopedBuf);
> -  EXPECT_EQ(v.Size(), (uptr)0);
> -  v.PushBack(42);
> -  EXPECT_EQ(v.Size(), (uptr)1);
> -  EXPECT_EQ(v[0], 42);
> -  v.PushBack(43);
> -  EXPECT_EQ(v.Size(), (uptr)2);
> -  EXPECT_EQ(v[0], 42);
> -  EXPECT_EQ(v[1], 43);
> -}
> -
> -TEST(Vector, Stride) {
> -  ScopedInRtl in_rtl;
> -  Vector<int> v(MBlockScopedBuf);
> -  for (int i = 0; i < 1000; i++) {
> -    v.PushBack(i);
> -    EXPECT_EQ(v.Size(), (uptr)(i + 1));
> -    EXPECT_EQ(v[i], i);
> -  }
> -  for (int i = 0; i < 1000; i++) {
> -    EXPECT_EQ(v[i], i);
> -  }
> -}
> -
> -}  // namespace __tsan
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list