diff --git a/doc/dev_infrastructure/ttool_development_infrastructure.tex b/doc/dev_infrastructure/ttool_development_infrastructure.tex index b16a4d5474790d84d317862352729daaf771ede7..1bce4d0d4cc55d0e45de92d10834b37399a772ef 100644 --- a/doc/dev_infrastructure/ttool_development_infrastructure.tex +++ b/doc/dev_infrastructure/ttool_development_infrastructure.tex @@ -830,10 +830,10 @@ further divided into its simulator and GUI components, which are not tested under the same test environment and framework due to the different languages used to develop these components. -A recommended practice consists of naming the folders containing the classes -with the same name of root package of the provided classes such as -$fr.tpt.ttool.tests.component\_name$, where $component\_name$ is the name of the -component of TTool being tested. +%A recommended practice consists of naming the folders containing the classes +%with the same name of root package of the provided classes such as +%$fr.tpt.ttool.tests.component\_name$, where $component\_name$ is the name of the +%component of TTool being tested. \subsection{Java} @@ -970,9 +970,230 @@ so that other can use them but be careful not to share something with absolute paths. -\subsection{C++} +\subsection{Directories} + +Tests are currently located in: +\begin{verbatim} +ttool/src/ +\end{verbatim} +\begin{itemize} +\item The Java source code for these tests is in: +\end{itemize} +\begin{verbatim} +ttool/src/java +\end{verbatim} +There, tests testing the graphical user interface are located in the \textit{ui/} subdirectory, those testing avatar aspects are in \textit{avatartranslator/}, \ldots +\begin{itemize} +\item The resources, for instances input files are in: +\end{itemize} +\begin{verbatim} +ttool/src/resources +\end{verbatim} + +\subsection{Examples} + +\subsubsection{Example \# 1: basic test} + +\begin{enumerate} +\item Open the file \textit{ttool/src/test/java/myutil/BoolExpressionEvaluatorTest.java}\\ +This file contains methods annotated with the "@Test" pragma. This means that when running the following command, all these functions will be executed: +\begin{verbatim} +gradle test -i --tests myutil.BoolExpressionEvaluatorTest +\end{verbatim} +\item Note the \textit{assertTrue()} and\textit{ assertFalse()} calls used to check a given assertion. For instance, if\textit{ assertTrue(b)} is called and b evals to false, then the test is considered as failed. +\end{enumerate} + +\subsubsection{Example \# 2: test using a resource as input} + +\begin{enumerate} +\item Open the file \textit{ttool/src/test/java/tmltranslator/DiplodocusParsingTest.java} +Basically, the test opens models and check their syntax, and compare the result of this syntax checking with the expected one. +\item The base directory in which input models are stored is first defined: +\begin{verbatim} +RESOURCES_DIR = getBaseResourcesDir() + "/tmltranslator/parsing/"; +\end{verbatim} +It means that input files are stored in: +\begin{verbatim} +ttool/src/test/resources/tmltranslator/parsing/ +\end{verbatim} +\item The names of the files to be loaded is given in a static attribute: +\begin{verbatim} +private final String [] MODELS = {"test_parsing_1", "test_parsing_2"}; +\end{verbatim} +\item The expected results of the syntax checking is stored in a static array: +\begin{verbatim} +private final boolean [] + EXPECTED_RESULTS_SYNTAX_CHECKING_OK = {true, false}; +\end{verbatim} +\end{enumerate} + + +\subsubsection{Example \# 3: test of the graphical user interface} +\begin{enumerate} +\item Open the file \textit{ttool/src/test/java/ui/TestAvatarDesignPanelTranslator.java} +Basically, the test opens an input graphical Avatar model and generates an intermediate Avatar specification. +\item The test inherits from \textit{AbstractUITest} which constructor creates the main TTool window. This class also features functions to load models, to locate a given view or a given component, e.g.: + +\begin{verbatim} +protected void openModel( final String fileName ) { ...} + +protected TDiagramPanel findDiagramPanel( final TDiagramPanel +parentPanel, final String diagramName ) {...} + +protected TGComponent findDiagComponent( final int compoId, + final TDiagramPanel diagPanel ) {...} +\end{verbatim} + +\item The test references diagrams and components of different models, e.g. with the following cascading calls: + +\begin{verbatim} +@Test +public void + testTranslateStateMachineDiagramToAvatarDisableTransitionInfoGuard() { +... + testTranslateStateMachineDiagramToAvatarCoffeeMachineDisable( + TAB_MAIN_DESIGN, DIAG_WALLET, "TransitionInfoGuard", 789 ); +} + +-> + +testTranslateStateMachineDiagramToAvatarDisable( "CoffeeMachine_Avatar", + tabName, blockName, testName, composToDisable ); + + +-> + +openModel( modelName ); +... +final AvatarSpecification spec = translateDiagramToAvatar( tabName ); +... +\end{verbatim} + +\end{enumerate} + + +\subsubsection{Example \# 4: test of the command line interface} +Tests evaluating the command line interface do no really enter commands in an interactive way. in fact, they execute a TTool script and test if the outputs of this execution are as expected. + +\begin{enumerate} +\item Open the file \textit{ttool/src/test/java/cli/CLIModelTest.java} +Basically, this tests executes a script called "scriptmodel". Basically, this scripts opens a model and saves it under a new name. +\begin{verbatim} +String filePath = getBaseResourcesDir() + + PATH_TO_TEST_FILE + "scriptmodel"; +\end{verbatim} + +\item It checks that the output directory of the test exists, if not, it creates it: +\begin{verbatim} +... +File makeDir = new File(getBaseResourcesDir() + + PATH_TO_OUTPUT_FILE); +makeDir.mkdir(); +... +\end{verbatim} + +\item It creates the command line interpreter, and asks this interpreter to run on the input script: +\begin{verbatim} +Interpreter interpret = new Interpreter(script, + (InterpreterOutputInterface)this, show); +interpret.interpret(); +\end{verbatim} + +\item It checks if the file was correctly saved, by checking if the file contains a plausible number of bytes(since the TTool XML format evolves all the time, we cannot check for a precise number of bytes). + +\begin{verbatim} +f = new File(getBaseResourcesDir() + NEW_MODEL_FILE); + assertTrue(myutil.FileUtils.checkFileForOpen(f)); + String data = myutil.FileUtils.loadFileData(f); + + assertTrue(data.length() > 0); + assertTrue (f.length() > 100); + assertTrue (f.length() < 500); +\end{verbatim} + +\end{enumerate} + +\subsubsection{Example \# 5: test of the C++ simulator} +Tests on the C++ simulator are also started from JUnit. Usually, there, the idea is to generate the C++ simulation environment from a TTool model, and then to check that the outputs of the execution of the simulation is as expected. + +\begin{enumerate} +\item Open the test file \textit{ttool/src/test/java/tmltranslator/DiplodocusSimulatorTest.java}\\ + +\item The test function testSimulationGraph iterates over input models: + +\begin{verbatim} +for(int i=0; i<MODELS.length; i++) { +... +\end{verbatim} + +\item The test loads the model under test + +\begin{verbatim} +File f = new File(RESOURCES_DIR + s + ".tmap"); +... +spec = FileUtils.loadFileData(f); +\end{verbatim} + +\item Then, the test parses the \textit{spec} String in order to build the corresponding mapping specification +\begin{verbatim} +boolean parsed = tmts.makeTMLMapping(spec, RESOURCES_DIR); +assertTrue(parsed); +\end{verbatim} + +\item The test verifies that the syntax of the built mapping is correct: +\begin{verbatim} +TMLMapping tmap = tmts.getTMLMapping(); +TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmap); +syntax.checkSyntax(); +assertTrue(syntax.hasErrors() == 0); +\end{verbatim} + +\item The test then generates the corresponding C code +\begin{verbatim} +tml2systc = DiploSimulatorFactory. + INSTANCE.createCodeGenerator(tmap, al, alTepe); +tml2systc.setModelName(s); +String error = tml2systc.generateSystemC(false, true); +assertTrue(error == null); +\end{verbatim} + +\item The test goes on with the compilation process: +\begin{verbatim} +proc = Runtime.getRuntime().exec("make -C " + SIM_DIR + " clean"); +... +proc = Runtime.getRuntime().exec("make -C " + SIM_DIR + ""); +\end{verbatim} + +\item If successful, the simulation is run: +\begin{verbatim} +String[] params = new String [4]; +params[0] = "./" + SIM_DIR + "run.x"; +params[1] = "-explo"; +params[2] = "-gname"; +params[3] = graphPath; +proc = Runtime.getRuntime().exec(params); +\end{verbatim} + +\item Simulation results (e.g., a reachability graph) can finally be gathered and compared with the existing ones +\begin{verbatim} +// Loading graph data +graphData = FileUtils.loadFileData(graphFile); + +// Creating the graph in memory +AUTGraph graph = new AUTGraph(); +graph.buildGraph(graphData); + +// Comparing with the golden model +assertTrue(NB_Of_STATES[i] == graph.getNbOfStates()); +assertTrue(NB_Of_TRANSTIONS[i] == graph.getNbOfTransitions()); +int maxValue = graph.getMinValue("allCPUsFPGAsTerminated"); +assertTrue(MIN_CYCLES[i] == minValue); +int maxValue = graph.getMaxValue("allCPUsFPGAsTerminated"); +assertTrue(MAX_CYCLES[i] == maxValue); +\end{verbatim} +\end{enumerate} + -TODO \newpage diff --git a/ttool/src/test/java/tmltranslator/DiplodocusParsingTest.java b/ttool/src/test/java/tmltranslator/DiplodocusParsingTest.java index 1cb7fb866e85f34a5f9272cc82970f09f304bb88..2ba83215e872fb75fc6ac0caef924d0afd489c50 100644 --- a/ttool/src/test/java/tmltranslator/DiplodocusParsingTest.java +++ b/ttool/src/test/java/tmltranslator/DiplodocusParsingTest.java @@ -24,8 +24,8 @@ import static org.junit.Assert.*; public class DiplodocusParsingTest extends AbstractTest { - final String [] MODELS = {"test_parsing_1", "test_parsing_2"}; - final boolean [] EXPECTED_RESULTS_SYNTAX_CHECKING_OK = {true, false}; + private final String [] MODELS = {"test_parsing_1", "test_parsing_2"}; + private final boolean [] EXPECTED_RESULTS_SYNTAX_CHECKING_OK = {true, false}; @BeforeClass diff --git a/ttool/src/test/java/tmltranslator/DiplodocusSimulatorTest.java b/ttool/src/test/java/tmltranslator/DiplodocusSimulatorTest.java index a1ba3f3087f4296406ac9f444f246f795fb1ee28..37e0785d6823d3dfdd4ffe22604fdd12eef0e5f0 100644 --- a/ttool/src/test/java/tmltranslator/DiplodocusSimulatorTest.java +++ b/ttool/src/test/java/tmltranslator/DiplodocusSimulatorTest.java @@ -92,7 +92,7 @@ public class DiplodocusSimulatorTest extends AbstractTest { assertTrue(syntax.hasErrors() == 0); - // Generate SystemC code + // Generate C code System.out.println("executing: sim code gen for " + s); final IDiploSimulatorCodeGenerator tml2systc; List<EBRDD> al = new ArrayList<EBRDD>();