Skip to content

Commit 623ecd9

Browse files
Add eoTrace (#95)
Can be useful to find out what Hedgehog is doing
1 parent 688dae3 commit 623ecd9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Protocols/Hedgehog.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Protocols.Hedgehog (
3030

3131
-- base
3232
import Control.Concurrent (threadDelay)
33+
import Control.Monad (when)
3334
import Control.Monad.IO.Class (liftIO)
3435
import Data.Proxy (Proxy (Proxy))
3536
import GHC.Stack (HasCallStack)
@@ -119,9 +120,11 @@ propWithModel ::
119120
propWithModel eOpts genData model prot prop =
120121
H.property $ maybe id withTimeoutMs (eoTimeoutMs eOpts) $ do
121122
dat <- H.forAll genData
123+
when (eoTrace eOpts) $ liftIO $ putStr "propWithModel: dat: " >> print dat
122124

123125
-- TODO: Different 'n's for each output
124126
n <- H.forAll (Gen.integral (Range.linear 0 (eoSampleMax eOpts)))
127+
when (eoTrace eOpts) $ liftIO $ putStr "propWithModel: n: " >> print n
125128

126129
-- TODO: Different distributions?
127130
let genStall = genSmallInt
@@ -130,13 +133,21 @@ propWithModel eOpts genData model prot prop =
130133
-- whether to stall or not. The second determines how many cycles to stall
131134
-- on each _valid_ cycle.
132135
lhsStallModes <- H.forAll (genVec genStallMode)
136+
when (eoTrace eOpts) $
137+
liftIO $
138+
putStr "propWithModel: lhsStallModes: " >> print lhsStallModes
133139
lhsStalls <- H.forAll (traverse (genStalls genStall n) lhsStallModes)
140+
when (eoTrace eOpts) $ liftIO $ putStr "propWithModel: lhsStalls: " >> print lhsStalls
134141

135142
-- Generate stalls for RHS part of the protocol. The first line determines
136143
-- whether to stall or not. The second determines how many cycles to stall
137144
-- on each _valid_ cycle.
138145
rhsStallModes <- H.forAll (genVec genStallMode)
146+
when (eoTrace eOpts) $
147+
liftIO $
148+
putStr "propWithModel: rhsStallModes: " >> print rhsStallModes
139149
rhsStalls <- H.forAll (traverse (genStalls genStall n) rhsStallModes)
150+
when (eoTrace eOpts) $ liftIO $ putStr "propWithModel: rhsStalls: " >> print rhsStalls
140151

141152
let
142153
simConfig = def{resetCycles = eoResetCycles eOpts}
@@ -157,9 +168,14 @@ propWithModel eOpts genData model prot prop =
157168
-- expectN errors if circuit does not produce enough data
158169
trimmed <- expectN (Proxy @b) eOpts sampled
159170

171+
when (eoTrace eOpts) $ liftIO $ putStrLn "propWithModel: before forcing trimmed.."
160172
_ <- H.evalNF trimmed
173+
when (eoTrace eOpts) $ liftIO $ putStrLn "propWithModel: before forcing expected.."
161174
_ <- H.evalNF expected
162175

176+
when (eoTrace eOpts) $
177+
liftIO $
178+
putStrLn "propWithModel: executing property.."
163179
prop expected trimmed
164180

165181
{- | Test a protocol against a pure model implementation. Circuit under test will

src/Protocols/Hedgehog/Internal.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ data ExpectOptions = ExpectOptions
4848
-- never acknowledge data while this is happening.
4949
, eoTimeoutMs :: Maybe Int
5050
-- ^ Terminate the test after /n/ milliseconds.
51+
, eoTrace :: Bool
52+
-- ^ Trace data generation for debugging purposes
5153
}
5254

5355
{- | Resets for 30 cycles, checks for superfluous data for 50 cycles after
@@ -67,6 +69,7 @@ defExpectOptions =
6769
, eoResetCycles = 30
6870
, eoDriveEarly = True
6971
, eoTimeoutMs = Nothing
72+
, eoTrace = False
7073
}
7174

7275
-- | Superclass class to reduce syntactical noise.

0 commit comments

Comments
 (0)