Skip to content

Commit ec98c93

Browse files
committed
Add prop_fanin
1 parent a5b4af8 commit ec98c93

File tree

2 files changed

+33
-1
lines changed
  • bittide-extra

2 files changed

+33
-1
lines changed

bittide-extra/src/Protocols/BiDf.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ dimap ::
130130
Circuit (BiDf dom req resp') (BiDf dom req' resp)
131131
dimap f g = mapC (Df.map f) (Df.map g)
132132

133-
-- | Merge a number of 'BiDf's, preferring requests from the last channel.
133+
{- | Merge a number of 'BiDf's, preferring requests from the last channel.
134+
TODO: Check why this does not work if we insert delays on the individual `Df` channels of the
135+
right hand side `BiDf`s. See `Tests.Protocols.BiDf.prop_fanin`.
136+
-}
134137
fanin ::
135138
forall n dom req resp.
136139
( KnownNat n

bittide-extra/tests/unittests/Tests/Protocols/BiDf.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ import Clash.Hedgehog.Sized.Vector (genVec)
1010
import Hedgehog (Gen, Property)
1111
import Protocols
1212
import Protocols.BiDf as BiDf
13+
import Protocols.Extra (fmapC)
1314
import Protocols.Hedgehog (ExpectOptions (eoResetCycles), defExpectOptions)
1415
import Test.Tasty (TestTree)
1516
import Test.Tasty.Hedgehog.Extra (testProperty)
1617
import Test.Tasty.TH (testGroupGenerator)
1718

19+
import qualified Data.List as L
1820
import qualified Hedgehog as H
1921
import qualified Hedgehog.Gen as Gen
2022
import qualified Hedgehog.Range as Range
2123
import qualified Protocols.Df as Df
2224
import qualified Protocols.Df.Extra as Df
2325
import qualified Protocols.Hedgehog as PH
26+
import qualified Protocols.Vec as Vec
2427

2528
smallInt :: Gen Int
2629
smallInt = 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+
78107
tests :: TestTree
79108
tests = $(testGroupGenerator)

0 commit comments

Comments
 (0)