dejafu-1.3.0.3: A library for unit-testing concurrent programs.

Copyright(c) 2017 Michael Walker
LicenseMIT
MaintainerMichael Walker <mike@barrucadu.co.uk>
Stabilityexperimental
PortabilityGeneralizedNewtypeDeriving
Safe HaskellNone
LanguageHaskell2010

Test.DejaFu.Types

Contents

Description

Common types and functions used throughout DejaFu.

Synopsis

Identifiers

newtype ThreadId Source #

Every thread has a unique identitifer.

Since: 1.0.0.0

Constructors

ThreadId Id 

newtype CRefId Source #

Every CRef has a unique identifier.

Since: 1.0.0.0

Constructors

CRefId Id 

newtype MVarId Source #

Every MVar has a unique identifier.

Since: 1.0.0.0

Constructors

MVarId Id 

newtype TVarId Source #

Every TVar has a unique identifier.

Since: 1.0.0.0

Constructors

TVarId Id 

data Id Source #

An identifier for a thread, MVar, CRef, or TVar.

The number is the important bit. The string is to make execution traces easier to read, but is meaningless.

Constructors

Id (Maybe String) !Int 

Instances

Eq Id Source # 

Methods

(==) :: Id -> Id -> Bool #

(/=) :: Id -> Id -> Bool #

Ord Id Source # 

Methods

compare :: Id -> Id -> Ordering #

(<) :: Id -> Id -> Bool #

(<=) :: Id -> Id -> Bool #

(>) :: Id -> Id -> Bool #

(>=) :: Id -> Id -> Bool #

max :: Id -> Id -> Id #

min :: Id -> Id -> Id #

Show Id Source # 

Methods

showsPrec :: Int -> Id -> ShowS #

show :: Id -> String #

showList :: [Id] -> ShowS #

NFData Id Source # 

Methods

rnf :: Id -> () #

initialThread :: ThreadId Source #

The ID of the initial thread.

Since: 0.4.0.0

Actions

data ThreadAction Source #

All the actions that a thread can perform.

Since: 1.1.0.0

Constructors

Fork ThreadId

Start a new thread.

ForkOS ThreadId

Start a new bound thread.

IsCurrentThreadBound Bool

Check if the current thread is bound.

MyThreadId

Get the ThreadId of the current thread.

GetNumCapabilities Int

Get the number of Haskell threads that can run simultaneously.

SetNumCapabilities Int

Set the number of Haskell threads that can run simultaneously.

Yield

Yield the current thread.

ThreadDelay Int

Yield/delay the current thread.

NewMVar MVarId

Create a new MVar.

PutMVar MVarId [ThreadId]

Put into a MVar, possibly waking up some threads.

BlockedPutMVar MVarId

Get blocked on a put.

TryPutMVar MVarId Bool [ThreadId]

Try to put into a MVar, possibly waking up some threads.

ReadMVar MVarId

Read from a MVar.

TryReadMVar MVarId Bool

Try to read from a MVar.

BlockedReadMVar MVarId

Get blocked on a read.

TakeMVar MVarId [ThreadId]

Take from a MVar, possibly waking up some threads.

BlockedTakeMVar MVarId

Get blocked on a take.

TryTakeMVar MVarId Bool [ThreadId]

Try to take from a MVar, possibly waking up some threads.

NewCRef CRefId

Create a new CRef.

ReadCRef CRefId

Read from a CRef.

ReadCRefCas CRefId

Read from a CRef for a future compare-and-swap.

ModCRef CRefId

Modify a CRef.

ModCRefCas CRefId

Modify a CRef using a compare-and-swap.

WriteCRef CRefId

Write to a CRef without synchronising.

CasCRef CRefId Bool

Attempt to to a CRef using a compare-and-swap, synchronising it.

CommitCRef ThreadId CRefId

Commit the last write to the given CRef by the given thread, so that all threads can see the updated value.

STM [TAction] [ThreadId]

An STM transaction was executed, possibly waking up some threads.

BlockedSTM [TAction]

Got blocked in an STM transaction.

Catching

Register a new exception handler

PopCatching

Pop the innermost exception handler from the stack.

Throw

Throw an exception.

ThrowTo ThreadId

Throw an exception to a thread.

BlockedThrowTo ThreadId

Get blocked on a throwTo.

Killed

Killed by an uncaught exception.

SetMasking Bool MaskingState

Set the masking state. If True, this is being used to set the masking state to the original state in the argument passed to a masked function.

ResetMasking Bool MaskingState

Return to an earlier masking state. If True, this is being used to return to the state of the masked block in the argument passed to a masked function.

LiftIO

Lift an IO action. Note that this can only happen with ConcIO.

Return

A return or pure action was executed.

Stop

Cease execution and terminate.

Subconcurrency

Start executing an action with subconcurrency.

StopSubconcurrency

Stop executing an action with subconcurrency.

DontCheck Trace

Execute an action with dontCheck.

data Lookahead Source #

A one-step look-ahead at what a thread will do next.

Since: 1.1.0.0

Constructors

WillFork

Will start a new thread.

WillForkOS

Will start a new bound thread.

WillIsCurrentThreadBound

Will check if the current thread is bound.

WillMyThreadId

Will get the ThreadId.

WillGetNumCapabilities

Will get the number of Haskell threads that can run simultaneously.

WillSetNumCapabilities Int

Will set the number of Haskell threads that can run simultaneously.

WillYield

Will yield the current thread.

WillThreadDelay Int

Will yield/delay the current thread.

WillNewMVar

Will create a new MVar.

WillPutMVar MVarId

Will put into a MVar, possibly waking up some threads.

WillTryPutMVar MVarId

Will try to put into a MVar, possibly waking up some threads.

WillReadMVar MVarId

Will read from a MVar.

WillTryReadMVar MVarId

Will try to read from a MVar.

WillTakeMVar MVarId

Will take from a MVar, possibly waking up some threads.

WillTryTakeMVar MVarId

Will try to take from a MVar, possibly waking up some threads.

WillNewCRef

Will create a new CRef.

WillReadCRef CRefId

Will read from a CRef.

WillReadCRefCas CRefId

Will read from a CRef for a future compare-and-swap.

WillModCRef CRefId

Will modify a CRef.

WillModCRefCas CRefId

Will modify a CRef using a compare-and-swap.

WillWriteCRef CRefId

Will write to a CRef without synchronising.

WillCasCRef CRefId

Will attempt to to a CRef using a compare-and-swap, synchronising it.

WillCommitCRef ThreadId CRefId

Will commit the last write by the given thread to the CRef.

WillSTM

Will execute an STM transaction, possibly waking up some threads.

WillCatching

Will register a new exception handler

WillPopCatching

Will pop the innermost exception handler from the stack.

WillThrow

Will throw an exception.

WillThrowTo ThreadId

Will throw an exception to a thread.

WillSetMasking Bool MaskingState

Will set the masking state. If True, this is being used to set the masking state to the original state in the argument passed to a masked function.

WillResetMasking Bool MaskingState

Will return to an earlier masking state. If True, this is being used to return to the state of the masked block in the argument passed to a masked function.

WillLiftIO

Will lift an IO action. Note that this can only happen with ConcIO.

WillReturn

Will execute a return or pure action.

WillStop

Will cease execution and terminate.

WillSubconcurrency

Will execute an action with subconcurrency.

WillStopSubconcurrency

Will stop executing an extion with subconcurrency.

WillDontCheck

Will execute an action with dontCheck.

data TAction Source #

All the actions that an STM transaction can perform.

Since: 0.8.0.0

Constructors

TNew TVarId

Create a new TVar

TRead TVarId

Read from a TVar.

TWrite TVarId

Write to a TVar.

TRetry

Abort and discard effects.

TOrElse [TAction] (Maybe [TAction])

Execute a transaction. If the transaction aborts by calling retry, execute the other transaction.

TThrow

Throw an exception, abort, and discard effects.

TCatch [TAction] (Maybe [TAction])

Execute a transaction. If the transaction aborts by throwing an exception of the appropriate type, it is handled and execution continues; otherwise aborts, propagating the exception upwards.

TStop

Terminate successfully and commit effects.

Instances

Eq TAction Source # 

Methods

(==) :: TAction -> TAction -> Bool #

(/=) :: TAction -> TAction -> Bool #

Show TAction Source # 
NFData TAction Source #

Since: 0.5.1.0

Methods

rnf :: TAction -> () #

Traces

type Trace = [(Decision, [(ThreadId, Lookahead)], ThreadAction)] Source #

One of the outputs of the runner is a Trace, which is a log of decisions made, all the alternative unblocked threads and what they would do, and the action a thread took in its step.

Since: 0.8.0.0

data Decision Source #

Scheduling decisions are based on the state of the running program, and so we can capture some of that state in recording what specific decision we made.

Since: 0.5.0.0

Constructors

Start ThreadId

Start a new thread, because the last was blocked (or it's the start of computation).

Continue

Continue running the last thread for another step.

SwitchTo ThreadId

Pre-empt the running thread, and switch to another.

Instances

Failures

data Failure Source #

An indication of how a concurrent computation failed.

The Eq, Ord, and NFData instances compare/evaluate the exception with show in the UncaughtException case.

Since: 1.1.0.0

Constructors

InternalError

Will be raised if the scheduler does something bad. This should never arise unless you write your own, faulty, scheduler! If it does, please file a bug report.

Abort

The scheduler chose to abort execution. This will be produced if, for example, all possible decisions exceed the specified bounds (there have been too many pre-emptions, the computation has executed for too long, or there have been too many yields).

Deadlock

Every thread is blocked, and the main thread is not blocked in an STM transaction.

STMDeadlock

Every thread is blocked, and the main thread is blocked in an STM transaction.

UncaughtException SomeException

An uncaught exception bubbled to the top of the computation.

IllegalSubconcurrency

Calls to subconcurrency were nested, or attempted when multiple threads existed.

IllegalDontCheck

A call to dontCheck was attempted after the first action of the initial thread.

isInternalError :: Failure -> Bool Source #

Check if a failure is an InternalError.

Since: 0.9.0.0

isAbort :: Failure -> Bool Source #

Check if a failure is an Abort.

Since: 0.9.0.0

isDeadlock :: Failure -> Bool Source #

Check if a failure is a Deadlock or an STMDeadlock.

Since: 0.9.0.0

isUncaughtException :: Failure -> Bool Source #

Check if a failure is an UncaughtException

Since: 0.9.0.0

isIllegalSubconcurrency :: Failure -> Bool Source #

Check if a failure is an IllegalSubconcurrency

Since: 0.9.0.0

isIllegalDontCheck :: Failure -> Bool Source #

Check if a failure is an IllegalDontCheck

Since: 1.1.0.0

Schedule bounding

newtype PreemptionBound Source #

Restrict the number of pre-emptive context switches allowed in an execution.

A pre-emption bound of zero disables pre-emptions entirely.

Since: 0.2.0.0

Constructors

PreemptionBound Int 

Instances

Enum PreemptionBound Source # 
Eq PreemptionBound Source # 
Integral PreemptionBound Source # 
Num PreemptionBound Source # 
Ord PreemptionBound Source # 
Read PreemptionBound Source # 
Real PreemptionBound Source # 
Show PreemptionBound Source # 
NFData PreemptionBound Source #

Since: 0.5.1.0

Methods

rnf :: PreemptionBound -> () #

newtype FairBound Source #

Restrict the maximum difference between the number of yield or delay operations different threads have performed.

A fair bound of zero disables yields and delays entirely.

Since: 0.2.0.0

Constructors

FairBound Int 

Instances

Enum FairBound Source # 
Eq FairBound Source # 
Integral FairBound Source # 
Num FairBound Source # 
Ord FairBound Source # 
Read FairBound Source # 
Real FairBound Source # 
Show FairBound Source # 
NFData FairBound Source #

Since: 0.5.1.0

Methods

rnf :: FairBound -> () #

newtype LengthBound Source #

Restrict the maximum length (in terms of primitive actions) of an execution.

A length bound of zero immediately aborts the execution.

Since: 0.2.0.0

Constructors

LengthBound Int 

Instances

Enum LengthBound Source # 
Eq LengthBound Source # 
Integral LengthBound Source # 
Num LengthBound Source # 
Ord LengthBound Source # 
Read LengthBound Source # 
Real LengthBound Source # 
Show LengthBound Source # 
NFData LengthBound Source #

Since: 0.5.1.0

Methods

rnf :: LengthBound -> () #

Discarding results and traces

data Discard Source #

An Either Failure a -> Maybe Discard value can be used to selectively discard results.

Since: 0.7.1.0

Constructors

DiscardTrace

Discard the trace but keep the result. The result will appear to have an empty trace.

DiscardResultAndTrace

Discard the result and the trace. It will simply not be reported as a possible behaviour of the program.

weakenDiscard :: (Either Failure a -> Maybe Discard) -> (Either Failure a -> Maybe Discard) -> Either Failure a -> Maybe Discard Source #

Combine two discard values, keeping the weaker.

Nothing is weaker than Just DiscardTrace, which is weaker than Just DiscardResultAndTrace. This forms a commutative monoid where the unit is const (Just DiscardResultAndTrace).

Since: 1.0.0.0

strengthenDiscard :: (Either Failure a -> Maybe Discard) -> (Either Failure a -> Maybe Discard) -> Either Failure a -> Maybe Discard Source #

Combine two discard functions, keeping the stronger.

Just DiscardResultAndTrace is stronger than Just DiscardTrace, which is stronger than Nothing. This forms a commutative monoid where the unit is const Nothing.

Since: 1.0.0.0

Memory Models

data MemType Source #

The memory model to use for non-synchronised CRef operations.

Since: 0.4.0.0

Constructors

SequentialConsistency

The most intuitive model: a program behaves as a simple interleaving of the actions in different threads. When a CRef is written to, that write is immediately visible to all threads.

TotalStoreOrder

Each thread has a write buffer. A thread sees its writes immediately, but other threads will only see writes when they are committed, which may happen later. Writes are committed in the same order that they are created.

PartialStoreOrder

Each CRef has a write buffer. A thread sees its writes immediately, but other threads will only see writes when they are committed, which may happen later. Writes to different CRefs are not necessarily committed in the same order that they are created.

MonadFail