Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Valerii Butorin committed Apr 30, 2024
1 parent 9757aa0 commit 8c8f454
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ nitta v0.0.0.1 - tool for hard real-time CGRA processors
nitta [OPTIONS] FILE

Target system configuration:
--uarch=PATH Microarchitecture configuration file
-a --auto-uarch Use empty microarchitecture and
--march=PATH Microarchitecture configuration file
-a --auto-march Use empty microarchitecture and
allocate PUs during synthesis process.
-t --type=fxM.B Overrides data type specified in
config file
Expand Down
5 changes: 2 additions & 3 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Control.Exception
import Control.Monad (when)
import Data.ByteString.Lazy.Char8 qualified as BS
import Data.Default (def)
import Data.Foldable (forM_)
import Data.Maybe
import Data.Proxy
import Data.String.Utils qualified as S
Expand Down Expand Up @@ -230,9 +231,7 @@ main = do
Nothing -> return Nothing
Just path -> Just <$> parseConfig path

case conf of
Nothing -> return ()
Just conf_ -> saveConfig output_path conf_
forM_ conf $ saveConfig output_path

let exactFrontendType = identifyFrontendType filename frontend_language

Expand Down
1 change: 0 additions & 1 deletion examples/microarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ library:
size: 32
accum{x}:
type: Accum
isInt: true
networks:
net1:
pus:
Expand Down
1 change: 1 addition & 0 deletions nitta.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ test-suite nitta-test
NITTA.Intermediate.Simulation.Tests
NITTA.Intermediate.Tests.Functions
NITTA.Intermediate.Value.Tests
NITTA.Model.Config.Tests
NITTA.Model.Problems.Refactor.Accum.Tests
NITTA.Model.Problems.Refactor.ConstantFolding.Tests
NITTA.Model.Problems.Refactor.Tests
Expand Down
6 changes: 4 additions & 2 deletions src/NITTA/Model/Microarchitecture/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
{-# LANGUAGE PartialTypeSignatures #-}

module NITTA.Model.Microarchitecture.Config (
MicroarchitectureConf (valueType, ioSync),
MicroarchitectureConf (..),
NetworkConf (..),
PUConf (..),
parseConfig,
saveConfig,
mkMicroarchitecture,
Expand Down Expand Up @@ -103,7 +105,7 @@ parseConfig path = do

saveConfig :: FilePath -> MicroarchitectureConf -> IO ()
saveConfig path conf = do
encodeFile (path <> "/microarch.yml") conf
encodeFile (path <> "/microarch.yml") conf

mkMicroarchitecture :: (Val v, Var x, ToJSON x) => MicroarchitectureConf -> BusNetwork T.Text x v Int
mkMicroarchitecture MicroarchitectureConf{mock, ioSync, library, networks} =
Expand Down
2 changes: 1 addition & 1 deletion src/NITTA/Model/Networks/Bus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ instance (UnitTag tag, VarValTime v x t) => ProcessorUnit (BusNetwork tag v x t)
| any (allowToProcess f) (M.elems bnPus) = Right net{bnRemains = f : bnRemains}
-- TODO:
-- There are several issues that need to be addressed: see https://github.com/ryukzak/nitta/pull/195#discussion_r853486450
-- 1) Now the binding of functions to the network is hardcoded, that prevents use of an empty uarch at the start
-- 1) Now the binding of functions to the network is hardcoded, that prevents use of an empty march at the start
-- 2) If Allocation options are independent of the bnRemains, then they are present in all synthesis states, which means no leaves in the synthesis tree
| any (\PUPrototype{pProto} -> allowToProcess f pProto) (M.elems bnPUPrototypes) = Right net{bnRemains = f : bnRemains}
tryBind f BusNetwork{bnPus} =
Expand Down
55 changes: 55 additions & 0 deletions test/NITTA/Model/Config/Tests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}

{- |
Module : NITTA.Model.Config.Tests
Description :
Copyright : (c) Valerii Butorin, 2024
License : BSD3
Maintainer : [email protected]
Stability : experimental
-}
module NITTA.Model.Config.Tests (
tests,
) where

import Data.Maybe
import Data.Map as M
import Data.Text qualified as T
import NITTA.Model.Microarchitecture.Config as Conf
import Test.Tasty (testGroup)
import Test.Tasty.HUnit

tests =
testGroup
"Configuration parsing"
[ testCase "parse config common" $ do
conf <- parseConfig "examples/microarch.yml"
let
lib = fromJust $ library conf
fram = fromJust $ M.lookup (T.pack "fram{x}") lib
nets = networks conf
net = fromJust $ M.lookup (T.pack "net1") nets
spi = fromJust $ M.lookup (T.pack "spi") (fromJust $ pus net)
proros_ = fromJust $ protos net
shift = fromJust $ M.lookup (T.pack "shift{x}") proros_
div_ = fromJust $ M.lookup (T.pack "div{x}") proros_

"Sync" @=? show (ioSync conf)
True @=? mock conf
"fx32.32" @=? T.unpack (valueType conf)
2 @=? M.size (fromJust $ library conf)

32 @=? Conf.size fram
Just True @=? Conf.sRight shift
4 @=? Conf.pipeline div_

"mosi" @=? T.unpack (mosi spi)
"miso" @=? T.unpack (miso spi)
"sclk" @=? T.unpack (sclk spi)
"cs" @=? T.unpack (cs spi)
True @=? isSlave spi
Just 6 @=? bufferSize spi
0 @=? bounceFilter spi
]
2 changes: 2 additions & 0 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import NITTA.Frontends.XMILE.MathParserTests qualified
import NITTA.Intermediate.Functions.Accum.Tests qualified
import NITTA.Intermediate.Simulation.Tests qualified
import NITTA.Intermediate.Value.Tests qualified
import NITTA.Model.Config.Tests qualified
import NITTA.Model.Problems.Refactor.Accum.Tests qualified
import NITTA.Model.Problems.Refactor.ConstantFolding.Tests qualified
import NITTA.Model.Problems.Refactor.Tests qualified
Expand Down Expand Up @@ -61,6 +62,7 @@ main = do
, NITTA.Model.ProcessorUnits.Accum.Tests.tests
, NITTA.Model.ProcessorUnits.Shift.Tests.tests
, NITTA.Model.ProcessorUnits.Tests.DSL.Tests.tests
, NITTA.Model.Config.Tests.tests
, NITTA.Tests.tests
, NITTA.Utils.Tests.tests
]
Expand Down

0 comments on commit 8c8f454

Please sign in to comment.