Skip to content

Commit

Permalink
Test: fix processing of aggregate projects
Browse files Browse the repository at this point in the history
The laltools framework supports aggregate projects in the sense
that they will be processed sequentially, invoking the tool in a
subprocess on each of the aggregated projects. It also however calls
the Init and Final tool methods on the aggregate project itself, which
is not necessary in gnattest's case, and even used to lead to a crash due
to call to GNATCOLL.Project primitives that were illegal on aggregate projects.

This fixes the crash by skipping the Init and Final call of the test tool when
the aggregate project is being processed.

(cherry picked from commit c9244a7)
  • Loading branch information
leocreuse committed Dec 16, 2024
1 parent f001c31 commit 05ecf93
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test-actions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ package body Test.Actions is
Test.Common.Verbose := Arg (Cmd, Verbose);
Test.Common.Quiet := Arg (Cmd, Quiet);

-- If the tool project is an aggregate one, exit early and do nothing.
-- The aggregated projects will be processed in sequence in subprocess
-- calls made by the driver.

if Tool.Project_Tree.Root_Project.Is_Aggregate_Project then
return;
end if;

Test.Common.Instrument := Arg (Cmd, Dump_Test_Inputs);

if Arg (Cmd, Passed_Tests) /= null then
Expand Down Expand Up @@ -1007,6 +1015,14 @@ package body Test.Actions is
Tool.Project_Tree.Root_Project.Project_Path.Display_Full_Name;
begin

-- If the tool project is an aggregate one, exit early and do nothing.
-- The aggregated projects will be processed in sequence in subprocess
-- calls made by the driver.

if Tool.Project_Tree.Root_Project.Is_Aggregate_Project then
return;
end if;

-- In any case, generate the support library if needed

if Test.Common.Get_Lib_Support_Status in Test.Common.Needed then
Expand Down
6 changes: 6 additions & 0 deletions testsuite/tests/test/200-aggregates/dep.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project Dep is

for Object_Dir use "obj_dep";
for Source_Dirs use ("src_dep");

end Dep;
3 changes: 3 additions & 0 deletions testsuite/tests/test/200-aggregates/prj.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
aggregate project Prj is
for Project_Files use ("prj1.gpr", "prj2.gpr");
end Prj;
8 changes: 8 additions & 0 deletions testsuite/tests/test/200-aggregates/prj1.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
with "dep.gpr";

project Prj1 is

for Object_Dir use "obj1";
for Source_Dirs use ("src1");

end Prj1;
8 changes: 8 additions & 0 deletions testsuite/tests/test/200-aggregates/prj2.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
with "dep.gpr";

project Prj2 is

for Object_Dir use "obj2";
for Source_Dirs use ("src2");

end Prj2;
7 changes: 7 additions & 0 deletions testsuite/tests/test/200-aggregates/src1/pkg.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
with Dep;

package body Pkg is

function Foo (X : Integer) return Integer is (Dep.Baz (X));

end Pkg;
5 changes: 5 additions & 0 deletions testsuite/tests/test/200-aggregates/src1/pkg.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Pkg is

function Foo (X : Integer) return Integer;

end Pkg;
7 changes: 7 additions & 0 deletions testsuite/tests/test/200-aggregates/src2/pkh.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
with Dep;

package body Pkh is

function Bar (X : Integer) return Integer is (Dep.Baz (X));

end Pkh;
5 changes: 5 additions & 0 deletions testsuite/tests/test/200-aggregates/src2/pkh.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Pkh is

function Bar (X : Integer) return Integer;

end Pkh;
5 changes: 5 additions & 0 deletions testsuite/tests/test/200-aggregates/src_dep/dep.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package body Dep is

function Baz (X : Integer) return Integer is (X);

end Dep;
5 changes: 5 additions & 0 deletions testsuite/tests/test/200-aggregates/src_dep/dep.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Dep is

function Baz (X : Integer) return Integer;

end Dep;
Empty file.
10 changes: 10 additions & 0 deletions testsuite/tests/test/200-aggregates/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash

# First, run gnattest in stub mode, with tests placed in source subdirectories,
# and stubs in the object dir of the stubbed project.
gnattest -P prj.gpr --stub --subdirs=test --stubs-dir=stub -q

# The build both test driver aggregate projects, to ensure the generated
# harnesses are valid.
gprbuild -q obj1/gnattest_stub/harness/test_drivers.gpr
gprbuild -q obj2/gnattest_stub/harness/test_drivers.gpr
5 changes: 5 additions & 0 deletions testsuite/tests/test/200-aggregates/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description:
Test that gnattest does not crash when processing an aggregate project,
and that they are processed in sequence, producing two valid harnesses.

driver: shell_script

0 comments on commit 05ecf93

Please sign in to comment.