From d7c3d8af2e45212e363aaf4d188f62b739e7494c Mon Sep 17 00:00:00 2001 From: Koen Wermer <koenwermer@gmail.com> Date: Fri, 3 Feb 2017 17:31:29 +0100 Subject: [PATCH] added a function to perform the false positives test --- Main.hs | 88 +++++++++++++---- ...eturnValueVar == returnValue_False_False_1 | 92 ++++++++++++++++++ Tests/arrays1.class | Bin 0 -> 2560 bytes Tests/arrays1.java | 2 +- 4 files changed, 162 insertions(+), 20 deletions(-) create mode 100644 Results/arrays1_true_returnValueVar == returnValue_returnValueVar == returnValue_False_False_1 create mode 100644 Tests/arrays1.class diff --git a/Main.hs b/Main.hs index 93f335f..e0b4450 100644 --- a/Main.hs +++ b/Main.hs @@ -21,6 +21,7 @@ sourcePath = joinPath ["Tests", testFile ++ ".java"] mutantsDir = joinPath ["..", testFile ++ " mutants"] resultsPath = joinPath ["Results", testFile ++ "_" ++ postCondVoid ++ "_" ++ postCondRefType ++ "_" ++ postCondPrimType ++ "_" ++ show ignoreLibMethods ++ "_" ++ show ignoreMainMethod ++ "_" ++ show nrOfUnroll] +-- The main functions performs the mutation test on the test file, given that the mutations of the source are already created in the right location main :: IO () main = do -- Create the file for the results @@ -39,30 +40,30 @@ main = do let mutationPaths = map (\n -> joinPath [mutantsDir, n, testFile ++ ".java"]) mutationFolders -- Calculate the wlp per method of all the mutants - wlpMutants <- mapM (\path -> parseFile path >>= (\(env', decls', methods') -> wlpMethods env' decls' methods') >>= return . (path, )) mutationPaths + wlpMutants <- mapM (\path -> parseFile path >>= (\(env', decls', methods') -> wlpMethods env' decls' methods') >>= return . (getMutantNumber path, )) mutationPaths -- A list containing a 1 or 0 per mutant, indicating the number of errors found - errorsFound <- mapM (compareWlps env decls wlpOriginal) wlpMutants + errorsFound <- mapM (compareWlps resultsPath env decls wlpOriginal) wlpMutants - printAndAppend ("Total number of mutants: " ++ show (length errorsFound)) - printAndAppend ("Number of mutants in which we found an error: " ++ show (sum errorsFound)) + printAndAppend resultsPath ("Total number of mutants: " ++ show (length errorsFound)) + printAndAppend resultsPath ("Number of mutants in which we found an error: " ++ show (sum errorsFound)) -- Creates and initializes a file for the results initResultsFile :: IO () initResultsFile = do writeFile resultsPath ("testFile: " ++ testFile) - printAndAppend ("postCondVoid: " ++ postCondVoid) - printAndAppend ("postCondRefType: " ++ postCondRefType) - printAndAppend ("postCondPrimType: " ++ postCondPrimType) - printAndAppend ("ignoreLibMethods: " ++ show ignoreLibMethods) - printAndAppend ("ignoreMainMethod: " ++ show ignoreMainMethod) - printAndAppend ("nrOfUnroll: " ++ show nrOfUnroll) - printAndAppend ("erronous mutations detected:") + printAndAppend resultsPath ("postCondVoid: " ++ postCondVoid) + printAndAppend resultsPath ("postCondRefType: " ++ postCondRefType) + printAndAppend resultsPath ("postCondPrimType: " ++ postCondPrimType) + printAndAppend resultsPath ("ignoreLibMethods: " ++ show ignoreLibMethods) + printAndAppend resultsPath ("ignoreMainMethod: " ++ show ignoreMainMethod) + printAndAppend resultsPath ("nrOfUnroll: " ++ show nrOfUnroll) + printAndAppend resultsPath ("erronous mutations detected:") -- Prints a string and writes it to the results file -printAndAppend :: String -> IO () -printAndAppend s = do - appendFile resultsPath ("\n" ++ s) +printAndAppend :: FilePath -> String -> IO () +printAndAppend results s = do + appendFile results ("\n" ++ s) putStrLn s -- Parses a files and extracts the necessary information from the compilation unit @@ -81,7 +82,7 @@ parseFile s = do return (env, decls, methods) --- | Calculates the wlp for every method in the source file. Also returns the type environment +-- | Calculates the wlp for every method in the list seperately wlpMethods :: TypeEnv -> [TypeDecl] -> [Ident] -> IO [(Ident, Exp)] wlpMethods env decls methods = mapM (\ident -> wlpMethod env decls ident >>= return . (ident, )) methods' where methods' = if ignoreMainMethod then filter (/= Ident "main") methods else methods @@ -100,8 +101,8 @@ wlpMethod env decls ident = do return pred -- | Compares the wlp per method of a program S and mutation S' by verifying that (wlp (S, m) q => wlp (S', m) q) holds for every method m. Returns 0 if it holds and 1 if it doesn't hold -compareWlps :: TypeEnv -> [TypeDecl] -> [(Ident, Exp)] -> (String, [(Ident, Exp)]) -> IO Int -compareWlps env decls s (path, s') = do +compareWlps :: FilePath -> TypeEnv -> [TypeDecl] -> [(Ident, Exp)] -> (String, [(Ident, Exp)]) -> IO Int +compareWlps results env decls s (path, s') = do -- Get a list with for every method the number of errors found (1 or 0) errorsFound <- mapM compareMethod s -- Return 1 if we found at least 1 error @@ -109,7 +110,7 @@ compareWlps env decls s (path, s') = do where compareMethod (ident, e) = case lookup ident s' of Nothing -> putStrLn ("The method \'" ++ show ident ++ "\' is missing in one of the mutations.") >> return 0 -- print a warning and return 0 errors found - Just e' -> if unsafeIsTrue (extendEnv env decls ident) decls (e `imp` e') then return 0 else printAndAppend (getMutantNumber path ++ " " ++ prettyPrint ident) >> return 1 -- print a message and return 1 error found + Just e' -> if unsafeIsTrue (extendEnv env decls ident) decls (e `imp` e') then return 0 else printAndAppend results (path ++ " " ++ prettyPrint ident) >> return 1 -- print a message and return 1 error found -- Gets the right post-condition given the type of a method getPostCond :: Maybe Type -> Exp @@ -125,7 +126,56 @@ getPostCond t = case parser Language.Java.Parser.exp postCond' of getMutantNumber :: FilePath -> String getMutantNumber path = takeWhile (/= '\\') (path \\ (mutantsDir ++ "\\")) --- Calculate the wlp (for testing purposes) + + + +---------------------------- +-- Other test functions -- +---------------------------- + +-- Performs the false-positives-test on the set of test programs with equivalent mutations +testFalsePositives :: IO () +testFalsePositives = do + let results = joinPath ["Results", "False Positives", postCondVoid ++ "_" ++ postCondRefType ++ "_" ++ postCondPrimType ++ "_" ++ show ignoreLibMethods ++ "_" ++ show ignoreMainMethod ++ "_" ++ show nrOfUnroll] + + -- Create the file for the results + writeFile results ("False positives test") + printAndAppend results ("postCondVoid: " ++ postCondVoid) + printAndAppend results ("postCondRefType: " ++ postCondRefType) + printAndAppend results ("postCondPrimType: " ++ postCondPrimType) + printAndAppend results ("ignoreLibMethods: " ++ show ignoreLibMethods) + printAndAppend results ("ignoreMainMethod: " ++ show ignoreMainMethod) + printAndAppend results ("nrOfUnroll: " ++ show nrOfUnroll) + printAndAppend results ("False positives found in:") + + n1 <- testFalsePositives' results "BST.java" ["BST_no_parent.java"] + n2 <- testFalsePositives' results "Fibonacci.java" ["Fibonacci_no_extra_prints.java"] + n3 <- testFalsePositives' results "Stack.java" ["Stack_bool_is_result.java", "Stack_constructor_duplication.java", "Stack_useless_property.java"] + + printAndAppend results ("Total number of false positives: " ++ show (n1 + n2 + n3)) + where + testFalsePositives' :: FilePath -> FilePath -> [FilePath] -> IO Int + testFalsePositives' results source mutations = testFalsePositives'' results (joinPath ["Equivalent mutations", source]) (map (\mutant -> joinPath ["Equivalent mutations", "Mutants", mutant]) mutations) + + -- Tests a specific source file against all its equivalent mutations, updates the test result file and returns the number of false positives + testFalsePositives'' :: FilePath -> FilePath -> [FilePath] -> IO Int + testFalsePositives'' results source mutations = do + -- Parse the original sourceCode + (env, decls, methods) <- parseFile source + + -- Get the wlp per method of the original source code + wlpOriginal <- wlpMethods env decls methods + + -- Calculate the wlp per method of all the mutants + wlpMutants <- mapM (\path -> parseFile path >>= (\(env', decls', methods') -> wlpMethods env' decls' methods') >>= return . (path, )) mutations + + -- A list containing a 1 or 0 per mutant, indicating the number of errors found + -- CompareWlp also writes detailed information to the results file + errorsFound <- mapM (compareWlps results env decls wlpOriginal) wlpMutants + + return (sum errorsFound) + +-- Calculate the wlp of the test file (for testing purposes) calcWlp :: IO () calcWlp = do source <- readFile sourcePath diff --git a/Results/arrays1_true_returnValueVar == returnValue_returnValueVar == returnValue_False_False_1 b/Results/arrays1_true_returnValueVar == returnValue_returnValueVar == returnValue_False_False_1 new file mode 100644 index 0000000..7c3634d --- /dev/null +++ b/Results/arrays1_true_returnValueVar == returnValue_returnValueVar == returnValue_False_False_1 @@ -0,0 +1,92 @@ +testFile: arrays1 +postCondVoid: true +postCondRefType: returnValueVar == returnValue +postCondPrimType: returnValueVar == returnValue +ignoreLibMethods: False +ignoreMainMethod: False +nrOfUnroll: 1 +erronous mutations detected: +96 findAndPrintPairs +93 main +93 findAndPrintPairs +90 main +90 findAndPrintPairs +85 main +85 findAndPrintPairs +75 goodResize +71 goodResize +68 goodResize +67 goodResize +65 goodResize +52 badResize +49 badResize +48 badResize +46 badResize +39 findMin +38 findMin +36 findMin +35 findMin +34 findMin +33 findMin +30 findMin +28 findMin +24 findMin +217 bubblesort +217 isAscending +215 isAscending +214 isAscending +213 isAscending +212 isAscending +211 isAscending +210 isAscending +209 isAscending +208 isAscending +207 isAscending +206 isAscending +203 isAscending +201 isAscending +196 isAscending +192 bubblesort +192 isAscending +191 isAscending +189 isAscending +188 isAscending +187 bubblesort +187 isAscending +186 bubblesort +186 isAscending +185 isAscending +184 bubblesort +184 isAscending +173 bubblesort +170 bubblesort +167 bubblesort +164 bubblesort +156 main +156 bubblesort +153 main +153 bubblesort +149 main +149 bubblesort +147 main +147 bubblesort +137 main +137 bubblesort +134 main +134 bubblesort +132 bubblesort +130 bubblesort +129 bubblesort +128 bubblesort +126 bubblesort +125 bubblesort +124 bubblesort +121 bubblesort +120 main +120 bubblesort +114 bubblesort +112 bubblesort +109 bubblesort +107 bubblesort +Total number of mutants: 217 +Number of mutants in which we found an error: 67 \ No newline at end of file diff --git a/Tests/arrays1.class b/Tests/arrays1.class new file mode 100644 index 0000000000000000000000000000000000000000..e5852dfde49dcfa0375623ed8358d28bdcb63bb5 GIT binary patch literal 2560 zcmbtVYi|@~6n@^_*`3|(_DZ)DcZ&lQY!_TEVr^kt?r5bKq<{imI^7xC!R<~nGpp8X zR0K^-RH6wNO{ALe!Ara(ZKI}q(}cu-;7>5|I|BN=Gh4QJ`(ihJ=gfJ}d(Ly7bKW!8 zZhf}^U@M9VtVDML8T80yn_RZXx#U&!#?Y5Q6gv{wiCuB*#vT=W6R1IV4EyABzg!-S z;h`A%V|ZA;9Y|mRgE0)nFf5%NlpbjRh}0jF%ZQ4@2^_&u6^{xmYu8=ZbUe#0xqB^F zA1j)MfH*D?&08hQ>k|lfbRHE@_Sl9gP(NUm%%Sq+nCTp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^^4iM4+Aq^4IFd+>Q(xHEY!_ilP^E2TnboYu6r!o7}QhLHciOh^L+SewFbwn1c zEjOC}7<<1#;(OE_n?tgxb{2J+S=2W*P-v4vBL&(n>Uc(qP1L3-%wpLrnooyG@MnI_ zFa4F|$Ju00GNY$h>``on4u|q{)V<8vB}r~ZwD|^vxPiF%9gnc|LG?M%gVaR2!t|H_ zl$z2T4pMq4a{<%gUcda=g*HPmW>D}?Y)L7XkW4AcXm;T;+GX!9CY)j-DMhB#LW$|f zmX=+^e`PfHDbh-BAm;st+#2SR4!Y{RpZe>5l&0)FmS04TbU%mIt5qiY*hqlQOdYhq z<!JEO_GNypp20Y|@Gwp3dAx)da27A(ZSI|;-Fdu<FYubr(sIO`Z}BQhp6bL(tv%qW znJvkWUZn@dNt7HQo5K0Dta5v`w7i)z%N0SEv$*TDV9|b|!7S2Ms4f0AJHz{NmMwUO zq2J`^^(`Ml9HAQs@gA&WP=19fL0_wkh#d+iLHYu^{b{hp=OmT6ggD<XS82&+6eGuu z`UI+S1xh%W71#bYE8bxy?=qkFIJ?d<<omp*AE1|{1hXP~6N(Tk)ViG_O1Ssm9=H;h i{A+AtC%0X!g!vYcYL<(`S9*#dl-wytbQfPjc;HVw+6oK+ literal 0 HcmV?d00001 diff --git a/Tests/arrays1.java b/Tests/arrays1.java index fdffebf..b2a09fd 100644 --- a/Tests/arrays1.java +++ b/Tests/arrays1.java @@ -3,7 +3,7 @@ //https://www.cs.utexas.edu/~scottm/cs307/javacode/codeSamples/ArrayExamples.java -public class ArrayExamples +public class arrays1 { public static void main(String[] args) { int[] list = new int[7]; -- GitLab