2015-11-16 05:48:54 +03:00
|
|
|
module Cases.Litmus (tests) where
|
|
|
|
|
2015-11-19 16:57:14 +03:00
|
|
|
import Test.DejaFu (MemType(..), defaultBounds, gives')
|
2015-12-01 07:11:44 +03:00
|
|
|
import Test.Framework (Test)
|
|
|
|
import Test.Framework.Providers.HUnit (hUnitTestToTests)
|
|
|
|
import Test.HUnit (test)
|
2015-11-16 05:48:54 +03:00
|
|
|
import Test.HUnit.DejaFu (testDejafu')
|
|
|
|
|
|
|
|
import Control.Monad.Conc.Class
|
|
|
|
|
2015-12-01 07:11:44 +03:00
|
|
|
tests :: [Test]
|
|
|
|
tests = hUnitTestToTests $ test
|
2015-11-19 16:57:14 +03:00
|
|
|
[ testDejafu' SequentialConsistency defaultBounds iorefRelaxed "iorefRelaxed-SQ" $
|
|
|
|
gives' [(True, True), (True, False), (False, True)]
|
|
|
|
, testDejafu' TotalStoreOrder defaultBounds iorefRelaxed "iorefRelaxed-TSO" $
|
|
|
|
gives' [(True, True), (True, False), (False, True), (False, False)]
|
|
|
|
, testDejafu' PartialStoreOrder defaultBounds iorefRelaxed "iorefRelaxed-PSO" $
|
|
|
|
gives' [(True, True), (True, False), (False, True), (False, False)]
|
2015-11-16 05:48:54 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- | Relaxed memory test, from Data.IORef
|
|
|
|
iorefRelaxed :: MonadConc m => m (Bool, Bool)
|
|
|
|
iorefRelaxed = do
|
|
|
|
r1 <- newCRef False
|
|
|
|
r2 <- newCRef False
|
|
|
|
x <- spawn $ writeCRef r1 True >> readCRef r2
|
|
|
|
y <- spawn $ writeCRef r2 True >> readCRef r1
|
|
|
|
(,) <$> readCVar x <*> readCVar y
|