ocarina-backends-execution_tests.ads 8.21 KB
Newer Older
1 2 3 4
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
jhugues's avatar
jhugues committed
5
--     O C A R I N A . B A C K E N D S . E X E C U T I O N _ T E S T S      --
6 7 8
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--       Copyright (C) 2009 Telecom ParisTech, 2010-2015 ESA & ISAE.        --
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
--                                                                          --
------------------------------------------------------------------------------

with System;

with GNAT.OS_Lib;
with GNAT.Expect;
with GNAT.Regpat;

with Ada.Strings.Unbounded;
with Ada.Unchecked_Deallocation;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;

with Ocarina.Backends.Properties;

package Ocarina.Backends.Execution_Tests is

   use GNAT.OS_Lib;
   use GNAT.Expect;
   use GNAT.Regpat;
   use Ada.Containers;
   use Ocarina.Backends.Properties;

53
   package String_String_Maps is new Ada.Containers.Indefinite_Hashed_Maps
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
     (String,
      String,
      Ada.Strings.Hash,
      Equivalent_Keys => "=");
   --  Define a package to create hashed maps between string and string.
   --  this one is needed to associate referencial file names to applications

   procedure Init;
   --  Initialize this package, looking for simulator path
   --  This function should always be called before any operations

   procedure Reset;
   --  Free all ressources allocated by this package

   procedure Launch_Test
     (Fd      : out GNAT.Expect.Process_Descriptor;
70 71 72
      Command :     String;
      Arch    :     Supported_Execution_Platform;
      Timeout :     Natural);
73 74 75 76 77 78 79
   --  Used to launch the test-program on a specific envoronnement
   --  with specific arguments (invokes Non_Blocking_Spawn)

   function No_Regression
     (Trace    : Ada.Strings.Unbounded.Unbounded_String;
      Ref      : Ada.Strings.Unbounded.Unbounded_String;
      App      : Name_Id;
80
      Ref_Path : String) return Boolean;
81 82 83 84
   --  The actual oracle function: it compares the trace with the
   --  given referencial

   function Load_Referencial
85
     (File_Path : String) return Ada.Strings.Unbounded.Unbounded_String;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
   --  Loads the referencial from a file and cleans it from unwanted
   --  characters.

   procedure Write_Referencial
     (File_Path : String;
      Ref       : Ada.Strings.Unbounded.Unbounded_String;
      App       : Name_Id);
   --  Write the referencial Ref to a file

   function Execute_Regression_Test
     (Scenario_Dirname : String;
      Ref_Map          : String_String_Maps.Map;
      Timeout          : Natural) return Boolean;
   --  Executes the entire test

   procedure Clean_String_From_Regexp
     (Str    : in out String_Ptr;
103
      Regexp :        Pattern_Matcher);
104 105
   --  Clean a string from Regexp

106
   procedure Clean_String_From_All_Regexp (Str : in out String_Ptr);
107 108
   --  Clean a string from all Regexps

109
   procedure Filter_Line (Line : String; Output_Str : in out String_Ptr);
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
   --  Clean a line from non conventional characters (\r) and from Clean_Regexp
   --  Line         : non filtered raw Line
   --  Clean_Regexp : Regexp used to stip Line from unwanted informations
   --                 such as time measures between brackets
   --  Output_Str   : output result string stripped from regexp

   procedure Filter_Procedure
     (Descriptor : Process_Descriptor'Class;
      Str        : String;
      User_Data  : System.Address);
   --  Called every time a line is read from the standard output of the tested
   --  program.
   --  Descriptor : the process descriptor of the running tested program
   --  Str        : the line read from the standard output
   --  User_Data  : see g-expect.ads for details

   procedure No_Filter_Procedure
     (Descriptor : Process_Descriptor'Class;
      Str        : String;
      User_Data  : System.Address);
   --  Filter function used as a bypass to store the output in User_Data
   --  Descriptor : the process descriptor of the running tested program
   --  Str        : the String read from the standard output
   --  User_Data  : see g-expect.ads for details

   function Execute_Coverage_Test (Timeout : Natural) return Boolean;
   --  Execute a coverage test on the generated application
   --  Scenario_Dirname : the name of the scenario directory
   --  Timeout : the duration (in ms) of the test

   function Tsim_Cmd (Cmd : String) return String;
   --  Formats the command string Cmd into a format understood by TSim.
   --  It just adds ASCII.CR to the end of the string.

   type Unbounded_String_Ptr is
     access all Ada.Strings.Unbounded.Unbounded_String;
   --  Define an access type for Unbounded_String

148 149 150
   type Trace is
     array
       (Positive range <>) of aliased Ada.Strings.Unbounded.Unbounded_String;
151 152 153 154 155
   --  Type for all traces

   type Trace_Ptr is access all Trace;
   --  Access to previous type

156
   procedure Free is new Ada.Unchecked_Deallocation (Trace, Trace_Ptr);
157 158 159 160 161
   --  Deallocation procedure for Trace_Ptr

   All_Traces : Trace_Ptr;
   --  Points to all traces generated from apps executions

162
   Header_Has_Ended : Boolean := True;
163 164 165 166 167
   --  Tells whether header has ended or not this is
   --  explicitly set to False when simulator is Tsim
   --  when Header has ended, then every lines read from
   --  application stdout are added to its trace

168
   Command_Name_Path : String_Ptr;
169 170
   --  The command name path

171
   Scenario_Dir : String_Ptr;
172 173 174 175 176 177
   --  Path to scenario directory

   Create_Referencial : Boolean := False;
   --  Decides if we make a regression test or if we write a referencial
   --  file

178
   Ref_Map : String_String_Maps.Map;
179 180
   --  Map table for referencial files

181
   Timeout : Unsigned_Long_Long;
182 183
   --  Timeout used to stop the testing process

184
   Write_Log : Boolean := True;
185 186
   --  Decides if we should write log files for referencials and traces

yoogx's avatar
yoogx committed
187
   Parse_Regexp : Pattern_Matcher (4 * 1024);
188

yoogx's avatar
yoogx committed
189
   Strip_CR_Regexp : Pattern_Matcher (4 * 1024);
190

yoogx's avatar
yoogx committed
191
   Header_End_Regexp : Pattern_Matcher (4 * 1024);
192 193 194 195 196 197 198 199 200 201 202

   Tsim_Traces_Regexp : Pattern_Matcher (56);

   Empty_Line_Regexp : Pattern_Matcher (20);
   --  Set of Regexp to compare outputs. An additional regexp must be
   --  initialized in Init and called in Clean_String_From_All_Regexp
   --  to be applied.

private
   type Fd_Array is array (Positive range <>) of Process_Descriptor;

203 204 205 206 207
   TSim_ERC32_Path : String_Access;
   TSim_LEON_Path  : String_Access;
   Qemu_Path       : String_Access;
   Qemu_Sparc_Path : String_Access;
   Xcov_Path       : String_Access;
208 209

end Ocarina.Backends.Execution_Tests;