From 67c16fdfe8f2ef61c34ae06d16e2d61bce6ea946 Mon Sep 17 00:00:00 2001 From: Jasper Vinkenvleugel Date: Fri, 21 Jun 2024 10:22:45 +0200 Subject: [PATCH] Move Sgmii dependency out of EbTb tests --- clash-cores/clash-cores.cabal | 1 - clash-cores/test/Test/Cores/EbTb.hs | 18 ++++++++++++++-- clash-cores/test/Test/Cores/Sgmii/BitSlip.hs | 2 +- clash-cores/test/Test/Cores/Sgmii/Common.hs | 22 -------------------- clash-cores/test/Test/Cores/Sgmii/Sync.hs | 2 +- 5 files changed, 18 insertions(+), 27 deletions(-) delete mode 100644 clash-cores/test/Test/Cores/Sgmii/Common.hs diff --git a/clash-cores/clash-cores.cabal b/clash-cores/clash-cores.cabal index 13645433df..d3f8cf9bd6 100644 --- a/clash-cores/clash-cores.cabal +++ b/clash-cores/clash-cores.cabal @@ -212,7 +212,6 @@ test-suite unittests Test.Cores.Internal.Signals Test.Cores.Sgmii.AutoNeg Test.Cores.Sgmii.BitSlip - Test.Cores.Sgmii.Common Test.Cores.Sgmii.Gearbox Test.Cores.Sgmii.PcsReceive Test.Cores.Sgmii.PcsTransmit diff --git a/clash-cores/test/Test/Cores/EbTb.hs b/clash-cores/test/Test/Cores/EbTb.hs index b709b7bf7f..7d332fb1a1 100644 --- a/clash-cores/test/Test/Cores/EbTb.hs +++ b/clash-cores/test/Test/Cores/EbTb.hs @@ -1,16 +1,30 @@ module Test.Cores.EbTb where import Clash.Cores.EbTb -import Clash.Cores.Sgmii.Common import Clash.Hedgehog.Sized.BitVector +import qualified Clash.Prelude as C import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen -import Test.Cores.Sgmii.Common import Test.Tasty import Test.Tasty.Hedgehog import Test.Tasty.TH import Prelude +-- | Check if a 'BitVector' does not contain a sequence of bits with the same +-- value for 5 or more bits consequetively. +checkBitSequence :: (C.KnownNat n) => C.BitVector n -> Bool +checkBitSequence cg = + fst (fst (C.mapAccumL (f 0) (0, 0) (C.bv2v cg))) + < 5 + && fst (fst (C.mapAccumL (f 1) (0, 0) (C.bv2v cg))) + < 5 + where + f :: C.Bit -> (Int, Int) -> C.Bit -> ((Int, Int), C.Bit) + f c (accMax, acc) i = + if i == c + then ((if accMax < (acc + 1) then acc + 1 else accMax, acc + 1), i) + else ((accMax, 0), i) + -- Check if the output of 'ebTbDecode' is a valid value for a given value from -- 'ebTbEncode'. prop_ebTbDecodeCheckNothing :: H.Property diff --git a/clash-cores/test/Test/Cores/Sgmii/BitSlip.hs b/clash-cores/test/Test/Cores/Sgmii/BitSlip.hs index 58df4a6b5f..1880b74316 100644 --- a/clash-cores/test/Test/Cores/Sgmii/BitSlip.hs +++ b/clash-cores/test/Test/Cores/Sgmii/BitSlip.hs @@ -8,7 +8,7 @@ import Data.Maybe (isNothing) import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range -import Test.Cores.Sgmii.Common +import Test.Cores.EbTb import Test.Tasty import Test.Tasty.Hedgehog import Test.Tasty.TH diff --git a/clash-cores/test/Test/Cores/Sgmii/Common.hs b/clash-cores/test/Test/Cores/Sgmii/Common.hs deleted file mode 100644 index 94a2600b51..0000000000 --- a/clash-cores/test/Test/Cores/Sgmii/Common.hs +++ /dev/null @@ -1,22 +0,0 @@ -module Test.Cores.Sgmii.Common where - -import Clash.Prelude - --- | Example DataWord that doesn't invert the running disparity -dwD09_1 :: BitVector 8 -dwD09_1 = 0b00101001 - --- | Check if a 'BitVector' does not contain a sequence of bits with the same --- value for 5 or more bits consequetively. -checkBitSequence :: (KnownNat n) => BitVector n -> Bool -checkBitSequence cg = - fst (fst (mapAccumL (f 0) (0, 0) (bv2v cg))) - < 5 - && fst (fst (mapAccumL (f 1) (0, 0) (bv2v cg))) - < 5 - where - f :: Bit -> (Int, Int) -> Bit -> ((Int, Int), Bit) - f c (accMax, acc) i = - if i == c - then ((if accMax < (acc + 1) then acc + 1 else accMax, acc + 1), i) - else ((accMax, 0), i) diff --git a/clash-cores/test/Test/Cores/Sgmii/Sync.hs b/clash-cores/test/Test/Cores/Sgmii/Sync.hs index 77961b7873..9b167f1b46 100644 --- a/clash-cores/test/Test/Cores/Sgmii/Sync.hs +++ b/clash-cores/test/Test/Cores/Sgmii/Sync.hs @@ -10,7 +10,7 @@ import Data.List (group, mapAccumL, maximumBy) import qualified Hedgehog as H import qualified Hedgehog.Gen as Gen import qualified Hedgehog.Range as Range -import Test.Cores.Sgmii.Common +import Test.Cores.EbTb import Test.Tasty import Test.Tasty.Hedgehog import Test.Tasty.TH