@@ -10,17 +10,20 @@ import Clash.Hedgehog.Sized.Vector (genVec)
1010import Hedgehog (Gen , Property )
1111import Protocols
1212import Protocols.BiDf as BiDf
13+ import Protocols.Extra (fmapC )
1314import Protocols.Hedgehog (ExpectOptions (eoResetCycles ), defExpectOptions )
1415import Test.Tasty (TestTree )
1516import Test.Tasty.Hedgehog.Extra (testProperty )
1617import Test.Tasty.TH (testGroupGenerator )
1718
19+ import qualified Data.List as L
1820import qualified Hedgehog as H
1921import qualified Hedgehog.Gen as Gen
2022import qualified Hedgehog.Range as Range
2123import qualified Protocols.Df as Df
2224import qualified Protocols.Df.Extra as Df
2325import qualified Protocols.Hedgehog as PH
26+ import qualified Protocols.Vec as Vec
2427
2528smallInt :: Gen Int
2629smallInt = Gen. integral (Range. linear 0 10 )
@@ -75,5 +78,31 @@ prop_fromDfs_toDfs_id = H.property $ do
7578 gen :: Gen [Int ]
7679 gen = Gen. list (Range. linear 0 10 ) smallInt
7780
81+ prop_fanin :: Property
82+ prop_fanin = H. property $ do
83+ -- stalls <- H.forAll genStalls
84+ let
85+ impl ::
86+ forall dom .
87+ (HiddenClockResetEnable dom ) =>
88+ Circuit (Vec 3 (Df dom Int )) (Vec 3 (Df dom Int ))
89+ impl = circuit $ \ reqs -> do
90+ (biDfs, resps) <- Vec. unzip <| fmapC (BiDf. fromDfs) -< reqs
91+ respBiDf <- BiDf. fanin -< biDfs
92+ resp0 <- BiDf. toDfs -< (respBiDf, resp0)
93+ -- resp1 <- Df.bypassFifo d2 (Df.fifo d8) -< resp0
94+ idC -< resps
95+ PH. propWithModelSingleDomainT @ System
96+ defExpectOptions
97+ gen
98+ (\ _ _ _ -> id )
99+ (exposeClockResetEnable impl)
100+ prop
101+ where
102+ gen :: Gen (Vec 3 [Int ])
103+ gen = genVec (Gen. list (Range. linear 0 10 ) smallInt)
104+ -- Since stalling can change the order of the samples, we only check if they are all present
105+ prop expected sampled = L. sort (L. concat (toList sampled)) H. === L. sort (L. concat (toList expected))
106+
78107tests :: TestTree
79108tests = $ (testGroupGenerator)
0 commit comments