module Test.DejaFu.Conc
(
Program
, Basic
, ConcT
, ConcIO
, WithSetup
, WithSetupAndTeardown
, withSetup
, withTeardown
, withSetupAndTeardown
, Invariant
, registerInvariant
, inspectIORef
, inspectMVar
, inspectTVar
, Snapshot
, MemType(..)
, runConcurrent
, recordSnapshot
, runSnapshot
, module Test.DejaFu.Schedule
, Condition(..)
, Trace
, Decision(..)
, ThreadId(..)
, ThreadAction(..)
, Lookahead(..)
, MVarId
, IORefId
, MaskingState(..)
, showTrace
, showCondition
) where
import Control.Exception (MaskingState(..))
import Control.Monad (void)
import Test.DejaFu.Conc.Internal.Common
import Test.DejaFu.Conc.Internal.Program
import Test.DejaFu.Conc.Internal.STM (ModelTVar)
import Test.DejaFu.Schedule
import Test.DejaFu.Types
import Test.DejaFu.Utils
type ConcT = Program Basic
type ConcIO = ConcT IO
withSetup
:: Program Basic n x
-> (x -> Program Basic n a)
-> Program (WithSetup x) n a
withSetup :: forall (n :: * -> *) x a.
Program Basic n x
-> (x -> Program Basic n a) -> Program (WithSetup x) n a
withSetup Program Basic n x
setup x -> Program Basic n a
p = WithSetup
{ wsSetup :: Program Basic n x
wsSetup = Program Basic n x
setup
, wsProgram :: x -> Program Basic n a
wsProgram = x -> Program Basic n a
p
}
withTeardown
:: (x -> Either Condition y -> Program Basic n a)
-> Program (WithSetup x) n y
-> Program (WithSetupAndTeardown x y) n a
withTeardown :: forall x y (n :: * -> *) a.
(x -> Either Condition y -> Program Basic n a)
-> Program (WithSetup x) n y
-> Program (WithSetupAndTeardown x y) n a
withTeardown x -> Either Condition y -> Program Basic n a
teardown Program (WithSetup x) n y
ws = WithSetupAndTeardown
{ wstSetup :: ModelConc n x
wstSetup = Program (WithSetup x) n y -> ModelConc n x
forall (n :: * -> *) x a.
Program (WithSetup x) n a -> ModelConc n x
wsSetup Program (WithSetup x) n y
ws
, wstProgram :: x -> ModelConc n y
wstProgram = Program (WithSetup x) n y -> x -> ModelConc n y
forall (n :: * -> *) x a.
Program (WithSetup x) n a -> x -> ModelConc n a
wsProgram Program (WithSetup x) n y
ws
, wstTeardown :: x -> Either Condition y -> Program Basic n a
wstTeardown = x -> Either Condition y -> Program Basic n a
teardown
}
withSetupAndTeardown
:: Program Basic n x
-> (x -> Either Condition y -> Program Basic n a)
-> (x -> Program Basic n y)
-> Program (WithSetupAndTeardown x y) n a
withSetupAndTeardown :: forall (n :: * -> *) x y a.
Program Basic n x
-> (x -> Either Condition y -> Program Basic n a)
-> (x -> Program Basic n y)
-> Program (WithSetupAndTeardown x y) n a
withSetupAndTeardown Program Basic n x
setup x -> Either Condition y -> Program Basic n a
teardown =
(x -> Either Condition y -> Program Basic n a)
-> Program (WithSetup x) n y
-> Program (WithSetupAndTeardown x y) n a
forall x y (n :: * -> *) a.
(x -> Either Condition y -> Program Basic n a)
-> Program (WithSetup x) n y
-> Program (WithSetupAndTeardown x y) n a
withTeardown x -> Either Condition y -> Program Basic n a
teardown (Program (WithSetup x) n y
-> Program (WithSetupAndTeardown x y) n a)
-> ((x -> Program Basic n y) -> Program (WithSetup x) n y)
-> (x -> Program Basic n y)
-> Program (WithSetupAndTeardown x y) n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Program Basic n x
-> (x -> Program Basic n y) -> Program (WithSetup x) n y
forall (n :: * -> *) x a.
Program Basic n x
-> (x -> Program Basic n a) -> Program (WithSetup x) n a
withSetup Program Basic n x
setup
registerInvariant :: Invariant n a -> Program Basic n ()
registerInvariant :: forall (n :: * -> *) a. Invariant n a -> Program Basic n ()
registerInvariant Invariant n a
inv = ((() -> Action n) -> Action n) -> Program Basic n ()
forall a (n :: * -> *).
((a -> Action n) -> Action n) -> Program Basic n a
ModelConc (\() -> Action n
c -> Invariant n () -> Action n -> Action n
forall (n :: * -> *). Invariant n () -> Action n -> Action n
ANewInvariant (Invariant n a -> Invariant n ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void Invariant n a
inv) (() -> Action n
c ()))
inspectIORef :: ModelIORef n a -> Invariant n a
inspectIORef :: forall (n :: * -> *) a. ModelIORef n a -> Invariant n a
inspectIORef = ((a -> IAction n) -> IAction n) -> Invariant n a
forall (n :: * -> *) a.
((a -> IAction n) -> IAction n) -> Invariant n a
Invariant (((a -> IAction n) -> IAction n) -> Invariant n a)
-> (ModelIORef n a -> (a -> IAction n) -> IAction n)
-> ModelIORef n a
-> Invariant n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModelIORef n a -> (a -> IAction n) -> IAction n
forall (n :: * -> *) a.
ModelIORef n a -> (a -> IAction n) -> IAction n
IInspectIORef
inspectMVar :: ModelMVar n a -> Invariant n (Maybe a)
inspectMVar :: forall (n :: * -> *) a. ModelMVar n a -> Invariant n (Maybe a)
inspectMVar = ((Maybe a -> IAction n) -> IAction n) -> Invariant n (Maybe a)
forall (n :: * -> *) a.
((a -> IAction n) -> IAction n) -> Invariant n a
Invariant (((Maybe a -> IAction n) -> IAction n) -> Invariant n (Maybe a))
-> (ModelMVar n a -> (Maybe a -> IAction n) -> IAction n)
-> ModelMVar n a
-> Invariant n (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModelMVar n a -> (Maybe a -> IAction n) -> IAction n
forall (n :: * -> *) a.
ModelMVar n a -> (Maybe a -> IAction n) -> IAction n
IInspectMVar
inspectTVar :: ModelTVar n a -> Invariant n a
inspectTVar :: forall (n :: * -> *) a. ModelTVar n a -> Invariant n a
inspectTVar = ((a -> IAction n) -> IAction n) -> Invariant n a
forall (n :: * -> *) a.
((a -> IAction n) -> IAction n) -> Invariant n a
Invariant (((a -> IAction n) -> IAction n) -> Invariant n a)
-> (ModelTVar n a -> (a -> IAction n) -> IAction n)
-> ModelTVar n a
-> Invariant n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModelTVar n a -> (a -> IAction n) -> IAction n
forall (n :: * -> *) a.
ModelTVar n a -> (a -> IAction n) -> IAction n
IInspectTVar