From 38374320a36b0f46ca6c0c9d09ad949710e0dae0 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 19 Nov 2008 17:25:02 +0000 Subject: [PATCH] Moved the remainder of the checkInitVar tests over to the new system --- checks/UsageCheckTest.hs | 54 +++++++++++++++++++--------------------- common/OccamEDSL.hs | 9 ++++++- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/checks/UsageCheckTest.hs b/checks/UsageCheckTest.hs index e5aa478..e28a6d7 100644 --- a/checks/UsageCheckTest.hs +++ b/checks/UsageCheckTest.hs @@ -216,39 +216,35 @@ testInitVar = TestList ,oX *:= oX ] - -- Test loops (0 -> 1, 1 -> 2 -> 3 -> 1, 1 -> 4) - -- Loop, nothing happens: - ,testInitVarPass 100 [(0,[],[]),(1,[],[]),(2,[],[]),(3,[],[]),(4,[],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - -- Loop, written to before the loop, read afterwards: - ,testInitVarPass 101 [(0,[],[variable "x"]),(1,[],[]),(2,[],[]),(3,[],[]),(4,[variable "x"],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - -- Loop, written to before the loop, read during the loop - ,testInitVarPass 102 [(0,[],[variable "x"]),(1,[],[]),(2,[],[]),(3,[variable "x"],[]),(4,[],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - -- Loop, written to during the loop, read afterwards (FAIL - loop might not be executed) - ,testInitVarFail 103 [(0,[],[]),(1,[],[]),(2,[],[variable "x"]),(3,[],[]),(4,[variable "x"],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - -- Loop, written to and then read during the loop: - ,testInitVarPass 104 [(0,[],[]),(1,[],[]),(2,[],[variable "x"]),(3,[variable "x"],[]),(4,[],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - -- Loop, read then written to during the loop (FAIL): - ,testInitVarFail 105 [(0,[],[]),(1,[],[]),(2,[variable "x"],[]),(3,[],[variable "x"]),(4,[],[])] - [(0,1,ESeq Nothing), (1,2,ESeq Nothing), (2,3,ESeq Nothing), (3,1,ESeq Nothing), (1,4,ESeq Nothing)] 0 4 "x" - - -- TODO work out (and test) par loops + ,test "Sandwiched loop" $ wrap $ + oSEQ [ + decl (return A.Int) oX [ + oX *:= (return (3::Int)) + ,oWHILE False oSKIP + ,oX *:= oX + ]] + ,test "Read during loop, written before" $ wrap $ + oSEQ [ + decl (return A.Int) oX [ + oX *:= (return (3::Int)) + ,oWHILE False $ oX *:= oX + ]] + ,testWarn "Read during loop, not written before" $ wrap $ + oSEQ [ + decl (return A.Int) oX [ + oWHILE False $ oX *:= oX + ]] + ,testWarn "Written during loop, read after, not written before" $ wrap $ + oSEQ [ + decl (return A.Int) oX [ + oWHILE False $ oX *:= oX + ,oX *:= oX + ]] + -- TODO test dereferenced variables ] where - testInitVarPass :: Int -> [(Int, [Var], [Var])] -> [(Int, Int, EdgeLabel)] -> Int -> Int -> String -> Test - testInitVarPass testNum ns es start end v = TestCase $ assertEither ("testInitVar " ++ show testNum) () $ flip runReaderT emptyState $ checkInitVar emptyMeta (buildTestFlowGraph ns es start end v) (-1) - - testInitVarFail :: Int -> [(Int, [Var], [Var])] -> [(Int, Int, EdgeLabel)] -> Int -> Int -> String -> Test - testInitVarFail testNum ns es start end v = TestCase $ assertEitherFail ("testInitVar " ++ show testNum) $ flip runReaderT emptyState $ checkInitVar emptyMeta (buildTestFlowGraph ns es start end v) (-1) - - variable = Var . A.Variable emptyMeta . simpleName - wrap x = oPROC "foo" [] x oempty test, testWarn :: String -> Occ A.AST -> Test diff --git a/common/OccamEDSL.hs b/common/OccamEDSL.hs index dab7842..b941899 100644 --- a/common/OccamEDSL.hs +++ b/common/OccamEDSL.hs @@ -18,7 +18,7 @@ with this program. If not, see . -- | The necessary components for using an occam EDSL (for building test-cases). module OccamEDSL (ExpInp, ExpInpT, - oSEQ, oPAR, oPROC, oSKIP, oINT, + oSEQ, oPAR, oPROC, oSKIP, oINT, oWHILE, oCASE, oCASEinput, caseOption, inputCaseOption, oALT, guard, oIF, ifChoice, @@ -229,6 +229,13 @@ ifChoice (e, body) body' <- body return $ makePlain $ A.Choice emptyMeta e' body' +oWHILE :: (CanBeExpression e, Castable r A.Process) => e -> O A.Process -> O r +oWHILE e body + = do e' <- liftExpInp $ expr e + body' <- body + return $ makePlain $ A.While emptyMeta e' body' + + singlify :: Data a => A.Structured a -> A.Structured a singlify (A.Several _ [s]) = s singlify ss = ss