diff --git a/osek-verification.cabal b/osek-verification.cabal index e950832b0442c192fca96421565a56ca8e41f10d..2724c75825f2a5ca99544c764341c5c1fd916da8 100644 --- a/osek-verification.cabal +++ b/osek-verification.cabal @@ -35,6 +35,7 @@ library , mtl >= 2.2 && <2.3 , process >= 1.4 && <1.5 default-language: Haskell2010 + ghc-options: -Wall executable mockup_generator main-is: Main.hs @@ -45,6 +46,7 @@ executable mockup_generator , optparse-applicative >= 0.12 && <0.13 hs-source-dirs: src/main default-language: Haskell2010 + ghc-options: -Wall test-suite spec type: exitcode-stdio-1.0 @@ -58,6 +60,8 @@ test-suite spec build-depends: base >= 4.8 && <4.10 , osek-verification , hspec >= 2.2.3 && <2.3 + , QuickCheck >= 2.8 && <2.9 + , quickcheck-text >= 0.1.2 && <0.2 , text , array >= 0.5 && <0.6 , containers >= 0.5 && <0.6 @@ -65,4 +69,6 @@ test-suite spec , bytestring >= 0.10 && <0.11 , aeson >= 1.0 && <1.1 , here >= 1.2 && < 1.3 + , mtl >= 2.2 && <2.3 default-language: Haskell2010 + ghc-options: -Wall diff --git a/src/CFG/C.hs b/src/CFG/C.hs index d4137690b89cbc58281370f2a7d31afb8dec754e..c36d93bf1b60973afecad480747312292529cef7 100644 --- a/src/CFG/C.hs +++ b/src/CFG/C.hs @@ -7,6 +7,7 @@ module CFG.C , compileToCAll , declareExtern , preIdleHook + , DecisionM ) where import Control.Comonad diff --git a/src/CFG/Sanitize.hs b/src/CFG/Sanitize.hs index afcf526fdfbe52b82fc390fcc2328ab43d6a4816..f7777081945e75ab2aa780dac33135b3e4a9fd9f 100644 --- a/src/CFG/Sanitize.hs +++ b/src/CFG/Sanitize.hs @@ -2,6 +2,7 @@ module CFG.Sanitize ( sanitizeNames + , sanitize ) where import Data.Char diff --git a/test/CFG/CSpec.hs b/test/CFG/CSpec.hs index 2b6e20afa660811a8189ce287ecdef254236b05e..75bf790d019af6d922b96989548a0a5f4ea8c0aa 100644 --- a/test/CFG/CSpec.hs +++ b/test/CFG/CSpec.hs @@ -8,6 +8,7 @@ import qualified Data.Text as T --import qualified Data.IntSet as S import Test.Hspec import Data.String.Here +import Control.Monad.State import CFG.IR import CFG.C @@ -15,8 +16,8 @@ import CFG.Types spec :: Spec spec = do - -- instrsToCTest - -- compileToCTest + instrsToCTest + compileToCTest compileToCAllTest externDecls @@ -117,21 +118,25 @@ example2ISRC dec = exampleExternDecls :: Text exampleExternDecls = "extern \"C\" {\nextern void syscall();\n}" --- instrsToCTest :: Spec --- instrsToCTest = describe "instrsToC" $ --- it "works for a given example" $ --- instrsToC Nothing KindFunction example1Input `shouldBe` example1Output +-- | Run DecisionM monad with 0 as initial state +runDecision :: DecisionM a -> a +runDecision = flip evalState 0 --- compileToCTest :: Spec --- compileToCTest = describe "compileToC" $ do --- it "works with a function" $ --- compileToC example1Function `shouldBe` example1FunctionC +instrsToCTest :: Spec +instrsToCTest = describe "instrsToC" $ + it "works for a given example" $ + runDecision (instrsToC Nothing KindFunction example1Input) `shouldBe` example1Output 0 --- it "works with a task" $ --- compileToC example1Function { funKind = KindSubtask } `shouldBe` example1TaskC +compileToCTest :: Spec +compileToCTest = describe "compileToC" $ do + it "works with a function" $ + runDecision (compileToC Nothing example1Function) `shouldBe` example1FunctionC 0 --- it "works with an isr" $ --- compileToC example1Function { funKind = KindISR } `shouldBe` example1ISRC + it "works with a task" $ + runDecision (compileToC Nothing example1Function { funKind = KindSubtask }) `shouldBe` example1TaskC 0 + + it "works with an isr" $ + runDecision (compileToC Nothing example1Function { funKind = KindISR }) `shouldBe` example1ISRC 0 include :: Text include = "#include <mockup_prelude.cc>" diff --git a/test/CFG/SanitizeSpec.hs b/test/CFG/SanitizeSpec.hs index d1e0fbc116ea52aaacd8c67f4791aeb226624d00..deffb5058d28588a11709946bcf109eca8bfc8fd 100644 --- a/test/CFG/SanitizeSpec.hs +++ b/test/CFG/SanitizeSpec.hs @@ -1,17 +1,31 @@ {-# LANGUAGE OverloadedStrings, DuplicateRecordFields #-} module CFG.SanitizeSpec (spec) where -import Data.Function -import Data.Graph -import Data.List -import Data.Maybe -import Data.Text (Text) +import qualified Data.Text as T +import Data.Text.Arbitrary () import Test.Hspec -import Control.Comonad +import Test.QuickCheck +import Data.Char import CFG.Sanitize -import CFG.Types --- TODO Test name sanitation spec :: Spec -spec = return () +spec = describe "sanitize" $ do + it "strips invalid characters" + containsOnlyValidCharacters + + it "it strips leading underscores" + doesntBeginWithUnderscore + +containsOnlyValidCharacters :: Property +containsOnlyValidCharacters = property $ \txt -> + T.all isValid (sanitize txt) + + where + isValid x = x == '_' || isAlphaNum x + +doesntBeginWithUnderscore :: Property +doesntBeginWithUnderscore = property $ \txt -> + case T.uncons (sanitize txt) of + Nothing -> True + Just (first,_) -> first /= '_'