dejafu-0.9.0.2: Systematic testing for Haskell concurrency.

Copyright (c) 2016 Michael Walker MIT Michael Walker experimental TupleSections Safe Haskell2010

Test.DejaFu.SCT.Internal

Description

Internal types and functions for dynamic partial-order reduction. This module is NOT considered to form part of the public interface of this library.

Synopsis

# Dynamic partial-order reduction

data DPOR Source #

DPOR execution is represented as a tree of states, characterised by the decisions that lead to that state.

Constructors

Instances

 Source # Methods(==) :: DPOR -> DPOR -> Bool #(/=) :: DPOR -> DPOR -> Bool # Source # MethodsshowsPrec :: Int -> DPOR -> ShowS #show :: DPOR -> String #showList :: [DPOR] -> ShowS # Source # Methodsrnf :: DPOR -> () #

One step of the execution, including information for backtracking purposes. This backtracking information is used to generate new schedules.

Constructors

 BacktrackStep FieldsbcktThreadid :: ThreadIdThe thread running at this stepbcktDecision :: DecisionWhat was decided at this step.bcktAction :: ThreadActionWhat happened at this step.bcktRunnable :: Map ThreadId LookaheadThe threads runnable at this stepbcktBacktracks :: Map ThreadId BoolThe list of alternative threads to run, and whether those alternatives were added conservatively due to the bound.bcktState :: DepStateSome domain-specific state at this point.

Instances

 Source # Methods Source # MethodsshowList :: [BacktrackStep] -> ShowS # Source # Methodsrnf :: BacktrackStep -> () #

Initial DPOR state, given an initial thread ID. This initial thread should exist and be runnable at the start of execution.

Produce a new schedule prefix from a DPOR tree. If there are no new prefixes remaining, return Nothing. Also returns whether the decision was added conservatively, and the sleep set at the point where divergence happens.

A schedule prefix is a possibly empty sequence of decisions that have already been made, terminated by a single decision from the to-do set. The intent is to put the system into a new state when executed with this initial sequence of scheduling decisions.

Arguments

 :: MemType Memory model -> Bool Whether the "to-do" point which was used to create this new execution was conservative or not. -> Trace The execution trace: the decision made, the runnable threads, and the action performed. -> DPOR -> DPOR

Add a new trace to the stack. This won't work if to-dos aren't explored depth-first.

Arguments

Produce a list of new backtracking points from an execution trace. These are then used to inform new "to-do" points in the DPOR tree.

Two traces are passed in to this function: the first is generated from the special DPOR scheduler, the other from the execution of the concurrent program.

If the trace ends with any threads other than the initial one still runnable, a dependency is imposed between this final action and everything else.

Add new backtracking points, if they have not already been visited and aren't in the sleep set.

# DPOR scheduler

The scheduler state

Constructors

 DPORSchedState FieldsschedSleep :: Map ThreadId ThreadActionThe sleep set: decisions not to make until something dependent with them happens.schedPrefix :: [ThreadId]Decisions still to makeschedBPoints :: Seq ([(ThreadId, Lookahead)], [ThreadId])Which threads are runnable and in-bound at each step, and the alternative decisions still to make.schedIgnore :: BoolWhether to ignore this execution or not: True if the execution is aborted due to all possible decisions being in the sleep set, as then everything in this execution is covered by another.schedBoundKill :: BoolWhether the execution was terminated due to all decisions being out of bounds.schedDepState :: DepStateState used by the dependency function to determine when to remove decisions from the sleep set.schedBState :: Maybe kState used by the incremental bounding function.

Instances

 Eq k => Eq (DPORSchedState k) Source # Methods(==) :: DPORSchedState k -> DPORSchedState k -> Bool #(/=) :: DPORSchedState k -> DPORSchedState k -> Bool # Show k => Show (DPORSchedState k) Source # MethodsshowsPrec :: Int -> DPORSchedState k -> ShowS #showList :: [DPORSchedState k] -> ShowS # NFData k => NFData (DPORSchedState k) Source # Methodsrnf :: DPORSchedState k -> () #

Arguments

Initial DPOR scheduler state for a given prefix

type IncrementalBoundFunc k = Maybe k -> Maybe (ThreadId, ThreadAction) -> (Decision, Lookahead) -> Maybe k Source #

An incremental bounding function is a stateful function that takes the last and next decisions, and returns a new state only if the next decision is within the bound.

type BacktrackFunc = [BacktrackStep] -> [(Int, Bool, ThreadId)] -> [BacktrackStep] Source #

A backtracking step is a point in the execution where another decision needs to be made, in order to explore interesting new schedules. A backtracking function takes the steps identified so far and a list of points and thread at that point to backtrack to. More points be added to compensate for the effects of the bounding function. For example, under pre-emption bounding a conservative backtracking point is added at the prior context switch. The bool is whether the point is conservative. Conservative points are always explored, whereas non-conservative ones might be skipped based on future information.

In general, a backtracking function should identify one or more backtracking points, and then use backtrackAt to do the actual work.

Arguments

 :: (ThreadId -> BacktrackStep -> Bool) If this returns True, backtrack to all runnable threads, rather than just the given thread. -> BacktrackFunc

Arguments

 :: MemType Memory model. -> IncrementalBoundFunc k Bound function: returns true if that schedule prefix terminated with the lookahead decision fits within the bound. -> Scheduler (DPORSchedState k)

DPOR scheduler: takes a list of decisions, and maintains a trace including the runnable threads, and the alternative choices allowed by the bound-specific initialise function.

After the initial decisions are exhausted, this prefers choosing the prior thread if it's (1) still runnable and (2) hasn't just yielded. Furthermore, threads which will yield are ignored in preference of those which will not.

The scheduler state

Constructors

 RandSchedState FieldsschedWeights :: Map ThreadId IntThe thread weights: used in determining which to run.schedGen :: gThe random number generator.

Instances

 Eq g => Eq (RandSchedState g) Source # Methods(==) :: RandSchedState g -> RandSchedState g -> Bool #(/=) :: RandSchedState g -> RandSchedState g -> Bool # Show g => Show (RandSchedState g) Source # MethodsshowsPrec :: Int -> RandSchedState g -> ShowS #showList :: [RandSchedState g] -> ShowS # NFData g => NFData (RandSchedState g) Source # Methodsrnf :: RandSchedState g -> () #

Initial weighted random scheduler state.

randSched :: RandomGen g => (g -> (Int, g)) -> Scheduler (RandSchedState g) Source #

Weighted random scheduler: assigns to each new thread a weight, and makes a weighted random choice out of the runnable threads at every step.

Check if an action is dependent on another.

This is basically the same as dependent', but can make use of the additional information in a ThreadAction to make better decisions in a few cases.

Variant of dependent to handle Lookahead.

Termination of the initial thread is handled specially in the DPOR implementation.

Check if two ActionTypes are dependent. Note that this is not sufficient to know if two ThreadActions are dependent, without being so great an over-approximation as to be useless!

data DepState Source #

Constructors

 DepState FieldsdepCRState :: Map CRefId BoolKeep track of which CRefs have buffered writes.depMaskState :: Map ThreadId MaskingStateKeep track of thread masking states. If a thread isn't present, the masking state is assumed to be Unmasked. This nicely provides compatibility with dpor-0.1, where the thread IDs are not available.

Instances

 Source # Methods Source # MethodsshowList :: [DepState] -> ShowS # Source # Methodsrnf :: DepState -> () #

Initial dependency state.

Update the CRef buffer state with the action that has just happened.

Update the CRef buffer state with the action that has just happened.

Update the thread masking state with the action that has just happened.

Check if a CRef has a buffered write pending.

Check if an exception can interrupt a thread (action).