From c79f151e2e57fbade5aeedeaa77dd0d42468be74 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Thu, 14 Jul 2022 13:47:30 +0200 Subject: [PATCH] Finished Task 3 --- .../phase_05/project_phase05_tasks/Makefile | 2 +- .../Mutation_Testing_Sample_Model.xml | 140 +++++++++++++----- .../Solution_Phase05_MichaelChen.tex | 19 ++- 3 files changed, 118 insertions(+), 43 deletions(-) diff --git a/project_task_sheets/phase_05/project_phase05_tasks/Makefile b/project_task_sheets/phase_05/project_phase05_tasks/Makefile index 65dee50..5f23eb5 100644 --- a/project_task_sheets/phase_05/project_phase05_tasks/Makefile +++ b/project_task_sheets/phase_05/project_phase05_tasks/Makefile @@ -4,7 +4,7 @@ name = MichaelChen solutionname = Solution_Phase$(phase)_$(name) target = $(solutionname)_V$(version).zip -package = $(solutionname).pdf Duration.java DurationTest.java mutants.txt Mutation_Testing_Sample_Model.xml +package = $(solutionname).pdf Duration.java DurationTest.java build.xml mutation_test.bat mutants.txt Mutation_Testing_Sample_Model.xml latexmkflags = .PHONY : all dev diff --git a/project_task_sheets/phase_05/project_phase05_tasks/Mutation_Testing_Sample_Model.xml b/project_task_sheets/phase_05/project_phase05_tasks/Mutation_Testing_Sample_Model.xml index 28e64e5..06506d0 100644 --- a/project_task_sheets/phase_05/project_phase05_tasks/Mutation_Testing_Sample_Model.xml +++ b/project_task_sheets/phase_05/project_phase05_tasks/Mutation_Testing_Sample_Model.xml @@ -1,7 +1,7 @@ - typedef int[-2,12] digit; + typedef int[47,58] char; broadcast chan initialized; int c0_in = 0; @@ -27,10 +27,10 @@ int c3_in = 0; - + End + Branch Init @@ -58,23 +59,25 @@ int c = 0; - + + - - + + + @@ -99,6 +102,7 @@ int c = 0; End + Branch Init @@ -108,23 +112,25 @@ int c = 0; - + + - - + + + @@ -137,23 +143,81 @@ c2 = c2_in, c3 = c3_in + NUM = Number(); -NUM_MUT = NumberMutant(); +// NUM = NumberMutant(); // to test the expression mutation +// NUM = NumberBranch(); // to test the branch mutation IN_RANGE = InputFromRange(); -system IN_RANGE, NUM, NUM_MUT; +system IN_RANGE, NUM; - - A[] (NUM.End && NUM_MUT.End) imply (NUM.c == NUM_MUT.c) - - A[] NUM.End imply (NUM.c >= -1 && NUM.c < 10000) - + Return value of the function is always a 4 digit number or -1. - A[] NUM_MUT.End imply (NUM_MUT.c >= -1 && NUM_MUT.c < 10000) - + A[] not deadlock || NUM.End + Model never deadlocks and always reaches the end location. + + + A[] (NUM.End imply (NUM.c1 == 48 && NUM.c1 == 49 && NUM.c2 == 50 && NUM.c3 == 51 imply NUM.c == 1234)) + Simple test case. diff --git a/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex b/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex index 57f9e53..5bc01c6 100644 --- a/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex +++ b/project_task_sheets/phase_05/project_phase05_tasks/Solution_Phase05_MichaelChen.tex @@ -344,22 +344,33 @@ \item Pick one suitable method (restricted to int values) or class from your project, and derive an automaton expressing its behaviour. For the creation of your automaton, use the \textit{Uppaal} model checker environment. \begin{answer} - [TODO: Add answer here] + For this exercise I selected a helper method from the \texttt{TypeUtils} class, namely the \texttt{num(char, char, char, char)} method that takes 4 digit characters and converts them to the corresponding 4 digit number. If the digits are invalid, i.e. non-digit characters, the output is $-1$. \end{answer} \item Formulate at least 2 formal requirements that your model / method needs to satisfy, create corresponding \textit{queries} in Uppaal, and execute them to assure that your base model satisfies them. Enable \texttt{Options $\rightarrow$ Diagnostic Trace $\rightarrow$ Some} to get a counterexample trace in case that a queried formula is not satisfied. This trace can be inspected in the \texttt{Simulator} tab. \begin{answer} - [TODO: Add answer here] + \begin{enumerate} + \item \texttt{A[] not deadlock || NUM.End} assures that the model will never deadlock except for the end location, meaning that the function always returns. This property is easily satisfied as there are no loops or complex behaviours in the model. + \item \texttt{A[] NUM.End imply (NUM.c >= -1 \&\& NUM.c < 10000)} assures that the return value of the function is always a 4 digit number or negative one. This property is also satisfied by the model. + \item \texttt{A[] (NUM.End imply (NUM.c1 == 48 \&\& NUM.c1 == 49 \&\& NUM.c2 == 50 \&\& NUM.c3 == 51 imply NUM.c == 1234))} is a simple test case for the assertion \texttt{num('1', '2', '3', '4') == 1234}. + \item \texttt{A[] (NUM.End \&\& NUM\_MUT.End) imply (NUM.c == NUM\_MUT.c)} verifies that for all executions of the function and the mutated function, i.e. when the functions each have reached their end state, have equal return values. This indicates that the mutation does not influence the function behaviour. In our example this property does not hold, because the mutation removes a boundary check. UPPAAL returns as a counterexample trace the inputs \texttt{num('9', '1', '6', ':')} for which the ground string function correctly returns $-1$ while the mutation missing the boundary check for the last character outputs $9170$. + \end{enumerate} \end{answer} \item Apply \textit{one} mutation operator from Table~\ref{table:operators} to \textit{one} single expression in your model, and re-evaluate your queries. Explain why the verification results of the model changed or remained the same. If a counterexample is created, note the test vector that kills the mutant. \begin{answer} - [TODO: Add answer here] + Here are the results for each of the properties from the previous subtask. + \begin{enumerate} + \item Since only one branch property changed and not the model structure the function still does not deadlock so the property still holds and cannot be killed by this property. + \item This property strongly killes the mutation because an edge case is now missing for the last character. The validator gives the counterexample trace input \texttt{num('9', '9', '9', ':')}, which now incorrectly outputs $10000$. The result should be $-1$ because \texttt{':'} isn't a digit character. + \item The last property still holds because the simple test case does not catch the mutated edge case. + \item This property already compares the function to its mutation so the task does not apply here. + \end{enumerate} \end{answer} \item Reroute one transition in your model (i.e., connect the edge to a different destination node), and re-evaluate your queries. Explain why the verification results of the model changed or remained the same. If a counterexample is created, note the test vector that kills the mutant. \begin{answer} - [TODO: Add answer here] + With the branch mutation (see model file), most properties still hold except for the deadlock property. This is because the properties are written as \texttt{A[] NUM.End imply ...}, but since the mutated version never reaches the end this property is always true. The deadlock property however is violated because now the model can be in a deadlock state without reaching the end state (note, that for modelling a deadlock here we require another guard to avoid a livelock situation here). \end{answer} \end{enumerate}