From 6a25f7e4e1524db7125cc67116cd989ce994c7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gl=C3=B6ckner?= Date: Thu, 31 Mar 2016 08:29:09 +0200 Subject: Added Atomic Tests about being lock free --- test/atomictest.cc | 56 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/atomictest.cc b/test/atomictest.cc index d73695e..1718b33 100644 --- a/test/atomictest.cc +++ b/test/atomictest.cc @@ -32,41 +32,38 @@ class AtomicTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(AtomicTest); - CPPUNIT_TEST(atomicIntUsesStandardImpl); - CPPUNIT_TEST(atomicFloatUsesStandardImpl); - CPPUNIT_TEST(atomicBoolUsesStandardImpl); - CPPUNIT_TEST(atomicStringCanBeUsed); + CPPUNIT_TEST(podAtomicsUseStandardImpl); + CPPUNIT_TEST(nonPodAtomicsUseOwnImpl); CPPUNIT_TEST(podAtomicCanBeDefaultInitialized); CPPUNIT_TEST(nonPodAtomicCanBeDefaultInitialized); CPPUNIT_TEST(podAtomicCanBeValueInitialized); CPPUNIT_TEST(nonPodAtomicCanBeValueInitialized); CPPUNIT_TEST(podAtomicCanBeValueAssigned); CPPUNIT_TEST(nonPodAtomicCanBeValueAssigned); + CPPUNIT_TEST(podAtomicsAreLockFree); CPPUNIT_TEST_SUITE_END(); public: void setUp() {} void tearDown() {} - void atomicIntUsesStandardImpl() { + void podAtomicsUseStandardImpl() { + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); CPPUNIT_ASSERT(isUsingStandardImpl()); - } - - void atomicFloatUsesStandardImpl() { + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); CPPUNIT_ASSERT(isUsingStandardImpl()); - } - - void atomicBoolUsesStandardImpl() { - CPPUNIT_ASSERT(isUsingStandardImpl()); - } - - void atomicDoubleUsesStandardImpl() { CPPUNIT_ASSERT(isUsingStandardImpl()); + CPPUNIT_ASSERT(isUsingStandardImpl()); } - void atomicStringCanBeUsed() { - // note: if it couldn't be used, the compiler would complain - Atomic tmp; + void nonPodAtomicsUseOwnImpl() { + CPPUNIT_ASSERT(!isUsingStandardImpl()); } void podAtomicCanBeDefaultInitialized() { @@ -101,6 +98,23 @@ class AtomicTest CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"}); } + void podAtomicsAreLockFree() { + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + CPPUNIT_ASSERT(isLockFree()); + + // compile error: undefined reference to `__atomic_is_lock_free' + //CPPUNIT_ASSERT(isLockFree()); + } + // todo: further testing private: @@ -108,6 +122,12 @@ class AtomicTest bool isUsingStandardImpl() { return std::is_base_of, Atomic>::value; } + + template + bool isLockFree() { + Atomic a; + return a.is_lock_free(); + } }; // Registers the fixture into the 'registry' -- cgit v1.2.3