@@ -19,7 +19,9 @@ with Ada.Command_Line;
19
19
with Ada.Directories ;
20
20
with Ada.Text_IO ;
21
21
with Ada.Strings.Unbounded ; use Ada.Strings.Unbounded;
22
- with GNAT.OS_Lib ;
22
+ with GNAT.OS_Lib ; use GNAT.OS_Lib;
23
+
24
+ with GNATCOLL.Utils ; use GNATCOLL.Utils;
23
25
24
26
with Spawn.Processes.Monitor_Loop ;
25
27
@@ -31,8 +33,7 @@ package body Tester.Tests is
31
33
type Command_Kind is (Start, Stop, Send, Comment);
32
34
33
35
procedure Do_Start
34
- (Self : in out Test'Class;
35
- Command : GNATCOLL.JSON.JSON_Value);
36
+ (Self : in out Test'Class);
36
37
37
38
procedure Do_Stop
38
39
(Self : in out Test'Class;
@@ -42,15 +43,20 @@ package body Tester.Tests is
42
43
(Self : in out Test'Class;
43
44
Command : GNATCOLL.JSON.JSON_Value);
44
45
45
- Is_Windows : constant Boolean := GNAT.OS_Lib.Directory_Separator = ' \' ;
46
+ function Wait_Factor return Integer;
47
+ -- Return the factor to multiply the delays with - useful for valgrind
48
+ -- runs. This is an integer read from the environment variable
49
+ -- $ALS_WAIT_FACTOR if it is defined.
50
+
51
+ Is_Windows : constant Boolean := Directory_Separator = ' \' ;
46
52
47
53
-- ------------
48
54
-- Do_Abort --
49
55
-- ------------
50
56
51
57
procedure Do_Abort (Self : Test) is
52
58
begin
53
- GNAT.OS_Lib. OS_Exit (1 );
59
+ OS_Exit (1 );
54
60
end Do_Abort ;
55
61
56
62
-- -----------
@@ -98,7 +104,7 @@ package body Tester.Tests is
98
104
exit when GNATCOLL.JSON.Length (Self.Waits) = 0 ;
99
105
100
106
Total_Milliseconds_Waited := Total_Milliseconds_Waited + Timeout;
101
- if Total_Milliseconds_Waited > Max_Wait then
107
+ if Total_Milliseconds_Waited > Max_Wait * Wait_Factor then
102
108
declare
103
109
Text : Spawn.String_Vectors.UTF_8_String_Vector;
104
110
begin
@@ -126,8 +132,7 @@ package body Tester.Tests is
126
132
-- ------------
127
133
128
134
procedure Do_Start
129
- (Self : in out Test'Class;
130
- Command : GNATCOLL.JSON.JSON_Value)
135
+ (Self : in out Test'Class)
131
136
is
132
137
function Program_Name (Path : String) return String;
133
138
-- Return full path to an exacutable designated by Path
@@ -138,21 +143,34 @@ package body Tester.Tests is
138
143
139
144
function Program_Name (Path : String) return String is
140
145
begin
141
- if Is_Windows then
146
+ if Is_Windows
147
+ and then not Ends_With (Path, " .exe" )
148
+ then
142
149
return Ada.Directories.Full_Name (Path & " .exe" );
143
150
else
144
151
return Ada.Directories.Full_Name (Path);
145
152
end if ;
146
153
end Program_Name ;
147
154
148
- Cmd : constant GNATCOLL.JSON.JSON_Array := Command.Get (" cmd" );
155
+ Command_Line : constant GNAT.OS_Lib.String_Access := Getenv (" ALS" );
156
+
149
157
Args : Spawn.String_Vectors.UTF_8_String_Vector;
150
158
begin
151
- for J in 2 .. GNATCOLL.JSON.Length (Cmd) loop
152
- Args.Append (GNATCOLL.JSON.Get (Cmd, J).Get);
153
- end loop ;
159
+ if Command_Line = null or else Command_Line.all = " " then
160
+ raise Program_Error with " You must specify the command line in $ALS" ;
161
+ end if ;
162
+
163
+ declare
164
+ Splits : constant Unbounded_String_Array :=
165
+ Split (Command_Line.all , ' ' );
166
+ begin
167
+ Self.Set_Program (Program_Name (To_String (Splits (Splits'First))));
168
+
169
+ for J in Splits'First + 1 .. Splits'Last loop
170
+ Args.Append (To_String (Splits (J)));
171
+ end loop ;
172
+ end ;
154
173
155
- Self.Set_Program (Program_Name (GNATCOLL.JSON.Get (Cmd, 1 ).Get));
156
174
Self.Set_Arguments (Args);
157
175
Self.Start;
158
176
@@ -442,7 +460,7 @@ package body Tester.Tests is
442
460
443
461
case Kind is
444
462
when Start =>
445
- Self.Do_Start (Value) ;
463
+ Self.Do_Start;
446
464
when Stop =>
447
465
Self.Do_Stop (Value);
448
466
when Send =>
@@ -461,11 +479,11 @@ package body Tester.Tests is
461
479
select
462
480
accept Cancel;
463
481
or
464
- delay 2.0 ;
482
+ delay 20.0 * Wait_Factor ;
465
483
466
484
Ada.Text_IO.Put_Line (" Timeout on command:" );
467
485
Ada.Text_IO.Put_Line (Command.Write);
468
- GNAT.OS_Lib. OS_Exit (1 );
486
+ OS_Exit (1 );
469
487
end select ;
470
488
end Watch_Dog ;
471
489
@@ -494,4 +512,19 @@ package body Tester.Tests is
494
512
end loop ;
495
513
end Run ;
496
514
515
+ -- ---------------
516
+ -- Wait_Factor --
517
+ -- ---------------
518
+
519
+ function Wait_Factor return Integer is
520
+ Factor : constant GNAT.OS_Lib.String_Access
521
+ := Getenv (" ALS_WAIT_FACTOR" );
522
+ begin
523
+ if Factor = null or else Factor.all = " " then
524
+ return 1 ;
525
+ else
526
+ return Integer'Value (Factor.all );
527
+ end if ;
528
+ end Wait_Factor ;
529
+
497
530
end Tester.Tests ;
0 commit comments