2

What command do I have to give to gnattest to make it only consider the code in my src directory (and ignore all subprojects such as the Ada Drivers Library)?

I've read this question, which says to tag every subprogram I want to test with the 'Test_Case' aspect. I'll go that route if I have to but I'd like the protection of gnattest automatically adding new test cases for new code so that I don't miss anything.

Here's my gpr file:

with "c:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\microbit_zfp.gpr";

project Demo_Project is

   for Runtime ("ada") use Microbit_Zfp'Runtime ("Ada");
   for Target use "arm-eabi";
   for Main use ("main.adb");
   for Languages use ("Ada");
   for Source_Dirs use ("src");
   for Object_Dir use "obj";
   for Create_Missing_Dirs use "True";

   package Compiler renames Microbit_Zfp.Compiler;

   package Linker is
      for Default_Switches ("ada") use Microbit_Zfp.Linker_Switches & ("-Wl,--print-memory-usage", "-Wl,--gc-sections", "-U__gnat_irq_trap");
   end Linker;

   package Ide is
      for Program_Host use ":1234";
      for Communication_Protocol use "remote";
      for Connection_Tool use "pyocd";
   end Ide;

   package Prove is
   for Proof_Switches ("Ada") use ("-j0");
end Prove;

   package Builder is
      for Switches ("ada") use ("-j0", "-s");
   end Builder;

end Demo_Project;

Here's the gnattest command that GPS created (which incorrectly created tests for the ada drivers library):

arm-eabi-gnat test -Pdemo_project.gpr --tests-dir=C:\Domains\ada\demo_project\microbit\tests

Update: 2019-12-17:

Here's what I got when I ran the suggested answer:

>c:\GNAT\2019\bin\gnattest -Pdemo_project.gpr --tests-dir=tests

Could not locate exec arm-eabi-gnatls
gprconfig: can't find a toolchain for the following configuration:
gprconfig: language 'ada', target 'arm-eabi', runtime 'zfp-cortex-m0'
microbit_zfp.gpr:61:25: warning: libraries are not supported on this platform

object path not found for runtime zfp-cortex-m0
gnattest: initialization failed

Update: 2019-12-17 (2):

I made some progress by adding the "--test-case-only" flag like so and adding a test_case aspect to a single procedure in the Battery package. Here's the command I ran:

arm-eabi-gnat test -dd -PC:\Domains\ada\Demo_Project\microbit\demo_project.gpr --tests-dir=C:\Domains\ada\Demo_Project\tests --test-case-only

Gnattest was successful. I can see my Battery package in the project view for the tests. However, when I try to build and run it from GPS, I get this mess:

gprbuild --target=arm-eabi -d -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr -XADL_BUILD_CHECKS=Enabled -XADL_BUILD=Debug -XTEST_DRIVER_BUILD_MODE=no-config-file C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_runner.adb -largs -Wl,-Map=map.txt
Compile
   [Ada]          test_runner.adb
   [Ada]          gnattest_main_suite.adb
   [Ada]          battery-test_data.adb
   [Ada]          battery-test_data-tests.adb
battery-test_data-tests.adb:40:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:40:13: warning: this handler can never be entered, and has been removed
battery-test_data-tests.adb:53:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:53:13: warning: this handler can never be entered, and has been removed
   [Ada]          battery-test_data-tests-suite.adb
   [Ada]          gnattest_generated.ads
Bind
   [gprbind]      test_runner.bexch
   [Ada]          test_runner.ali
Link
   [link]         test_runner.adb
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a(crt0.o): in function `hang':
(.text+0x40): undefined reference to `__stack_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x48): undefined reference to `__data_words'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x4c): undefined reference to `__data_load'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: (.text+0x54): undefined reference to `__bss_words'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a(crt0.o): in function `__vectors':
(.vectors+0x0): undefined reference to `__stack_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a(s-memory.o): in function `__gnat_malloc':
s-memory.adb:(.text.__gnat_malloc+0x40): undefined reference to `__heap_end'
c:/gnat/2019-arm-elf/bin/../lib/gcc/arm-eabi/7.4.1/../../../../arm-eabi/bin/ld.exe: C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a(s-memory.o):(.data.system__memory__top+0x0): undefined reference to `__heap_start'
collect2.exe: error: ld returned 1 exit status
gprbuild: link of test_runner.adb failed
gprbuild: failed command was: c:\gnat\2019-arm-elf\bin\arm-eabi-gcc.exe test_runner.o b__test_runner.o C:\Domains\ada\Demo_Project\microbit\obj\battery.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\gnattest_generated.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data-tests.o C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\battery-test_data-tests-suite.o C:\Domains\
ada\Demo_Project\microbit\obj\gnattest\harness\gnattest_main_suite.o C:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\obj\zfp_lib_Debug\libada_drivers_library.a C:\gnat\2019-arm-elf\arm-eabi\zfp-cortex-m0\lib\aunit\libaunit.a -g -Wl,-Map=map.txt -LC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\ -LC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\ -LC:\gnat\2019-arm-elf\arm-eabi\zfp-cortex-m0\lib\aunit\ -LC:\Domains\ada\Demo_Project\microbit\obj\ -LC:\Domains\ada\Ada_Drive
rs_Library\boards\MicroBit\obj\zfp_lib_Debug\ -LC:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\ -static-libgcc C:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\adalib\libgnat.a -Wl,-LC:\gnat\2019-arm-elf\arm-eabi\lib\gnat\zfp-cortex-m0\/adalib -nostartfiles -nolibc -mlittle-endian -mthumb -msoft-float -mcpu=cortex-m0 -o test_runner
[2019-12-17 10:47:38] process exited with status 4, 100% (174/174), elapsed time: 03.00s
Traceback (most recent call last):
  File "C:\GNAT\2019\share\gps\support\ui\workflows\__init__.py", line 351, in internal_run_as_wf
    r = workflow(*args, **kwargs)
  File "C:\GNAT\2019\share\gps\plug-ins\memory_usage_providers\ld.py", line 242, in async_fetch_memory_usage_data
    visitor.on_memory_usage_data_fetched(regions, sections, modules)
GPS.Unexpected_Exception: unexpected internal exception raised CONSTRAINT_ERROR : Memory_Usage_Views.Memory_Region_Description_Maps.Reference: key not in map
[C:\GNAT\2019\bin\gps.exe]
0x21a541b
0x197c5b5
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7d79bc at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7d8b16 at ???
[C:\GNAT\2019\bin\gps.python27\python27.dll]
0x1e0c3d54
0x1e113eb9
0x1e114778
0x1e117ee2
0x1e119780
0x1e0b5831
0x1e08dae3
0x1e1141cb
0x1e117fbd
0x1e119780
0x1e0b5831
0x1e08dae3
0x1e09bfcf
0x1e08dae3
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e459f at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e55e0 at ???
[C:\GNAT\2019\bin\gps.libgnatcoll_python\libgnatcoll_python.dll]
0xc7e5833 at ???
[C:\GNAT\2019\bin\gps.libgnatcoll\libgnatcoll.dll]
0xc08dbb4 at ???
[C:\GNAT\2019\bin\gps.exe]
0x197ecf7
0x1975d5f
0x10687c2
0x14ba66a
0x145cc61
0x15e0780
0xfcfa72
0x10b4114
0x10b4672
0x10b7893
0x10b7cf7
0xe30b4c
0xe31022
0xe2deaa
[C:\GNAT\2019\bin\gps.libglib-2.0-0\libglib-2.0-0.dll]
g_timeout_dispatch at gmain.c:4545
g_main_context_dispatch at gmain.c:3122
g_main_context_iterate.isra.10 at gmain.c:3808
g_main_context_iteration at gmain.c:3869
[C:\GNAT\2019\bin\gps.libgio-2.0-0\libgio-2.0-0.dll]
g_application_run at gapplication.c:2308
[C:\GNAT\2019\bin\gps.exe]
0x425199
0x2150c58
0x4013f6
0x4014e9
[C:\windows\system32\kernel32.dll]
0x7768556b
[C:\windows\SYSTEM32\ntdll.dll]
0x777e372b

Build error. [workflow stopped]

There are three problems:

  1. the autogenerated test code wants to throw exceptions but my project doesn't allow them.
  2. I don't understand any of the output after that.
  3. And I don't really understand how the gpr files work. I'm sure there's a magic incantation I can type there and get this sorted out but I've been googling and trying things for a whole day and I'm stuck.

FYI: I'm running the 2019 community versions of gnat, the ARM cross-compiler, and GPS on windows 7.

Update: 2019-12-18:

I've made some progress but it's still not working correctly. I edited the test_driver.gpr as Fabien suggested. I had to comment out the original linker package because it wouldn't work with two of them in the file.

test_driver.gpr now looks like this:

with "test_demo_project.gpr";
with "gnattest_common.gpr";
with "c:\Domains\ada\Ada_Drivers_Library\boards\MicroBit\microbit_zfp.gpr";

project Test_Driver is

   for Origin_Project use "..\..\..\demo_project.gpr";

   for Target use Gnattest_Common'Target;

   for Runtime ("Ada") use Gnattest_Common'Runtime ("Ada");

   for Languages use ("Ada", "ASM_CPP");
   for Main use ("test_runner.adb");
   for Exec_Dir use ".";

   package Builder renames Gnattest_Common.Builder;
   --  package Linker renames Gnattest_Common.Linker;

   package Linker is
   for Default_Switches ("Ada") use MicroBit_ZFP.Linker_Switches &
                                    ("-Wl,--print-memory-usage",
                                     "-Wl,--gc-sections");
   end Linker;

   package Binder renames Gnattest_Common.Binder;
   package Compiler renames Gnattest_Common.Compiler;

   package Ide renames test_demo_project.Ide;

   package GNATtest is
      for GNATTest_Mapping_File use "gnattest.xml";
   end GNATtest;

end Test_Driver;

It doesn't fix the problem with test cases being generated for the ada drivers library but I can live with running gnattest with the "--test-case-only" flag, which largely accomplishes my goal.

But when I build the project it complains about the "ASM_CPP" language and the use of assertions. See below:

gprbuild --target=arm-eabi -d -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr -XADL_BUILD_CHECKS=Enabled -XADL_BUILD=Debug -XTEST_DRIVER_BUILD_MODE=no-config-file -largs -Wl,-Map=map.txt
test_driver.gpr:5:09: warning: there are no sources of language "ASM_CPP" in this project
Compile
   [Ada]          battery-test_data-tests.adb
battery-test_data-tests.adb:40:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:40:13: warning: this handler can never be entered, and has been removed
battery-test_data-tests.adb:53:13: warning: pragma Restrictions (No_Exception_Propagation) in effect
battery-test_data-tests.adb:53:13: warning: this handler can never be entered, and has been removed
Bind
   [gprbind]      test_runner.bexch
   [Ada]          test_runner.ali
Link
   [link]         test_runner.adb
Memory region         Used Size  Region Size  %age Used
           flash:       21668 B       256 KB      8.27%
             ram:        3056 B        16 KB     18.65%
[2019-12-19 08:39:18] process terminated successfully, elapsed time: 02.08s
[2019-12-19 08:39:21] The selected rows in the Locations view cannot be exported, please select files and/or categories.

I tried removing the "ASM_CPP" text and the warning goes away. I don't know now to remove the warnings about the use of exceptions.

When I run my tests I get this:

arm-eabi-gnatemu -PC:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_driver.gpr C:\Domains\ada\Demo_Project\microbit\obj\gnattest\harness\test_runner
[2019-12-19 08:40:01] process terminated successfully, elapsed time: 00.66s

I get the same output when I make my tests fail or pass. Is the warning about the use of exceptions causing the compiler to remove them, which breaks the tests? What do I have to do allow exceptions in my tests?

Blaine Osepchuk
  • 1,067
  • 1
  • 9
  • 17

2 Answers2

3

The question you linked is about testing only a few subprograms, not all the sources in one project, which should be as easy as:

gnattest -Pproject.gpr

You can specify one or more specific files:

gnattest -Pproject.gpr file1.ads file2.ads


Just avoid -r, and you should be fine:

-r Consider recursively all sources from all projects

egilhh
  • 6,464
  • 1
  • 18
  • 19
  • I edited the question to include the command I originally ran and the results of the command you suggested, which threw an error. It looks like I can't use your suggested command because I'm compiling for ARM. Thoughts? – Blaine Osepchuk Dec 17 '19 at 15:12
  • yeah, gnatttest is for native development, for cross-compilation to ARM, you should use arm-eabi-gnattest, as in your edit – egilhh Dec 17 '19 at 15:20
  • Any thoughts on a way forward? I ran arm-eabi-gnat test to create a test for a single file from my project. That created successfully but it throws an error when I try to build it. – Blaine Osepchuk Dec 17 '19 at 15:40
0

The compilation errors in your last update seems to show that you did not specify the linker script and startup code.

Those are provided in Ada Drivers Library in the project file boards/MicroBit/microbit_zfp.gpr.

So you first have to "with" this project from the test_driver.gpr project, and then add those lines to the test_driver.gpr project:

package Linker is
   for Default_Switches ("Ada") use MicroBit_ZFP.Linker_Switches &
                                    ("-Wl,--print-memory-usage",
                                     "-Wl,--gc-sections");
end Linker;

You also have to add assembly in the list of languages in test_driver.gpr:

for Languages use ("Ada", "ASM_CPP");
  • Thanks for your suggestions. I got a little closer to getting it to work but I'm not there yet. I added a 2019-12-18 update to the bottom of my question with the results of your suggested changes. I want to be respectful of your time here. So if digging deeper into this issue is more work than you want, I'll understand if you opt out (just leave a comment here so I know). I don't have time to read the docs and solve this on my own right now. But I can create my own informal tests relatively quickly. It's not my ideal solution but it will work without additional assistance. – Blaine Osepchuk Dec 19 '19 at 16:14
  • GNATemulator (arm-eabi-gnatemu) doesn't simulate the micro:bit, you should run your executable on the real board. The tests output will be sent to the serial over USB connection. – Fabien Chouteau Dec 20 '19 at 19:13
  • Thanks. I'll look into how to do that when I get a chance. – Blaine Osepchuk Dec 20 '19 at 22:23