GithubHelp home page GithubHelp logo

Comments (3)

bgamari avatar bgamari commented on August 16, 2024 1

I'm quite fond of the idea of a monadic interface, at least in principle. Here is my attempt: https://git.smart-cactus.org/ben/clash-play/blob/master/TestM.hs.

from clash-prelude.

bgamari avatar bgamari commented on August 16, 2024

Just to supply some inspiration, here is an example of the test bench that I would like to be able to write,

-- | A test plan for a component accepting inputs of type @i@ and outputs of type @o@
data TestM clk i o a 

-- | Feed the DUT an input, return the output that it produces.
tick :: i -> TestM clk i o o

-- | Feed the DUT the given input until it produces an output that satisfies
-- the given predicate.
tickUntil :: i -> (o -> Bool) -> TestM clk i o o

-- | A simple assertion
assert :: Bool -> String -> TestM clk i o ()

testIt :: TestM System (AxiIn 13 32) (AxiOut 13 32) ()
testIt = do
    tick defAxiIn  -- feed the DUT with an input
    tickUntil
        (defAxiIn & axiReadIn %~
               ( (arvalid .~ True)
               . (arid .~ TransId 1)
               . (araddr .~ 32)
               . (arlen  .~ 0)
               . (arsize .~ BurstSize 4)
               . (arburst .~ BurstIncr)))
        (view $ axiReadOut . arready)
    o <- tickUntil defAxiIn (view $ axiReadOut . rvalid)
    assertEqual "Data" 10 (o ^. axiReadOut . rdata)

Unfortunately, it's not at all clear how to implement such an interface in a safe way. You can approximate the desired semantics with some clever knot tying, but it's hard to preserve the property that tick gives you the output from cycle n on the nth invocation.

from clash-prelude.

christiaanb avatar christiaanb commented on August 16, 2024

How about something like this?

data Test i o = Tick i | TickUntil i (o -> Bool) 

testMachineS plan curOutput = case plan of
  [] -> error "finished"
  Tick _:rest -> rest
  TickUntil _ f:rest -> if f curOutput then rest else plan

testMachineO plan = case plan of
  [] -> error "finished"
  Tick i:_ -> i
  TickUntil i _:_ -> i

testIt
  :: (Signal domain i -> Signal domain o)
  -- ^ Function to test
  -> [Test i o]
  -- ^ Plan
  -> [o]
testIt dut plan = sample o
  where
    o   = dut inp
    inp = moore testMachineS testMachineO plan o

from clash-prelude.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.