Skip to content

Commit 9970963

Browse files
committed
Merge branch 'leo/46-delta_aggr' into 'master'
Add test verifying delta aggregate support See merge request eng/cov/gnatcoverage!236 Closes eng/cov/gnatcoverage!46
2 parents b2382e8 + 9789e7b commit 9970963

File tree

12 files changed

+268
-0
lines changed

12 files changed

+268
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pragma Ada_2022;
2+
3+
package body Pkg is
4+
5+
--------------------------
6+
-- Copy_With_Abs_Update --
7+
--------------------------
8+
9+
function Copy_With_Abs_Update
10+
(Input : Composite;
11+
Item : Item_Type;
12+
Use_Cache : Boolean := False) return Composite
13+
is
14+
Elem : integer renames -- # st
15+
Input (if Item = First then 1 else 2); -- # comp_expr
16+
begin
17+
return -- # st
18+
[(if Use_Cache then Cached_Comp else Input) with delta -- # base_expr_first
19+
(if Item = First then 1 else 2) => -- # comp_expr
20+
(if Elem >= 0 then Elem else -Elem)]; -- # value_expr_first
21+
end Copy_With_Abs_Update;
22+
end Pkg;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
pragma Ada_2012;
2+
3+
package Pkg is
4+
5+
type Item_Type is (First, Last);
6+
7+
type Composite is private;
8+
9+
Cached_Comp : constant Composite;
10+
11+
function Make (First, Last : Integer) return Composite;
12+
13+
function Eq (Comp : Composite; First, Last : Integer) return Boolean;
14+
15+
function Copy_With_Abs_Update
16+
(Input : Composite;
17+
Item : Item_Type;
18+
Use_Cache : Boolean := False) return Composite;
19+
-- Return a copy of Input or Cached_Comp depending on the value of
20+
-- Use_Cache, with either the "First" or "Last" component being updated to
21+
-- its absolute value.
22+
private
23+
type Composite is array (1 .. 2) of Integer;
24+
25+
Cached_Comp : constant Composite := (0, 0);
26+
27+
----------
28+
-- Make --
29+
----------
30+
31+
function Make (First, Last : Integer) return Composite is ((First, Last));
32+
33+
--------
34+
-- Eq --
35+
--------
36+
37+
function Eq (Comp : Composite; First, Last : Integer) return Boolean is
38+
(Comp (1) = First and then Comp (2) = Last);
39+
40+
end Pkg;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Test the correct handling and instrumentation of array delta aggregates
3+
"""
4+
5+
from SCOV.tc import TestCase
6+
from SCOV.tctl import CAT
7+
from SUITE.context import thistest
8+
9+
10+
TestCase(category=CAT.decision).run()
11+
thistest.result()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pragma Ada_2022;
2+
3+
package body Pkg is
4+
5+
--------------------------
6+
-- Copy_With_Abs_Update --
7+
--------------------------
8+
9+
function Copy_With_Abs_Update
10+
(Input : Composite;
11+
Item : Item_Type;
12+
Use_Cache : Boolean := False) return Composite
13+
is
14+
Elem : constant integer := -- # st
15+
(if Item = First then Input.First else Input.Last); -- # comp_expr
16+
begin
17+
-- We can't dynamically condition which component is used in a record
18+
-- delta aggregate, so in order to emulate the behavior we need to
19+
-- resort to two separate aggregates. This duplicates some decisions,
20+
-- only one will be covered by the driver meant to exercise the
21+
-- specific part of the aggregate.
22+
23+
return -- # st
24+
((if Item = First -- # comp_expr
25+
then ((if Use_Cache then Cached_Comp else Input) with delta -- # base_expr_first
26+
First => (if Elem >= 0 then Elem else -Elem)) -- # value_expr_first
27+
else ((if Use_Cache then Cached_Comp else Input) with delta -- # base_expr_last
28+
Last => (if Elem >= 0 then Elem else -Elem)))); -- # value_expr_last
29+
end Copy_With_Abs_Update;
30+
end Pkg;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
pragma Ada_2012;
2+
3+
package Pkg is
4+
5+
type Item_Type is (First, Last);
6+
7+
type Composite is private;
8+
9+
Cached_Comp : constant Composite;
10+
11+
function Make (First, Last : Integer) return Composite;
12+
13+
function Eq (Comp : Composite; First, Last : Integer) return Boolean;
14+
15+
function Copy_With_Abs_Update
16+
(Input : Composite;
17+
Item : Item_Type;
18+
Use_Cache : Boolean := False) return Composite;
19+
-- Return a copy of Input or Cached_Comp depending on the value of
20+
-- Use_Cache, with either the "First" or "Last" component being updated to
21+
-- its absolute value.
22+
private
23+
type Composite is record
24+
First : Integer;
25+
Last : Integer;
26+
end record;
27+
28+
Cached_Comp : constant Composite := (0, 0);
29+
30+
----------
31+
-- Make --
32+
----------
33+
34+
function Make (First, Last : Integer) return Composite is ((First, Last));
35+
36+
--------
37+
-- Eq --
38+
--------
39+
40+
function Eq (Comp : Composite; First, Last : Integer) return Boolean is
41+
(Comp.First = First and then Comp.Last = Last);
42+
43+
end Pkg;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Test the correct handling and instrumentation of record delta aggregates
3+
"""
4+
5+
from SCOV.tc import TestCase
6+
from SCOV.tctl import CAT
7+
from SUITE.context import thistest
8+
9+
10+
TestCase(category=CAT.decision).run()
11+
thistest.result()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
with Pkg; use Pkg;
2+
3+
procedure Test_Pkg_0 is
4+
begin
5+
null;
6+
end Test_Pkg_0;
7+
8+
--# pkg.adb
9+
--
10+
-- /st/ l- ## s-
11+
-- /base_expr/ l- ## 0
12+
-- /comp_expr/ l- ## 0
13+
-- /value_expr/ l- ## 0
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
with Pkg; use Pkg;
2+
3+
with Support; use Support;
4+
5+
procedure Test_Pkg_Base is
6+
Comp : Composite := Cached_Comp;
7+
begin
8+
Assert (Eq (Copy_With_Abs_Update (Comp, First, True), 0, 0));
9+
Assert (Eq (Copy_With_Abs_Update (Comp, First, False), 0, 0));
10+
end Test_Pkg_Base;
11+
12+
--# pkg.adb
13+
--
14+
-- /st/ l+ ## 0
15+
-- /base_expr_last/ l! ## d-
16+
-- /base_expr_first/ l+ ## 0
17+
-- /comp_expr/ l! ## dF-
18+
-- /value_expr_last/ l! ## d-
19+
-- /value_expr_first/ l! ## dF-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
with Pkg; use Pkg;
2+
3+
with Support; use Support;
4+
5+
procedure Test_Pkg_Comp is
6+
Comp : Composite := Cached_Comp;
7+
begin
8+
Assert (Eq (Copy_With_Abs_Update (Comp, First, False), 0, 0));
9+
Assert (Eq (Copy_With_Abs_Update (Comp, Last, False), 0, 0));
10+
end Test_Pkg_Comp;
11+
12+
--# pkg.adb
13+
--
14+
-- /st/ l+ ## 0
15+
-- /base_expr/ l! ## dT-
16+
-- /comp_expr/ l+ ## 0
17+
-- /value_expr/ l! ## dF-
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
with Pkg; use Pkg;
2+
3+
with Support; use Support;
4+
5+
procedure Test_Pkg_Full is
6+
Comp : Composite := Cached_Comp;
7+
begin
8+
Assert (Eq (Copy_With_Abs_Update (Comp, First, True), 0, 0));
9+
Assert (Eq (Copy_With_Abs_Update (Comp, Last, True), 0, 0));
10+
Assert (Eq (Copy_With_Abs_Update (Comp, First, False), 0, 0));
11+
Assert (Eq (Copy_With_Abs_Update (Comp, Last, False), 0, 0));
12+
Comp := Make (-1, 0);
13+
Assert (Eq (Copy_With_Abs_Update (Comp, First, False), 1, 0));
14+
Comp := Make (0, -1);
15+
Assert (Eq (Copy_With_Abs_Update (Comp, Last, False), 0, 1));
16+
17+
end Test_Pkg_Full;
18+
19+
--# pkg.adb
20+
--
21+
-- /st/ l+ ## 0
22+
-- /base_expr/ l+ ## 0
23+
-- /comp_expr/ l+ ## 0
24+
-- /value_expr/ l+ ## 0

0 commit comments

Comments
 (0)