diff --git a/bs/TagEngine.bs b/bs/TagEngine.bs index 8b12b9d..7726811 100644 --- a/bs/TagEngine.bs +++ b/bs/TagEngine.bs @@ -1,7 +1,6 @@ package TagEngine( - MkTagType, + MkTagType(..), TagEngine(..), - Util.BasicResult(..), mkTagEngine) where import Vector diff --git a/bs/Tests/TagEngineTester.bs b/bs/Tests/TagEngineTester.bs index 4fc700e..5a26477 100644 --- a/bs/Tests/TagEngineTester.bs +++ b/bs/Tests/TagEngineTester.bs @@ -2,6 +2,10 @@ package TagEngineTester(mkTagEngineTester) where import TagEngine import ActionSeq +import Printf +import Util + +type NumTags = 5 mkTagEngineTester :: Module Empty mkTagEngineTester = do @@ -26,39 +30,44 @@ mkTagEngineTester = do in actionSeq $ - do requestTagAction - |> do requestTagAction - |> do requestTagAction - |> do requestTagAction - |> do requestTagAction + do + let expectedTag = 4 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 3 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 2 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 1 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + let expectedTag = 0 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" |> do retireTagAction 2 - -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" |> do - retireTagAction 4 - requestTagAction - -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" - -- |> do $display "BEGIN TRY SIMULTANEOUS RETIRE and REQUEST" + retireTagAction 4 + let expectedTag :: MkTagType NumTags + expectedTag = 2 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" |> do - retireTagAction 4 - requestTagAction - -- |> do $display "END TRY SIMULTANEOUS RETIRE and REQUEST" - |> do $finish - -- |> do retireTagAction 4 - -- |> do retireTagAction 4 - -- |> do retireTagAction 0 - -- |> do requestTagAction - -- |> do requestTagAction - -- |> do retireTagAction 1 - -- |> do requestTagAction - -- |> do $finish + retireTagAction 2 + let expectedTag = 3 + tag <- tagEngine.requestTag + dynamicAssert (tag == expectedTag) "" + |> do + terminateSimNoError addRules $ rules - -- "counter": when True ==> - -- do - -- count := count + 1 - -- $display "count : " (fshow count) - "testIncrement": when (runOnce == False) ==> + "start unit test": when (runOnce == False) ==> do s.start runOnce := True diff --git a/bs/Top.bs b/bs/Top.bs index a0816a0..b5276fd 100644 --- a/bs/Top.bs +++ b/bs/Top.bs @@ -7,9 +7,9 @@ import BRAM import CBindings import Bus import TagEngine + import List import ActionSeq - import Vector import BusTypes diff --git a/bs/Util.bs b/bs/Util.bs index 89492f5..0448782 100644 --- a/bs/Util.bs +++ b/bs/Util.bs @@ -1,24 +1,37 @@ package Util( (|>), - BasicResult(..), - simulate_for) where + terminateSimNoError, + terminateSimWithError, + dynamicAssert + ) where + +import CBindings infixr 0 |> -data BasicResult = Success - | Failure - deriving (Bits, Eq, FShow) - (|>) :: (a -> b) -> a -> b f |> x = f x; -simulate_for :: (Bits a n, Arith a, Eq a) => Reg a -> Reg a -> Rules -simulate_for curr_cycle end_cycle = - rules - "count_cycle_rule": when True ==> action - curr_cycle := curr_cycle + 1 - if curr_cycle == end_cycle - then - $finish - else - $display "cycle = " curr_cycle +assertMessage :: String -> String -> String +assertMessage which mess = + letseq pos = getStringPosition mess -- get position of original message literal + in (which +++" assertion failed: " +++ printPosition pos +++ mess) + +dynamicAssert :: Bool -> String -> Action +dynamicAssert = if not testAssert then (\ _ _ -> noAction) + else (\ b s -> if b then noAction else + action + $display (assertMessage "Dynamic" s) + restoreTerminal + $finish 1 + ) + +terminateSimNoError :: Action +terminateSimNoError = do + restoreTerminal + $finish 0 + +terminateSimWithError :: Action +terminateSimWithError = do + restoreTerminal + $finish 1