Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Created March 4, 2016 09:44
Show Gist options
  • Save christiaanb/e1c69f1657331ca5028d to your computer and use it in GitHub Desktop.
Save christiaanb/e1c69f1657331ca5028d to your computer and use it in GitHub Desktop.
module TestDF where
import CLaSH.Prelude
testDF :: (Eq b, Show b, KnownNat n, KnownNat m)
=> DataFlow Bool Bool a b
-> Vec n a -- ^ Inputs
-> Vec m b -- ^ Expected outputs
-> Signal Bool -- ^ 'True' indicates we're done with testing
testDF f testIn expOut =
let (o,oEn,iEn) = df f i (signal True) (signal True)
i = inpGen testIn iEn
in outVer expOut oEn o
-- | Generates a new test sample when the enable is 'True'
inpGen :: KnownNat n
=> Vec n a -- ^ Vector of test samples
-> Signal Bool -- ^ Enable
-> Signal a
inpGen testIn en = (!!) <$> signal testIn <*> i
where
i :: Signal Int
i = regEn 0 en (min <$> (i+1) <*> signal maxI)
maxI :: Int
maxI = fromIntegral $ maxIndex testIn
-- | Checks output against a new verification sample when the enable
-- is 'True'
outVer :: (KnownNat n, Eq b, Show b)
=> Vec n b -- ^ Vector of expected samples
-> Signal Bool -- ^ Enable
-> Signal b -- ^ Output
-> Signal Bool -- ^ 'True' when all the samples are checked
outVer expOut en b = mux en checked finished
where
i :: Signal Int
i = regEn 0 en (min <$> (i+1) <*> signal maxI)
maxI :: Int
maxI = fromIntegral $ maxIndex expOut
finished :: Signal Bool
finished = register False ((==) <$> i <*> signal maxI)
checked :: Signal Bool
checked = assert "testDF" ((!!) <$> signal expOut <*> i)
b
finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment