@@ -926,10 +926,54 @@ The tool currently has the following limitations:
926
926
927
927
.. _Automatic_testcase_generation :
928
928
929
- Automatically generating test cases (alpha )
930
- -------------------------------------------
929
+ Automatically generating test cases (experimental )
930
+ --------------------------------------------------
931
931
932
- ``gnattest `` provides a switch ``--gen-test-vectors `` that can be used to
932
+ Please note that all the features described bellow are experimental, and the
933
+ interface is subject to change.
934
+
935
+ GNATtest has the capability to generate test inputs for subprograms under test.
936
+
937
+ .. _Tgen_Env :
938
+
939
+ Setting up the test generation runtime
940
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
941
+
942
+ Generation of values for Ada cannot be fully done statically, as the bounds of
943
+ some types may only be defined at runtime. As such, the test generation feature
944
+ requires the compilation and installation of a runtime project.
945
+
946
+ The sources for that project are located at
947
+ ``<GNATdas_install_dir/share/tgen/tgen_rts ``.
948
+
949
+ To build the runtime, simply copy the above directory to a location of you
950
+ choice, build the project using ``gprbuild ``, install it using ``gprinstall ``
951
+ and make it available to the tools by referencing it in the ``GPR_PROJECT_PATH ``
952
+ environment variable:
953
+
954
+ .. code-block :: sh
955
+
956
+ # Clean previous source if present
957
+ rm -rf /tmp/tgen_rts_src
958
+
959
+ # Copy the sources
960
+ cp -r < GNATdas_install_dir> /share/tgen/tgen_rts /tmp/tgen_rts_src
961
+
962
+ # Build the project
963
+ cd /tmp/tgen_rts_src
964
+ gprbuild -P tgen_rts.gpr
965
+
966
+ # Install the project (removing the previous one if needed)
967
+ gprinstall --uninstall -P tgen_rts.gpr --prefix=/tmp/tgen_rts_install
968
+ gprinstall -p -P tgen_rts.gpr --prefix=/tmp/tgen_rts_install
969
+
970
+ # Make it available to other tools
971
+ export GPR_PROJECT_PATH=/tmp/tgen_rts_install/share/gpr:$GPR_PROJECT_PATH
972
+
973
+ Generating test inputs
974
+ ^^^^^^^^^^^^^^^^^^^^^^
975
+
976
+ ``gnattest `` provides a ``--gen-test-vectors `` switch that can be used to
933
977
automatically generate test cases for all of the supported subprogram profiles.
934
978
The number of generated test cases can be configured through the
935
979
``--gen-test-num `` switch.
@@ -946,21 +990,39 @@ are true:
946
990
5. Any of the subprogram's "in" or "out" mode parameters is a private type of
947
991
a nested package.
948
992
949
- ..
950
- TODO: document a bit the value generation (mostly random, except for
951
- unconstrained arrays and discriminated record).
993
+ Input value generation currently follows a simple strategy for each input
994
+ parameter of the subprogram under test. Parameters of scalar types, and scalar
995
+ components of composite types have their values uniformly generated. For
996
+ unconstrained array types, a length is randomly chosen between 0 and 10
997
+ elements, then the low bound is randomly chosen and the high bound computed
998
+ accordingly to those two first points.
999
+
1000
+ For record discriminants, different strategies are chosen depending on the use
1001
+ of the discriminant within the record: If the discriminant constraints a array
1002
+ component, then the array strategy described above is used. If the discriminant
1003
+ is used in a variant part, generation will be biased in order to generated all
1004
+ possible shapes of the record (i.e. explore all variants). Otherwise, these are
1005
+ generated as any other scalar component.
1006
+
952
1007
953
1008
The generated test cases are then stored in a ad-hoc (and yet to be specified)
954
- JSON format, in files under the <obj_dir>/gnattest/tests/JSON_Tests directory.
1009
+ JSON format, in files under the `` <obj_dir>/gnattest/tests/JSON_Tests `` directory.
955
1010
The generated JSON files are preserved through a ``gnattest `` rerun. The user is
956
1011
thus free to modify them, to e.g. fill in expected return values, though
957
1012
backward compatibility of the format is not guaranteed at this stage.
958
1013
959
1014
``gnattest `` also generates Ada files to actually execute the test cases. Each test vector
960
1015
has its own AUnit test case, and all test cases for a specific subprogram are all
961
1016
stored in a dedicated file, namely
962
- <unit_name>-test_data-test_<subp_name>_<subp_hash>.ad[bs]. The content of these
963
- files is not preserved through a ``gnattest `` rerun.
1017
+ ``<unit_name>-test_data-test_<subp_name>_<subp_hash>.ad[bs] ``, where
1018
+ ``<unit_name> `` is the name of the unit in which the subprogram is declared,
1019
+ ``<subp_name> `` is the name of the subprogram, and <subp_hash> is a hash based
1020
+ on the profile of the subprogram, in order to differentiate overloads.
1021
+
1022
+ The content of these files are re-generated each time ``gnattest `` is invoked,
1023
+ independently of the presence of the ``--gen-test-vectors `` switch on the
1024
+ command line. It is thus not necessary to re-invoke ``gnattest `` with that
1025
+ switch more than once, unless the goal is to generate additional test inputs.
964
1026
965
1027
..
966
1028
TODO: document the --unparse switch
0 commit comments