From 05ecf933200fff61d7c5f6d1d39c3c2258025709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Creuse?= Date: Mon, 7 Oct 2024 16:56:47 +0200 Subject: [PATCH] Test: fix processing of aggregate projects 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 c9244a727c0e91a2f2cec0bbf7453ae5407237fe) --- src/test-actions.adb | 16 ++++++++++++++++ testsuite/tests/test/200-aggregates/dep.gpr | 6 ++++++ testsuite/tests/test/200-aggregates/prj.gpr | 3 +++ testsuite/tests/test/200-aggregates/prj1.gpr | 8 ++++++++ testsuite/tests/test/200-aggregates/prj2.gpr | 8 ++++++++ testsuite/tests/test/200-aggregates/src1/pkg.adb | 7 +++++++ testsuite/tests/test/200-aggregates/src1/pkg.ads | 5 +++++ testsuite/tests/test/200-aggregates/src2/pkh.adb | 7 +++++++ testsuite/tests/test/200-aggregates/src2/pkh.ads | 5 +++++ .../tests/test/200-aggregates/src_dep/dep.adb | 5 +++++ .../tests/test/200-aggregates/src_dep/dep.ads | 5 +++++ testsuite/tests/test/200-aggregates/test.out | 0 testsuite/tests/test/200-aggregates/test.sh | 10 ++++++++++ testsuite/tests/test/200-aggregates/test.yaml | 5 +++++ 14 files changed, 90 insertions(+) create mode 100644 testsuite/tests/test/200-aggregates/dep.gpr create mode 100644 testsuite/tests/test/200-aggregates/prj.gpr create mode 100644 testsuite/tests/test/200-aggregates/prj1.gpr create mode 100644 testsuite/tests/test/200-aggregates/prj2.gpr create mode 100644 testsuite/tests/test/200-aggregates/src1/pkg.adb create mode 100644 testsuite/tests/test/200-aggregates/src1/pkg.ads create mode 100644 testsuite/tests/test/200-aggregates/src2/pkh.adb create mode 100644 testsuite/tests/test/200-aggregates/src2/pkh.ads create mode 100644 testsuite/tests/test/200-aggregates/src_dep/dep.adb create mode 100644 testsuite/tests/test/200-aggregates/src_dep/dep.ads create mode 100644 testsuite/tests/test/200-aggregates/test.out create mode 100644 testsuite/tests/test/200-aggregates/test.sh create mode 100644 testsuite/tests/test/200-aggregates/test.yaml diff --git a/src/test-actions.adb b/src/test-actions.adb index 0c0b3871c..9c8472a7f 100644 --- a/src/test-actions.adb +++ b/src/test-actions.adb @@ -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 @@ -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 diff --git a/testsuite/tests/test/200-aggregates/dep.gpr b/testsuite/tests/test/200-aggregates/dep.gpr new file mode 100644 index 000000000..79e9942b1 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/dep.gpr @@ -0,0 +1,6 @@ +project Dep is + + for Object_Dir use "obj_dep"; + for Source_Dirs use ("src_dep"); + +end Dep; diff --git a/testsuite/tests/test/200-aggregates/prj.gpr b/testsuite/tests/test/200-aggregates/prj.gpr new file mode 100644 index 000000000..cd7150bdd --- /dev/null +++ b/testsuite/tests/test/200-aggregates/prj.gpr @@ -0,0 +1,3 @@ +aggregate project Prj is + for Project_Files use ("prj1.gpr", "prj2.gpr"); +end Prj; diff --git a/testsuite/tests/test/200-aggregates/prj1.gpr b/testsuite/tests/test/200-aggregates/prj1.gpr new file mode 100644 index 000000000..0cad09574 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/prj1.gpr @@ -0,0 +1,8 @@ +with "dep.gpr"; + +project Prj1 is + + for Object_Dir use "obj1"; + for Source_Dirs use ("src1"); + +end Prj1; diff --git a/testsuite/tests/test/200-aggregates/prj2.gpr b/testsuite/tests/test/200-aggregates/prj2.gpr new file mode 100644 index 000000000..3652fde0c --- /dev/null +++ b/testsuite/tests/test/200-aggregates/prj2.gpr @@ -0,0 +1,8 @@ +with "dep.gpr"; + +project Prj2 is + + for Object_Dir use "obj2"; + for Source_Dirs use ("src2"); + +end Prj2; diff --git a/testsuite/tests/test/200-aggregates/src1/pkg.adb b/testsuite/tests/test/200-aggregates/src1/pkg.adb new file mode 100644 index 000000000..e13c21be6 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src1/pkg.adb @@ -0,0 +1,7 @@ +with Dep; + +package body Pkg is + + function Foo (X : Integer) return Integer is (Dep.Baz (X)); + +end Pkg; diff --git a/testsuite/tests/test/200-aggregates/src1/pkg.ads b/testsuite/tests/test/200-aggregates/src1/pkg.ads new file mode 100644 index 000000000..a608851f6 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src1/pkg.ads @@ -0,0 +1,5 @@ +package Pkg is + + function Foo (X : Integer) return Integer; + +end Pkg; diff --git a/testsuite/tests/test/200-aggregates/src2/pkh.adb b/testsuite/tests/test/200-aggregates/src2/pkh.adb new file mode 100644 index 000000000..bea2bf145 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src2/pkh.adb @@ -0,0 +1,7 @@ +with Dep; + +package body Pkh is + + function Bar (X : Integer) return Integer is (Dep.Baz (X)); + +end Pkh; diff --git a/testsuite/tests/test/200-aggregates/src2/pkh.ads b/testsuite/tests/test/200-aggregates/src2/pkh.ads new file mode 100644 index 000000000..6bb9c9d2d --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src2/pkh.ads @@ -0,0 +1,5 @@ +package Pkh is + + function Bar (X : Integer) return Integer; + +end Pkh; diff --git a/testsuite/tests/test/200-aggregates/src_dep/dep.adb b/testsuite/tests/test/200-aggregates/src_dep/dep.adb new file mode 100644 index 000000000..81d44798f --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src_dep/dep.adb @@ -0,0 +1,5 @@ +package body Dep is + + function Baz (X : Integer) return Integer is (X); + +end Dep; diff --git a/testsuite/tests/test/200-aggregates/src_dep/dep.ads b/testsuite/tests/test/200-aggregates/src_dep/dep.ads new file mode 100644 index 000000000..e75aa1b97 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/src_dep/dep.ads @@ -0,0 +1,5 @@ +package Dep is + + function Baz (X : Integer) return Integer; + +end Dep; diff --git a/testsuite/tests/test/200-aggregates/test.out b/testsuite/tests/test/200-aggregates/test.out new file mode 100644 index 000000000..e69de29bb diff --git a/testsuite/tests/test/200-aggregates/test.sh b/testsuite/tests/test/200-aggregates/test.sh new file mode 100644 index 000000000..12ba3b5bd --- /dev/null +++ b/testsuite/tests/test/200-aggregates/test.sh @@ -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 diff --git a/testsuite/tests/test/200-aggregates/test.yaml b/testsuite/tests/test/200-aggregates/test.yaml new file mode 100644 index 000000000..84484d9a5 --- /dev/null +++ b/testsuite/tests/test/200-aggregates/test.yaml @@ -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