| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Protocols.Experimental.Hedgehog
Description
A collection of Hedgehog helpers to test Circuit components. To test a
protocol component against a combinatorial model, see idWithModel. To write
your own tester, see Test.
Synopsis
- data ExpectOptions = ExpectOptions {
- eoStopAfterEmpty :: Maybe Int
- eoSampleMax :: Int
- eoStallsMax :: Int
- eoConsecutiveStalls :: Int
- eoResetCycles :: Int
- eoDriveEarly :: Bool
- eoTimeoutMs :: Maybe Int
- eoTrace :: Bool
- defExpectOptions :: ExpectOptions
- data StallMode
- class (Drivable a, TestType (SimulateFwdType a), TestType (ExpectType a)) => Test a where
- expectN :: (HasCallStack, MonadTest m) => Proxy a -> ExpectOptions -> SimulateFwdType a -> m (ExpectType a)
- class (NFData a, NFDataX a, ShowX a, Show a, Eq a) => TestType a
- idWithModel :: (Test a, Test b, HasCallStack) => ExpectOptions -> Gen (ExpectType a) -> (ExpectType a -> ExpectType b) -> Circuit a b -> Property
- idWithModelSingleDomain :: forall (dom :: Domain) a b. (Test a, Test b, KnownDomain dom, HasCallStack) => ExpectOptions -> Gen (ExpectType a) -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) -> Property
- propWithModel :: (Test a, Test b, HasCallStack) => ExpectOptions -> Gen (ExpectType a) -> (ExpectType a -> ExpectType b) -> Circuit a b -> (ExpectType b -> ExpectType b -> PropertyT IO ()) -> Property
- propWithModelSingleDomain :: forall (dom :: Domain) a b. (Test a, Test b, KnownDomain dom, HasCallStack) => ExpectOptions -> Gen (ExpectType a) -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) -> (ExpectType b -> ExpectType b -> PropertyT IO ()) -> Property
- idWithModelT :: forall a b (m :: Type -> Type). (Test a, Test b, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) => ExpectOptions -> Gen (ExpectType a) -> (ExpectType a -> ExpectType b) -> Circuit a b -> PropertyT m ()
- idWithModelSingleDomainT :: forall (dom :: Domain) a b (m :: Type -> Type). (Test a, Test b, KnownDomain dom, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) => ExpectOptions -> Gen (ExpectType a) -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) -> PropertyT m ()
- propWithModelT :: forall a b (m :: Type -> Type). (Test a, Test b, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) => ExpectOptions -> Gen (ExpectType a) -> (ExpectType a -> ExpectType b) -> Circuit a b -> (ExpectType b -> ExpectType b -> PropertyT m ()) -> PropertyT m ()
- propWithModelSingleDomainT :: forall (dom :: Domain) a b (m :: Type -> Type). (Test a, Test b, KnownDomain dom, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) => ExpectOptions -> Gen (ExpectType a) -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) -> (ExpectType b -> ExpectType b -> PropertyT m ()) -> PropertyT m ()
- genStallAck :: Gen StallAck
- genStallMode :: Gen StallMode
- genStalls :: Gen Int -> Int -> StallMode -> Gen (StallAck, [Int])
- expectedEmptyCycles :: ExpectOptions -> Int
Types
data ExpectOptions Source #
Options for expectN function. See individual fields for more information.
Constructors
| ExpectOptions | |
Fields
| |
defExpectOptions :: ExpectOptions Source #
Conservative settings for ExpectOptions:
- Reset for 30 cycles
- Insert at most 10 stall moments
- Every stall moment is at most 10 cycles long
- Sample at most 1000 cycles
- Automatically derive when to stop sampling empty samples using expectedEmptyCycles.
Whether to stall or not. Used in idWithModel.
Instances
| Bounded StallMode Source # | |
| Enum StallMode Source # | |
Defined in Protocols.Experimental.Hedgehog Methods succ :: StallMode -> StallMode # pred :: StallMode -> StallMode # fromEnum :: StallMode -> Int # enumFrom :: StallMode -> [StallMode] # enumFromThen :: StallMode -> StallMode -> [StallMode] # enumFromTo :: StallMode -> StallMode -> [StallMode] # enumFromThenTo :: StallMode -> StallMode -> StallMode -> [StallMode] # | |
| Show StallMode Source # | |
class (Drivable a, TestType (SimulateFwdType a), TestType (ExpectType a)) => Test a where Source #
Provides a way of comparing expected data with data produced by a protocol component.
Methods
Arguments
| :: (HasCallStack, MonadTest m) | |
| => Proxy a | |
| -> ExpectOptions | Options, see |
| -> SimulateFwdType a | Raw sampled data |
| -> m (ExpectType a) | Depending on ExpectOptions, fails the test if:
If it does not fail, SimulateFwdType a will contain exactly the number of expected data packets. TODO: Should probably return a 'Vec (SimulateChannels) Failures' in order to produce pretty reports. |
Trim each channel to the lengths given as the third argument. See result documentation for failure modes.
Instances
class (NFData a, NFDataX a, ShowX a, Show a, Eq a) => TestType a Source #
Superclass class to reduce syntactical noise.
Test functions
Arguments
| :: (Test a, Test b, HasCallStack) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (ExpectType a -> ExpectType b) | Model |
| -> Circuit a b | Implementation |
| -> Property |
Test a protocol against a pure model implementation. Circuit under test will be arbitrarily stalled on the left hand and right hand side and tested for a number of properties:
- Whether it does not produce too little data
- Whether it does not produce more data than expected
- Whether the expected data corresponds to the sampled data
- Whether it responds to backpressure correctly
- Whether it (eventually) drives a nack while in reset
For testing custom properties, see propWithModel.
idWithModelSingleDomain Source #
Arguments
| :: forall (dom :: Domain) a b. (Test a, Test b, KnownDomain dom, HasCallStack) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) | Model |
| -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) | Implementation |
| -> Property |
Same as propWithModel, but with single clock, reset, and enable.
Arguments
| :: (Test a, Test b, HasCallStack) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (ExpectType a -> ExpectType b) | Model |
| -> Circuit a b | Implementation |
| -> (ExpectType b -> ExpectType b -> PropertyT IO ()) | Property to test for. Function is given the data produced by the model as a first argument, and the sampled data as a second argument. |
| -> Property |
Test a protocol against a pure model implementation. Circuit under test will be arbitrarily stalled on the left hand and right hand side and tested for a number of properties:
- Whether it does not produce too little data.
- Whether it does not produce more data than expected.
- Whether it responds to backpressure correctly
- Whether it (eventually) drives a nack while in reset.
Finally, the data will be tested against the property supplied in the last argument.
propWithModelSingleDomain Source #
Arguments
| :: forall (dom :: Domain) a b. (Test a, Test b, KnownDomain dom, HasCallStack) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) | Model |
| -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) | Implementation |
| -> (ExpectType b -> ExpectType b -> PropertyT IO ()) | Property to test for. Function is given the data produced by the model as a first argument, and the sampled data as a second argument. |
| -> Property |
Same as propWithModel, but with single clock, reset, and enable.
Monadic test functions
Arguments
| :: forall a b (m :: Type -> Type). (Test a, Test b, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (ExpectType a -> ExpectType b) | Model |
| -> Circuit a b | Implementation |
| -> PropertyT m () |
Monadic version of idWithModel.
Runs the protocol-vs-model test using the default equality property (===) in any monad supporting MonadIO and 'MonadBaseControl IO'.
Use this when you want to run the test in a monadic context or need additional effects.
idWithModelSingleDomainT Source #
Arguments
| :: forall (dom :: Domain) a b (m :: Type -> Type). (Test a, Test b, KnownDomain dom, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) | Model |
| -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) | Implementation |
| -> PropertyT m () |
Monadic version of idWithModelSingleDomain.
Runs the single-domain protocol-vs-model test using the default equality property (===) in any monad supporting MonadIO and 'MonadBaseControl IO'.
Use this for monadic test frameworks or when additional effects are needed.
Arguments
| :: forall a b (m :: Type -> Type). (Test a, Test b, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (ExpectType a -> ExpectType b) | Model |
| -> Circuit a b | Implementation |
| -> (ExpectType b -> ExpectType b -> PropertyT m ()) | Property to test for. Function is given the data produced by the model as a first argument, and the sampled data as a second argument. |
| -> PropertyT m () |
Monadic version of propWithModel.
Allows property-based protocol testing in any monad supporting MonadIO and 'MonadBaseControl IO'.
This is useful for integrating with monadic test frameworks or when additional effects are needed during testing.
propWithModelSingleDomainT Source #
Arguments
| :: forall (dom :: Domain) a b (m :: Type -> Type). (Test a, Test b, KnownDomain dom, HasCallStack, Monad m, MonadIO m, MonadBaseControl IO m) | |
| => ExpectOptions | Options, see |
| -> Gen (ExpectType a) | Test data generator |
| -> (Clock dom -> Reset dom -> Enable dom -> ExpectType a -> ExpectType b) | Model |
| -> (Clock dom -> Reset dom -> Enable dom -> Circuit a b) | Implementation |
| -> (ExpectType b -> ExpectType b -> PropertyT m ()) | Property to test for. Function is given the data produced by the model as a first argument, and the sampled data as a second argument. |
| -> PropertyT m () |
Monadic version of propWithModelSingleDomain.
Allows property-based protocol testing for single-domain circuits in any monad supporting MonadIO and 'MonadBaseControl IO'.
This is useful for monadic test integration or when effects are required during testing.
Internals
genStallAck :: Gen StallAck Source #
Generator for StallMode. Shrinks towards StallWithNack.
expectedEmptyCycles :: ExpectOptions -> Int Source #
Default derivation of eoStopAfterEmpty when it is set to Nothing.