ocaml/ocamltest
David Allsopp f6279a64b5
Switch the compiler CI builds from Travis to GitHub actions (#10036)
* Switch compiler builds and tests to GitHub actions

* Expose ${cc} in ocamltest

* Allow lib-bigarray-2/bigarrfml.ml to run on 32-bit

* Simplify environment variables passed to scripts

* Reduce matrix to 3 builds

* Move minimum build into Jenkins other-configs
2020-11-24 14:16:31 +01:00
..
.depend Add Ocamltest_stdlib.Unix.has_symlink 2020-07-23 14:55:36 +01:00
Makefile Remove Spacetime 2020-10-08 20:28:12 +02:00
README Fixing typos in various files (#2246) 2019-02-13 14:04:56 +01:00
actions.ml ocamltest: introduce the action_name variable 2019-09-26 17:44:22 +02:00
actions.mli ocamltest: introduce the action_name variable 2019-09-26 17:44:22 +02:00
actions_helpers.ml Remove use of ln -sf from ocamltest 2020-07-23 15:05:00 +01:00
actions_helpers.mli ocamltest: add the asmgen test 2018-04-27 17:51:57 +02:00
builtin_actions.ml Add Ocamltest_stdlib.Unix.has_symlink 2020-07-23 14:55:36 +01:00
builtin_actions.mli Fix ppc64 TOC load for exception handler addresses (#8506) 2019-03-18 13:31:57 +01:00
builtin_variables.ml ocamltest: introduce the MAKE built-in variable 2018-04-19 11:33:36 +02:00
builtin_variables.mli ocamltest: introduce the MAKE built-in variable 2018-04-19 11:33:36 +02:00
dune Modify ocamltest_core_and_plugin dune. (#9843) 2020-09-22 10:27:32 +02:00
environments.ml ocamltest: do not overwrite user-defined variables 2020-06-05 07:40:17 +02:00
environments.mli ocamltest: do not overwrite user-defined variables 2020-06-05 07:40:17 +02:00
filecompare.ml Report a diff for files differing by endings only 2020-07-25 10:36:24 +01:00
filecompare.mli ocamltest: fix "promote" actions on reference files with skipped lines/bytes 2019-09-03 11:43:55 +02:00
getocamloptdefaultflags ocamltest: the test driver for the OCaml compiler 2017-09-18 17:40:14 +02:00
main.ml Remove use of rm -rf from ocamltest 2020-07-23 15:04:49 +01:00
main.mli ocamltest: the test driver for the OCaml compiler 2017-09-18 17:40:14 +02:00
modifier_parser.ml ocamltest: take parsing of response files out of environments module 2019-09-26 17:44:22 +02:00
modifier_parser.mli ocamltest: take parsing of response files out of environments module 2019-09-26 17:44:22 +02:00
ocaml_actions.ml Switch the compiler CI builds from Travis to GitHub actions (#10036) 2020-11-24 14:16:31 +01:00
ocaml_actions.mli ocamltest: do not compare binaries produced by ocamlopt.opt and ocamlopt.byte (#9677) 2020-06-23 17:36:37 +02:00
ocaml_backends.ml ocamltest: complete and clarify support for runtime flags 2018-02-19 09:13:15 +01:00
ocaml_backends.mli ocamltest: complete and clarify support for runtime flags 2018-02-19 09:13:15 +01:00
ocaml_commands.ml stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_commands.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_compilers.ml stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_compilers.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_directories.ml Use Sys.{win32,...} instead Sys.os_type 2020-05-27 19:19:22 +02:00
ocaml_directories.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_files.ml Add the $(EXE) suffix to all programs at build rather than install time 2020-06-18 11:16:55 +02:00
ocaml_files.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_filetypes.ml Whitespace and overlong line fixes. 2018-06-14 15:15:34 +01:00
ocaml_filetypes.mli ocamltest: define a file type for object files 2018-04-17 10:43:24 +02:00
ocaml_flags.ml stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_flags.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_modifiers.ml ocamltest: fix include native dynlink (#9791) 2020-07-23 09:47:03 +02:00
ocaml_modifiers.mli ocamltest: machinery for ocamldoc tests 2018-03-06 11:58:10 +01:00
ocaml_tests.ml Remove Spacetime 2020-10-08 20:28:12 +02:00
ocaml_tests.mli ocamltest: add the asmgen test 2018-04-27 17:51:57 +02:00
ocaml_tools.ml stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_tools.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_toplevels.ml stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_toplevels.mli stop passing the constant ocamlsrcdir to each function 2020-05-27 19:19:22 +02:00
ocaml_variables.ml Switch the compiler CI builds from Travis to GitHub actions (#10036) 2020-11-24 14:16:31 +01:00
ocaml_variables.mli Switch the compiler CI builds from Travis to GitHub actions (#10036) 2020-11-24 14:16:31 +01:00
ocamltest.org ocamltest: draft of reference manual (tutorial section) 2019-11-28 18:04:53 +01:00
ocamltest_config.ml.in Remove Spacetime 2020-10-08 20:28:12 +02:00
ocamltest_config.mli Remove Spacetime 2020-10-08 20:28:12 +02:00
ocamltest_stdlib.ml Fix handling of EOL-at-EOF in ocamltest 2020-07-25 10:04:31 +01:00
ocamltest_stdlib.mli Fix handling of EOL-at-EOF in ocamltest 2020-07-25 10:04:31 +01:00
ocamltest_unix.mli Remove use of ln -sf from ocamltest 2020-07-23 15:05:00 +01:00
ocamltest_unix_dummy.ml Remove use of ln -sf from ocamltest 2020-07-23 15:05:00 +01:00
ocamltest_unix_real.ml Remove use of ln -sf from ocamltest 2020-07-23 15:05:00 +01:00
options.ml Hide references in Options implementation 2020-05-27 19:19:22 +02:00
options.mli Hide references in Options implementation 2020-05-27 19:19:22 +02:00
result.ml ocamltest: introduce the result module 2018-02-05 08:49:49 +01:00
result.mli ocamltest: introduce the result module 2018-02-05 08:49:49 +01:00
run.h ocamltest: refactoring and implementation of hooks 2017-11-23 17:04:46 +01:00
run_command.ml Use Sys.{win32,...} instead Sys.os_type 2020-05-27 19:19:22 +02:00
run_command.mli ocamltest: refactoring and implementation of hooks 2017-11-23 17:04:46 +01:00
run_common.h Rename: use _os suffix 2017-09-27 11:55:53 +02:00
run_stubs.c Lock channels before doing I/O 2020-07-27 17:29:39 +01:00
run_unix.c Fix memory leak 2020-07-17 19:49:27 +02:00
run_win32.c Fix ocamltest process termination on Windows 2018-04-26 16:30:57 +01:00
strace.ml strace in ocamltest: take reviewer comments into account 2019-09-26 17:48:25 +02:00
strace.mli ocamltest: add support for using strace 2019-09-26 17:44:22 +02:00
tests.ml ocamltest: show failing logs (#9696) 2020-06-23 20:47:38 +02:00
tests.mli ocamltest: introduce the result module 2018-02-05 08:49:49 +01:00
tsl_ast.ml Fixing typos in various files (#2246) 2019-02-13 14:04:56 +01:00
tsl_ast.mli Fixing typos in various files (#2246) 2019-02-13 14:04:56 +01:00
tsl_lexer.mli Harden ocamltest against errors in scripts and hooks 2019-04-02 17:24:16 +02:00
tsl_lexer.mll Typos 2020-05-27 19:19:22 +02:00
tsl_parser.mly Typos 2020-05-27 19:19:22 +02:00
tsl_semantics.ml ocamltest: make it possible to declare variables in the DSL 2018-03-21 17:23:29 +01:00
tsl_semantics.mli ocamltest: the test driver for the OCaml compiler 2017-09-18 17:40:14 +02:00
variables.ml ocamltest: add the -show-variables commandline option 2018-05-29 08:45:56 +02:00
variables.mli ocamltest: add the -show-variables commandline option 2018-05-29 08:45:56 +02:00

README

# Introduction

## Context

The testsuite of the OCaml compiler consists of a series of programs
that are compiled and executed. The output of their compilation and
execution is compared to expected outputs.

Before the introduction of ocamltest, the tests were driven by a set of
makefiles which were responsible for compiling and running the test
programs, and verifying that the compilation and execution outputs were
matching the expected ones.

In this set-up, the precise information about how exactly one test
should be compiled was separated from the test itself. It was stored
somewhere in the makefiles, interleaved with the recipes to actually
compile and run the test. Thus, given one test, it was not easy to
determine exactly how this test was supposed to be compiled and run.

## Purpose

The ocamltest tool has been introduced to replace most of the makefiles
logic. It takes a test program as its input and derives from annotations
stored as a special comment at the beginning of the program the exact
way to compile and run it. Thus the test-specific metadata are stored in
the test file itself and clearly separated from the machinery required
to perform the actual tasks, which is centralized in the ocamltest tool.

## Constraints

It may look odd at first glance to write the tool used to test the
compiler in its target language. There are, however, parts of the
compiler and the standard library that are already tested in a way,
namely those used to compile the compiler itself. Therefore, these
components can be considered more trustworthy than those that have
not yet been used and that's
why ocamltest relies only on the part of the standard library that has been
used to develop the compiler itself.

This excludes for instance the use of the Unix and Str libraries.

# Initial set-up

ocamltest needs to know two things:

1. Where the sources of the OCaml compiler to test are located.
This is determined while OCaml is built. The default location can be
overridden by defining the OCAMLSRCDIR environment variable.

2. Which directory to use to build tests. The default value for this is
"ocamltest" under Filename.get_temp_dir_name(). This value can be
overridden by defining the OCAMLTESTDIR environment variable.

# Running tests

(all the commands below are assumed to be run from OCAMLSRCDIR/testsuite)

From here, one can:

## Run all tests: make all

This runs the complete testsuite. This includes the "legacy" tests
that still use the makefile-based infrastructure and the "new" tests
that have been migrated to use ocamltest.

## Run legacy tests: make legacy

## Run new tests: make new

## Run tests manually

It is convenient to have the following ocamltest script in a directory
appearing in PATH, like ~/bin:

#!/bin/sh
TERM=dumb OCAMLRUNPARAM= /path/to/ocaml/sources/ocamltest/ocamltest $*

Once this file has been made executable, one can for instance run:

ocamltest tests/basic-io/wc.ml

As can be seen, ocamltest's output looks similar to the legacy format.

This is to make the transition between the makefile-based
infrastructure and ocamltest as smooth as possible. Once all the
tests will have been migrated to ocamltest, it will become possible to
change this output format.

The details of what exactly has been tested can be found in
${OCAMLTESTDIR}/tests/basic-io/wc/wc.log

One can then examine tests/basic-io/wc.ml to see how the file
had to be annotated to produce such a result.

Many other tests have already been migrated and it may be useful to see
how the test files have been annotated. the command

find tests -name '*ocamltests*' | xargs cat

gives a list of tests that have been modified and can therefore be used
as starting points to understand what ocamltest can do.

# Migrating tests from makefiles to ocamltest

It may be a good idea to run make new from the testsuite directory before
starting to migrate tests. This will show how many "new" tests there
already are.

Then, when running make new after migrating n tests,
the number of new tests reported by make new should have increased by n.

OCaml's testsuite is divided into directories, each of them
containing one or several tests, which can each consist of one or
several files.

Thus, the directory is the smallest unit that can be migrated.

To see which directories still need to be migrated, do:

find tests -name 'Makefile'

In other words, the directories that still need to be migrated are
the subdirectories of testsuite/tests that still contain a Makefile.

Once you know which directory you want to migrate, say foo, here is
what you should do:

Read foo/Makefile to see how many tests the directory contains and how
they are compiled. If the makefile only includes other makefiles and
does not define any variable, then it means that nothing special
has to be done to compile or run the tests.

You can also run the tests of this directory with the legacy framework,
to see exactly how they are compiled and executed. To do so, use the
following command  from the testsuite directory:

make --trace DIR=tests/foo

(You may want to log the output of this command for future reference.)

For each test, annotate its main file with a test block, i.e. a
comment that looks like this:

(* TEST
  Optional variable assignments and tests
*)

In particular, if the test's main file is foo.ml and the test uses
modules m1.ml and m2.ml, the test block will look like this:

(* TEST
  modules = "m1.ml m2.ml"
*)

And if the test consists of a single file foo.ml that needs to be
run under the top-level, then its test block will look like this:

(* TEST
  * toplevel
*)

Or, if there are two reference files for that test and the name
of one of them contains "principal", then it means the file should
be tested with the top-level, without and with the -principal option.
This is expressed as follows:

(* TEST
  * toplevel
  * toplevel
    include principal
*)

Lines starting with stars indicate which tests to run. If no test is
specified, then the tests that are enabled by default are used,
namely to compile and run the test program in both bytecode and native
code (roughly speaking).

Once your test has been annotated, run ocamltest on it and see
whether it passes or fails. If it fails, see the log file to understand why
and make the necessary adjustments until all the tests pass.

The adjustments will mostly consist in renaming reference files and
updating their content.

Note that there are different types of reference files, those for
compiler output and those for program output.

To make sure the migration has been done correctly, you can compare the
commands used to compile the programs in ocamltest's log file to those
obtained with make --trace. Beware that the commands used to compare an
obtained result to an expected one will not show up in ocamltest's log
file.

Once this has been done for all tests, create a file called "ocamltests"
(mark the final s!) with the names of all the files that
have been annotated for ocamltest, one per line.

Finally, git rm the Makefile and run make new from the testsuite directory
to make sure the number of new tests has increased as expected.