summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-03-31 08:29:09 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-03-31 21:15:01 +0200
commit6a25f7e4e1524db7125cc67116cd989ce994c7f5 (patch)
tree5c7fc1ca67104cb8cf6d67212feb9d7bfffbf405
parent0d2668121d2b3e188dc60cb7bdb5d9dcc39beab4 (diff)
Added Atomic Tests about being lock free
-rw-r--r--test/atomictest.cc56
1 files changed, 38 insertions, 18 deletions
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<bool>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned int>());
CPPUNIT_ASSERT(isUsingStandardImpl<int>());
- }
-
- void atomicFloatUsesStandardImpl() {
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long long int>());
CPPUNIT_ASSERT(isUsingStandardImpl<float>());
- }
-
- void atomicBoolUsesStandardImpl() {
- CPPUNIT_ASSERT(isUsingStandardImpl<bool>());
- }
-
- void atomicDoubleUsesStandardImpl() {
CPPUNIT_ASSERT(isUsingStandardImpl<double>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long double>());
}
- void atomicStringCanBeUsed() {
- // note: if it couldn't be used, the compiler would complain
- Atomic<std::string> tmp;
+ void nonPodAtomicsUseOwnImpl() {
+ CPPUNIT_ASSERT(!isUsingStandardImpl<std::string>());
}
void podAtomicCanBeDefaultInitialized() {
@@ -101,6 +98,23 @@ class AtomicTest
CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
}
+ void podAtomicsAreLockFree() {
+ CPPUNIT_ASSERT(isLockFree<bool>());
+ CPPUNIT_ASSERT(isLockFree<unsigned short int>());
+ CPPUNIT_ASSERT(isLockFree<short int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned int>());
+ CPPUNIT_ASSERT(isLockFree<int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned long int>());
+ CPPUNIT_ASSERT(isLockFree<long int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned long long int>());
+ CPPUNIT_ASSERT(isLockFree<long long int>());
+ CPPUNIT_ASSERT(isLockFree<float>());
+ CPPUNIT_ASSERT(isLockFree<double>());
+
+ // compile error: undefined reference to `__atomic_is_lock_free'
+ //CPPUNIT_ASSERT(isLockFree<long double>());
+ }
+
// todo: further testing
private:
@@ -108,6 +122,12 @@ class AtomicTest
bool isUsingStandardImpl() {
return std::is_base_of<std::atomic<T>, Atomic<T>>::value;
}
+
+ template <typename T>
+ bool isLockFree() {
+ Atomic<T> a;
+ return a.is_lock_free();
+ }
};
// Registers the fixture into the 'registry'