quickcheck-state-machine-0.6.0: Test monadic programs using state machine based models

Copyright(C) 2017 ATS Advanced Telematic Systems GmbH
LicenseBSD-style (see the file LICENSE)
MaintainerStevan Andjelkovic <stevan.andjelkovic@here.com>
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Test.StateMachine.Parallel

Description

This module contains helpers for generating, shrinking, and checking parallel programs.

Synopsis

Documentation

forAllParallelCommands Source #

Arguments

:: Testable prop 
=> (Show (cmd Symbolic), Show (resp Symbolic), Show (model Symbolic)) 
=> CommandNames cmd 
=> (Traversable cmd, Foldable resp) 
=> StateMachine model cmd m resp 
-> (ParallelCommands cmd resp -> prop)

Predicate.

-> Property 

generateParallelCommands :: forall model cmd m resp. (Foldable resp, Show (model Symbolic)) => CommandNames cmd => StateMachine model cmd m resp -> Gen (ParallelCommands cmd resp) Source #

Generate parallel commands.

Parallel commands are generated as follows. We begin by generating sequential commands and then splitting this list in two at some index. The first half will be used as the prefix.

The second half will be used to build suffixes. For example, starting from the following sequential commands:

[A, B, C, D, E, F, G, H, I]

We split it in two, giving us the prefix and the rest:

prefix: [A, B]
rest:   [C, D, E, F, G, H, I]

We advance the model with the prefix.

Make a suffix: we take commands from rest as long as these are parallel safe (see parallelSafe). This means that the pre-conditions (using the 'advanced' model) of each of those commands will hold no matter in which order they are executed.

Say this is true for [C, D, E], but not anymore for F, maybe because F depends on one of [C, D, E]. Then we divide this 'chunk' in two by splitting it in the middle, obtaining [C] and [D, E]. These two halves of the chunk (stored as a Pair) will later be executed in parallel. Together they form one suffix.

Then the model is advanced using the whole chunk [C, D, E]. Think of it as a barrier after executing the two halves of the chunk in parallel. Then this process of building a chunk/suffix repeats itself, starting from Make a suffix using the 'advanced' model.

In the end we might end up with something like this:

        ┌─ [C] ──┐  ┌ [F, G] ┐
[A, B] ─┤        ├──┤        │
        └ [D, E] ┘  └ [H, I] ┘

shrinkParallelCommands :: forall cmd model m resp. Traversable cmd => Foldable resp => StateMachine model cmd m resp -> ParallelCommands cmd resp -> [ParallelCommands cmd resp] Source #

Shrink a parallel program in a pre-condition and scope respecting way.

shrinkAndValidateParallel :: forall model cmd m resp. (Traversable cmd, Foldable resp) => StateMachine model cmd m resp -> ShouldShrink -> ValidateEnv model -> ParallelCommands cmd resp -> [ParallelCommands cmd resp] Source #

runParallelCommands :: (Show (cmd Concrete), Show (resp Concrete)) => (Traversable cmd, Foldable resp) => (MonadCatch m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> PropertyM m [(History cmd resp, Logic)] Source #

runParallelCommandsNTimes Source #

Arguments

:: (Show (cmd Concrete), Show (resp Concrete)) 
=> (Traversable cmd, Foldable resp) 
=> (MonadCatch m, MonadUnliftIO m) 
=> Int

How many times to execute the parallel program.

-> StateMachine model cmd m resp 
-> ParallelCommands cmd resp 
-> PropertyM m [(History cmd resp, Logic)] 

executeParallelCommands :: (Traversable cmd, Foldable resp) => (MonadCatch m, MonadUnliftIO m) => StateMachine model cmd m resp -> ParallelCommands cmd resp -> m (History cmd resp, Reason) Source #

linearise :: forall model cmd m resp. (Show (cmd Concrete), Show (resp Concrete)) => StateMachine model cmd m resp -> History cmd resp -> Logic Source #

Try to linearise a history of a parallel program execution using a sequential model. See the *Linearizability: a correctness condition for concurrent objects* paper linked to from the README for more info.

toBoxDrawings :: forall cmd resp. Foldable cmd => (Show (cmd Concrete), Show (resp Concrete)) => ParallelCommands cmd resp -> History cmd resp -> Doc Source #

Draw an ASCII diagram of the history of a parallel program. Useful for seeing how a race condition might have occured.

prettyParallelCommands Source #

Arguments

:: (MonadIO m, Foldable cmd) 
=> (Show (cmd Concrete), Show (resp Concrete)) 
=> ParallelCommands cmd resp 
-> [(History cmd resp, Logic)]

Output of runParallelCommands.

-> PropertyM m () 

Takes the output of parallel program runs and pretty prints a counterexample if any of the runs fail.

advanceModel Source #

Arguments

:: StateMachine model cmd m resp 
-> model Symbolic

The model.

-> Commands cmd resp

The commands.

-> model Symbolic 

Apply the transition of some commands to a model.