Skip to content

Commit 1ca5437

Browse files
Add tests for #1033
1 parent 83ed83a commit 1ca5437

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module T1033 where
2+
3+
import Clash.Explicit.Prelude
4+
import Clash.Prelude (HiddenClock, hasClock)
5+
import qualified Prelude as P
6+
7+
{-# ANN topEntity
8+
(Synthesize
9+
{ t_name = "top"
10+
, t_inputs = [ PortName "wrong"]
11+
, t_output = PortName "theOutput"
12+
}
13+
)#-}
14+
topEntity
15+
:: (Clock System, Reset System, Enable System)
16+
-> Signal System Int
17+
-> Signal System Int
18+
topEntity (clk, rst, en) i =
19+
register clk rst en 0 i
20+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module T1033 where
2+
3+
import Clash.Explicit.Prelude
4+
import Clash.Prelude (HiddenClock, hasClock)
5+
import Data.List
6+
import System.Environment
7+
import System.FilePath
8+
import qualified Prelude as P
9+
10+
{-# ANN topEntity
11+
(Synthesize
12+
{ t_name = "top"
13+
, t_inputs =
14+
[ PortName "theHiddenClock"
15+
, PortProduct "en_int" [PortName "theEnable", PortName "a"]
16+
, PortProduct "int_int_rst" [PortName "b", PortProduct "int_rst" []]
17+
]
18+
, t_output = PortName "theOutput"
19+
}
20+
)#-}
21+
topEntity
22+
:: ( dom ~ System -- Check whether Clash skips eq constraints
23+
, HiddenClock dom ) -- Hidden* consists of some construct and a
24+
-- KnownDomain. We don't want them to split off.
25+
=> (Enable dom, Signal dom Int)
26+
-- ^ We do want Enable/Signal to be split
27+
-> (Signal dom Int, (Signal dom Int, Reset dom))
28+
-- ^ And we want to do that recursively
29+
-> Signal dom Int
30+
topEntity (en, a) (b, (c, rst)) =
31+
register hasClock rst en 0 (a + b + c)
32+
33+
assertIn :: String -> String -> IO ()
34+
assertIn needle haystack
35+
| needle `isInfixOf` haystack = return ()
36+
| otherwise = P.error $ P.concat [ "Expected:\n\n ", needle
37+
, "\n\nIn:\n\n", haystack ]
38+
39+
-- VHDL test
40+
main :: FilePath -> IO ()
41+
main topFile = do
42+
content <- readFile topFile
43+
44+
assertIn "theHiddenClock" content
45+
assertIn "en_int_theEnable" content
46+
assertIn "en_int_a" content
47+
assertIn "int_int_rst_b" content
48+
assertIn "int_int_rst_int_rst_0" content
49+
assertIn "int_int_rst_int_rst_1" content
50+
51+
mainVHDL :: IO ()
52+
mainVHDL = do
53+
[topFile] <- getArgs
54+
main (replaceFileName topFile "top/top.vhdl")
55+
56+
mainVerilog :: IO ()
57+
mainVerilog = do
58+
[topFile] <- getArgs
59+
main (replaceFileName topFile "top/top.v")
60+
61+
mainSystemVerilog :: IO ()
62+
mainSystemVerilog = do
63+
[topFile] <- getArgs
64+
main (replaceFileName topFile "top/top.sv")

testsuite/Main.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ runClashTest = defaultMain $ clashTestRoot
9595
, runFailingTest ("tests" </> "shouldfail" </> "InvalidPrimitive") [VHDL] ["-itests/shouldfail/InvalidPrimitive"] "InvalidPrimitive" (Just "InvalidPrimitive.json")
9696
-- Disabled, due to it eating gigabytes of memory:
9797
-- , runFailingTest ("tests" </> "shouldfail") allTargets [] "RecursivePoly" (Just "??")
98+
, runFailingTest ("tests" </> "shouldfail" </> "TopEntity") allTargets [] "T1033" (Just "PortProduct \"wrong\" []")
9899
]
99100
, clashTestGroup "shouldwork"
100101
[ clashTestGroup "AutoReg"
@@ -382,6 +383,8 @@ runClashTest = defaultMain $ clashTestRoot
382383
, outputTest ("tests" </> "shouldwork" </> "TopEntity") [Verilog] [] [] "PortNamesWithRTree" "main"
383384
, runTest "TopEntHOArg" def{entities=Entities ["f", "g"], topEntity=TopEntity "f", hdlSim=False}
384385
, runTest "T701" def {hdlSim=False,entities=Entities ["mynot", ""]}
386+
, runTest "T1033" def {hdlSim=False,entities=Entities ["top", ""], topEntity=TopEntity "top"}
387+
, outputTest ("tests" </> "shouldwork" </> "TopEntity") allTargets [] [] "T1033" "main"
385388
]
386389
, clashTestGroup "Unit"
387390
[ runTest "Imap" def

0 commit comments

Comments
 (0)