[compiler-rt] r177851 - [Sanitizer] Add basic test for atomic_compare_exchange implementation
Alexey Samsonov
samsonov at google.com
Mon Mar 25 01:48:16 PDT 2013
Author: samsonov
Date: Mon Mar 25 03:48:16 2013
New Revision: 177851
URL: http://llvm.org/viewvc/llvm-project?rev=177851&view=rev
Log:
[Sanitizer] Add basic test for atomic_compare_exchange implementation
Added:
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_clang.h
compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_clang.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_clang.h?rev=177851&r1=177850&r2=177851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_clang.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_atomic_clang.h Mon Mar 25 03:48:16 2013
@@ -113,9 +113,9 @@ INLINE bool atomic_compare_exchange_stro
template<typename T>
INLINE bool atomic_compare_exchange_weak(volatile T *a,
- typename T::Type *cmp,
- typename T::Type xchg,
- memory_order mo) {
+ typename T::Type *cmp,
+ typename T::Type xchg,
+ memory_order mo) {
return atomic_compare_exchange_strong(a, cmp, xchg, mo);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=177851&r1=177850&r2=177851&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Mon Mar 25 03:48:16 2013
@@ -2,6 +2,7 @@ include(CompilerRTCompile)
set(SANITIZER_UNITTESTS
sanitizer_allocator_test.cc
+ sanitizer_atomic_test.cc
sanitizer_common_test.cc
sanitizer_flags_test.cc
sanitizer_libc_test.cc
Added: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc?rev=177851&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_atomic_test.cc Mon Mar 25 03:48:16 2013
@@ -0,0 +1,51 @@
+//===-- sanitizer_atomic_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/AddressSanitizer runtime.
+//
+//===----------------------------------------------------------------------===//
+#include "sanitizer_common/sanitizer_atomic.h"
+#include "gtest/gtest.h"
+
+namespace __sanitizer {
+
+template<typename T>
+void CheckAtomicCompareExchange() {
+ typedef typename T::Type Type;
+ {
+ Type old_val = 42;
+ Type new_val = 24;
+ Type var = old_val;
+ EXPECT_TRUE(atomic_compare_exchange_strong((T*)&var, &old_val, new_val,
+ memory_order_relaxed));
+ EXPECT_FALSE(atomic_compare_exchange_strong((T*)&var, &old_val, new_val,
+ memory_order_relaxed));
+ EXPECT_EQ(new_val, old_val);
+ }
+ {
+ Type old_val = 42;
+ Type new_val = 24;
+ Type var = old_val;
+ EXPECT_TRUE(atomic_compare_exchange_weak((T*)&var, &old_val, new_val,
+ memory_order_relaxed));
+ EXPECT_FALSE(atomic_compare_exchange_weak((T*)&var, &old_val, new_val,
+ memory_order_relaxed));
+ EXPECT_EQ(new_val, old_val);
+ }
+}
+
+TEST(SanitizerCommon, AtomicCompareExchangeTest) {
+ CheckAtomicCompareExchange<atomic_uint8_t>();
+ CheckAtomicCompareExchange<atomic_uint16_t>();
+ CheckAtomicCompareExchange<atomic_uint32_t>();
+ CheckAtomicCompareExchange<atomic_uint64_t>();
+ CheckAtomicCompareExchange<atomic_uintptr_t>();
+}
+
+} // namespace __sanitizer
More information about the llvm-commits
mailing list