X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FSynchronizedTest.cpp;h=db0f9c93ce6509a8736008d9008b24263223f9e8;hb=7acba7e1a0a75d22087647b3e9e830c9b0e8d41e;hp=adbac4194a735f987371cea1e83ed7a072d67edc;hpb=6a6ac91e1fda65d7871390f03be8d19b3591ba45;p=folly.git diff --git a/folly/test/SynchronizedTest.cpp b/folly/test/SynchronizedTest.cpp index adbac419..db0f9c93 100644 --- a/folly/test/SynchronizedTest.cpp +++ b/folly/test/SynchronizedTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include using namespace folly::sync_tests; @@ -330,69 +330,20 @@ class FakeAllPowerfulAssertingMutex { } }; -// Single level of SYNCHRONIZED and UNSYNCHRONIZED, although nested test are -// super set of it, it is possible single level test passes while nested tests -// fail -TEST_F(SynchronizedLockTest, SyncUnSync) { - folly::Synchronized, FakeMutex> obj; - EXPECT_EQ((CountPair{0, 0}), FakeMutex::getLockUnlockCount()); - SYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{1, 0}), FakeMutex::getLockUnlockCount()); - UNSYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{1, 1}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{2, 1}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{2, 2}), FakeMutex::getLockUnlockCount()); -} - -// Nested SYNCHRONIZED UNSYNCHRONIZED test, 2 levels of synchronization -TEST_F(SynchronizedLockTest, NestedSyncUnSync) { - folly::Synchronized, FakeMutex> obj; - EXPECT_EQ((CountPair{0, 0}), FakeMutex::getLockUnlockCount()); - SYNCHRONIZED(objCopy, obj) { - EXPECT_EQ((CountPair{1, 0}), FakeMutex::getLockUnlockCount()); - SYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{2, 0}), FakeMutex::getLockUnlockCount()); - // Note: UNSYNCHRONIZED has always been kind of broken here. - // The input parameter is ignored (other than to overwrite what the input - // variable name refers to), and it unlocks the most object acquired in - // the most recent SYNCHRONIZED scope. - UNSYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{2, 1}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{3, 1}), FakeMutex::getLockUnlockCount()); - UNSYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{3, 2}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{4, 2}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{4, 3}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{4, 4}), FakeMutex::getLockUnlockCount()); -} - -// Different nesting behavior, UNSYNCHRONIZED called on different depth of -// SYNCHRONIZED -TEST_F(SynchronizedLockTest, NestedSyncUnSync2) { - folly::Synchronized, FakeMutex> obj; - EXPECT_EQ((CountPair{0, 0}), FakeMutex::getLockUnlockCount()); - SYNCHRONIZED(objCopy, obj) { - EXPECT_EQ((CountPair{1, 0}), FakeMutex::getLockUnlockCount()); - SYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{2, 0}), FakeMutex::getLockUnlockCount()); - UNSYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{2, 1}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{3, 1}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{3, 2}), FakeMutex::getLockUnlockCount()); - UNSYNCHRONIZED(obj) { - EXPECT_EQ((CountPair{3, 3}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{4, 3}), FakeMutex::getLockUnlockCount()); - } - EXPECT_EQ((CountPair{4, 4}), FakeMutex::getLockUnlockCount()); +TEST_F(SynchronizedLockTest, TestCopyConstructibleValues) { + struct NonCopyConstructible { + NonCopyConstructible(const NonCopyConstructible&) = delete; + NonCopyConstructible& operator=(const NonCopyConstructible&) = delete; + }; + struct CopyConstructible {}; + EXPECT_FALSE(std::is_copy_constructible< + folly::Synchronized>::value); + EXPECT_FALSE(std::is_copy_assignable< + folly::Synchronized>::value); + EXPECT_TRUE(std::is_copy_constructible< + folly::Synchronized>::value); + EXPECT_TRUE( + std::is_copy_assignable>::value); } TEST_F(SynchronizedLockTest, UpgradableLocking) {