InteractiveTests.hs revision d3ea4ab5527bc4bd7381d39ecbc4af2199f54341
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher{-# LANGUAGE TypeSynonymInstances, FlexibleContexts #-}
d6342c92c226becbdd254f90a0005b8c00c300dcPetr CechModule : $Header$
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherDescription : Test environment for CSL
294e9a5521d327c5cdc49beeb9cb9e703b3134f1Jan ZelenyCopyright : (c) Ewaryst Schulz, DFKI Bremen 2010
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherLicense : GPLv2 or higher, see LICENSE.txt
8a05fd320a44636d120a18eb7e9956c7b35b3138Jakub HrozekMaintainer : Ewaryst.Schulz@dfki.de
ba4a81e933deebb416603369b447ead6ebaa040dJakub HrozekStability : experimental
60cab26b12df9a2153823972cde0c38ca86e01b9Yassir ElleyPortability : non-portable (uses type-expression in type contexts)
f2b40ec8a4158fec75873828e4980965abbe7f66Yassir ElleyThis file is for experimenting with the Interpreter instances
f2b40ec8a4158fec75873828e4980965abbe7f66Yassir Elleyand general static analysis tools
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Common.Result (diags, printDiags, resultToMaybe)
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport qualified Common.Lib.Rel as Rel
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Control.Monad.Trans (MonadIO (..), lift)
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher-- the process communication interface
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Control.Monad.State (StateT(..))
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Control.Monad.Error (MonadError(..))
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Static.SpecLoader (getSigSensComplete, SigSens(..))
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport Common.Utils (getEnvDef)
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport qualified Data.Map as Map
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherimport qualified Data.Set as Set
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherMAIN TESTING FUNCTIONS:
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallaghertest 64 assStoreAndProgSimple
1dfa1e2968ce2031deb6da7c28b09ce1b5ba56f2Sumit Bosetest 44 assStoreAndProgElim
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallaghertest 45 loadAssignmentStore
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallaghertestResult 54 (depClosure ["F_G"])
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher(mit, _) <- testWithMaple 4 0.8 stepProg 3
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher(mit, _) <- testWithMaple 4 0.8 verifyProg 3
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherinDefinition (undef ncl) ncl
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherFor engineering of the specification (to see how to fix missing constants):
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallaghersens 56 >>= (\ ncl -> inDefinition (undef ncl) ncl) >>= mapM putStrLn >>= return . length
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherVerification Condition Testing:
e22e04517b9f9d0c7759dc4768eedfd05908e9b6Sumit Bose(as, prog) <- testResult 102 assStoreAndProgSimple
83a796ec8de4bde65b11cc8032675406950641faSumit Boselet gr = assDepGraphFromDescList (const $ const True) as
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallaghergr <- fmap (assDepGraphFromDescList (const $ const True) . fst)testResult 102 assStoreAndProgSimple
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherinteresting i's: 44, 46
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherudefC i == show all undefined constants of spec i
022456e93c9b175ce3774afe524e3926f41ba80fSumit BoseelimDefs i == ep-eliminated AS for spec i
3cf7fdfcaedb986f42a6640e26aa057007b64045Jakub HrozekprettyEDefs i == pretty output for elimDefs
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallaghertestElim i == raw elimination proc for spec i
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherprepareAS i == the assignment store after extraction from spec i and further analysis
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallaghertestSMT i == returns the length of elimDefs-output and measures time, good for testing of smt comparison
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher let l = lines s
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher startP = ("MAIN TESTING FUNCTIONS:" /=)
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher endP = ("-}" /=)
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher putStrLn $ unlines $ takeWhile endP $ dropWhile startP l
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagherinstance Pretty Bool where
8babbeee01e67893af4828ddfc922ecac0be4197Pavel Reichl pretty = text . show
fae99bfe4bfc8b4a12e9c2a0ad01b3684c22f934Simo Sorce--------------------------- Shortcuts --------------------------
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherevalWithVerification :: DTime -> Int -> String -> String -> IO String
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallagherevalWithVerification to v lb sp = do
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher let exitWhen s = null s || s == "q" || take 4 s == "quit" || take 4 s == "exit"
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher (_, prog) <- loadAssignmentStore False ncl
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher liftIO $ putStrLn ""
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher liftIO $ putStrLn "****************** Assignment store loaded ******************"
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher liftIO $ putStrLn ""
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher mE <- verifyProg prog
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher when (isJust mE) $ liftIO $ putStrLn $ show $ fromJust mE
1b171c456ff901ab622e44bcfd213f7de86fd787Ariel Barria -- readEvalPrintLoop stdin stdout ">" exitWhen
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen Gallagher testWithMapleGen v to p lb sp >> return ""
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallaghermapleLoop :: MITrans -> IO ()
03532fb1cbb7e8c1d5cf2e93aa3719f926631cabStephen GallaghermapleLoop mit = do
07b7b76d7cd494cbd26263503ba2732c21819941Jan Zeleny if x == "q" then mapleExit mit >> return ()
4cdaf239d4504966bed8ecd5e3fa07def74c7302Sumit Bose else mapleDirect False mit x >>= putStrLn >> mapleLoop mit
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose-- ----------------------------------------------------------------------
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose-- * Gluing the Analysis and Evaluation together
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose-- ----------------------------------------------------------------------
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bosetest :: (Pretty a, MonadIO m) => Int -> ([Named CMD] -> m a) -> m ()
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bosetest i f = testResult i f >>= liftIO . putStrLn . show . pretty
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit BosetestResult :: (Pretty a, MonadIO m) => Int -> ([Named CMD] -> m a) -> m a
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit BosetestResult i f = liftIO (sens i) >>= f
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose-- | Returns sorted assignment store and program after EP elimination
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit BoseassStoreAndProgElim :: [Named CMD] -> IO ([(ConstantName, AssDefinition)], [Named CMD])
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit BoseassStoreAndProgElim ncl = do
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose let (asss, prog) = splitAS ncl
7c30e60c525ea798aaab142766ff00eef4b5df3bPavel Březina gm = fmap analyzeGuarded asss
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose sgl = dependencySortAS gm
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose ve = VarEnv { varmap = Map.fromList $ zip ["I", "F"] [1..]
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose , loghandle = Just stdout
61804568ce5ede3b1a699cda17c033dd6c23f0e3Sumit Bose --, loghandle = Nothing
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek -- ve = emptyVarEnv $ Just stdout
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek el <- execSMTTester' ve $ epElimination sgl
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek return (getElimAS el, prog)
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub Hrozek-- | Returns sorted assignment store and program without EP elimination
03b859510dc13a13a456ca4aa94c0561a0e9684cJakub HrozekassStoreAndProgSimple :: [Named CMD] -> IO ([(ConstantName, AssDefinition)], [Named CMD])
vchdl <- openFile "/tmp/vc.out" WriteMode
f x = case Map.lookup x dr of
Just s -> if Set.null s then x ++ " *" else x
br = Map.filterWithKey (\k _ -> elem k l) $ getBackRef dr
g m x = Map.findWithDefault "" x m
in return $ map f' $ Map.toList $ fmap h br
allDefinitions :: [Named CMD] -> (Map.Map String String)
allDefinitions ncl = Map.fromList $ mapMaybe f ncl where
undef ncl = Set.toList $ undefinedConstants $ fst $ splitAS ncl
[ (44, ("EnCL/EN1591.het", "EN1591"))
, (45, ("EnCL/flange.het", "Flange"))
, (46, ("EnCL/flange.het", "FlangeComplete"))
, (54, ("EnCL/EN1591S.het", "EN1591"))
, (55, ("EnCL/flangeS.het", "Flange"))
, (56, ("EnCL/flangeS.het", "FlangeComplete"))
, (65, ("EnCL/flangeDefault.het", "FlangeDefault"))
, (66, ("EnCL/flangeExported.het", "FlangeComplete"))
libFP i = fromMaybe (if i >= 0 then ("EnCL/Tests.het", "Test" ++ show i)
else ("EnCL/ExtParamExamples.het", "E" ++ show (- i)))
$ Prelude.lookup i testspecs
logf = "/tmp/CSL.log"
:m +CSL.Analysis
toEP s = case runParser (Lexer.separatedBy extparam pComma >-> fst) "" "" s of
(Lexer.separatedBy extparam pComma >-> fst) pSemi >-> fst) "" "" s of
:m +CSL.Analysis
let grdd = snd $ Map.elemAt 0 grdm
:m +CSL.Analysis
let (_, xg) = Map.elemAt 1 gm
let (_, yg) = Map.elemAt 2 gm
-- undefinedConstants :: GuardedMap a -> Set.Set String
f (_, m) = mapM_ g $ Map.toList m
modelRg1 :: Map.Map String (Int, Int)
modelRg1 = Map.fromList [("I", (-5, 5))]
modelRg2 :: Map.Map String (Int, Int)
modelRg2 = Map.fromList [("I", (-5, 5)), ("F", (-5, 5))]
modelRg3 :: Map.Map String (Int, Int)
modelRg3 = Map.fromList [("I", (-5, 5)), ("J", (-5, 5)), ("F", (-5, 5))]
printModel :: Map.Map String (Int, Int) -> EPRange -> String
-- Test for partitioning taken from E82 in CSL/ExtParamExamples.het
:m +CSL.Analysis
execSMTTester' vEnv $ eliminateGuard Map.empty grd
getAS = liftM (Map.toList . fst . splitAS) . sens
getASana = liftM (Map.toList . fmap analyzeGuarded . fst . splitAS) . sens
grddMap = foldr (uncurry $ addAssignment "?") Map.empty . assignments
varMapFromList l = Map.fromList $ zip l $ [1 .. length l]
varMapFromSet :: Set.Set String -> VarMap
varMapFromSet = varMapFromList . Set.toList
vMap :: Map.Map String Int
-- vTypes = Map.map (const Nothing) vMap
vTypes = Map.fromList $ map (\ (x,y) -> (x, boolExps vMap y)) epDomain
vEnvX = VarEnv { varmap = vMap, vartypes = Map.empty, loghandle = Nothing }
compareEPgen :: Show a => (String -> a) -> (a -> a -> EPCompare) -> String -> String -> IO EPCompare
-- many instances (connection/disconnection tests)
printDiags (PC.verbosity $ getRI r') (diags res)
--s -> t -> t1 -> IO (Common.Result.Result a, s)
runTest (CSL.Interpreter.lookup "x") r' >>= return . pretty
runTest (CSL.Interpreter.eval $ toE "cos(x-x)") r' >>= return . pretty
y <- fmap fromJust $ runTest (CSL.Interpreter.lookup "y") r'
addOp mp s = Map.insertWith (+) s 1 mp
extractOps :: OpExtractor a => a -> Map.Map String Int
extractOps = extr Map.empty
-- addOp mp s = Map.insertWith (+) s 1 mp
-- extractOps :: OpExtractor a => a -> Map.Map String Int
-- extractOps = extr Map.empty