forked from OSchip/llvm-project
[Sanitizer] Add basic test for atomic_compare_exchange implementation
llvm-svn: 177851
This commit is contained in:
parent
13df03624b
commit
c6fd019c77
|
@ -113,9 +113,9 @@ INLINE bool atomic_compare_exchange_strong(volatile T *a,
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue