Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bc2e9c4

Browse files
authoredFeb 16, 2023
Merge pull request #11930 from gasche/restructure-contributing.md
Some small changes to CONTRIBUTING.md
2 parents 1c5e748 + fbcbf6d commit bc2e9c4

File tree

2 files changed

+80
-112
lines changed

2 files changed

+80
-112
lines changed
 

‎CONTRIBUTING.md

Lines changed: 17 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -119,101 +119,17 @@ preserving the code semantics.
119119

120120
## Test you must.
121121

122-
Whenever applicable, merge requests must come with tests
123-
exercising the affected features: regression tests for bug fixes,
124-
and correctness tests for new features (including corner cases and
125-
failure cases). For regression tests, testing other aspects of the
126-
feature (in particular, related edge cases) that are not currently
127-
covered is a good way to catch other instances of bugs -- this did
128-
happen several times in the past. Warnings and errors should also
129-
be tested.
130-
131-
Tests go in the sub-directories of `testsuite/tests`. Running
132-
`make all` in `testsuite/` runs all tests (this takes
133-
a few minutes), and you can use `make one DIR=tests/foo` to run
134-
the tests of a specific sub-directory. There are many kind of tests
135-
already, so the easiest way to start is to extend or copy an
136-
existing test.
137-
138-
In general, running a test produces one (or several) `.result` file,
139-
that are compared to one (or several) `.reference` file present in the
140-
repository; the test succeeds if they are identical. If your patch
141-
breaks a test, diffing the `.result` and `.reference` file is a way to
142-
see what went wrong. Some reasonable compiler changes affect the
143-
compiler output in way that make those outputs differ (for example
144-
slight modifications of warning or error messages may break all tests
145-
checking warnings). If you are positive that the new `.result` file
146-
is correct (and that the change in behavior does not endanger
147-
backward compatibility), you can replace the old `.reference` file
148-
with it. Finally, when adding new tests, do not forget to include your
149-
`.reference` files (but not `.result`) in the versioned repository.
150-
151-
Testing is also a way to make sure reviewers see working
152-
(and failing) examples of the feature you fix, extend or
153-
introduce, rather than just an abstract description of it.
122+
Whenever applicable, merge requests must come with tests exercising
123+
the affected features: regression tests for bug fixes, and correctness
124+
tests for new features (including corner cases and
125+
failure cases). Warnings and errors should also be tested.
154126

127+
See [testsuite/HACKING.adoc](testsuite/HACKING.adoc) for details on
128+
how to write tests and run the testsuite.
155129

156-
### Run tests before sending a PR
157-
158-
You should run all the tests before creating the merge request or
159-
pushing new commits (even if Travis will also do it for you): `make
160-
tests` (this takes a few minutes).
161-
162-
Unfortunately some of the `lib-threads` test are non-deterministic
163-
and fail once in a while (it's hard to test these well). If they
164-
consistently break after your change, you should investigate, but if
165-
you only see a transient failure once and your change has no reason
166-
to affect threading, it's probably not your fault.
167-
168-
169-
### Benchmarking
170-
171-
If your contribution can impact the performance of the code generated
172-
by the native compiler, you can use the infrastructure that the
173-
flambda team put together to benchmark the compiler to assess the
174-
consequences of your contribution. It has two main accessible parts:
175-
176-
- The website that hosts benchmarks results, at
177-
[http://bench.flambda.ocamlpro.com/](http://bench.flambda.ocamlpro.com/).
178-
It exposes two ways to compare compilers: the first, under the header
179-
`Plot a given benchmark`, allows to select a benchmark and
180-
see graphs plotting the evolution of the performance of the different
181-
compilers over time. The second, under `Compare two runs`, allows
182-
to get an overview of the differences between a reference compiler
183-
(selected using the `ref` button) and a compiler under test (using
184-
the `tst` button). Clicking on the `Compare` button at the bottom
185-
right of the page will create a new page containing summaries and
186-
raw data comparing the selected runs.
187-
188-
- The git repository containing the data about which benchmarks
189-
to run, on which compilers, at [https://github.com/OCamlPro/ocamlbench-repo](
190-
https://github.com/OCamlPro/ocamlbench-repo). This needs to be a valid
191-
opam 2.0 repository, and contains the benchmarks as normal packages
192-
and the compilers as versions of the package `ocaml-variants`.
193-
To add a compiler to the list, you must have a publicly accessible
194-
version of your branch (if you're making a pull request again the
195-
compiler, you should have a branch on github that was used to make
196-
the pull request, that you can use for this purpose).
197-
Then, you should make a pull request against `ocamlbench-repo`
198-
that adds a repertory in the `packages/ocaml-variants` sub-folder
199-
which contains a single `opam` file. The contents of the file
200-
should be inspired from the other files already present, with
201-
the main points of interest being the `url` field, which should
202-
point to your branch, the `build` field that should be adapted
203-
if the features that you want to benchmark depend on configure-time
204-
options, and the `setenv` field that can be used to pass compiler
205-
options via the `OCAMLPARAM` environment variable.
206-
The `trunk+flambda+opt` compiler, for instance, both uses a
207-
`configure` option and sets the `OCAMLPARAM` variable.
208-
The folder you add has to be named `ocaml-variants.%VERSION%+%DESCR%`,
209-
where `%VERSION%` is the version that will be used by opam to
210-
check compatibility with the opam packages that are needed for the
211-
benchmarks, and `%DESCR%` should be a short description of the feature
212-
you're benchmarking (if you're making a pull request against `ocaml`,
213-
you can use the PR number in the description, e.g. `+gpr0000`).
214-
Once your pull request is merged, it will likely take a few hours
215-
until the benchmark server picks up the new definition and again
216-
up to a few hours before the results are available on the results page.
130+
Adding tests is also a way to make sure reviewers see working
131+
(and failing) examples of the feature you fix, extend or
132+
introduce, rather than just an abstract description of it.
217133

218134

219135
## Description of the proposed change
@@ -223,9 +139,14 @@ up to a few hours before the results are available on the results page.
223139
The description of the merge request must contain a precise
224140
explanation of the proposed change.
225141

226-
Before going in the implementation details, you should include
227-
a summary of the change, and a high-level description of the design
228-
of the proposed change, with example use-cases.
142+
Before going into the implementation details, you should include
143+
a summary of the change, a justification of why it is beneficial, and
144+
a high-level description of the design of the proposed change with
145+
example use cases.
146+
147+
Changes have a cost, they require review work and may accidentally
148+
introduce new bugs. Communicating as clearly as you can the benefits
149+
of your PR will reassure and motivate potential reviewers.
229150

230151
### In the patches
231152

‎testsuite/HACKING.adoc

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
== Running the testsuite
22

3+
From the root directory of this repository, `make tests` will run all
4+
the tests, which takes a few minutes.
5+
6+
More control is available from the `testsuite/` subdirectory (here):
7+
`make all` runs all tests, `make parallel` runs the tests in parallel,
8+
and you can use `make one DIR=tests/foo` to run the tests of
9+
a specific sub-directory.
10+
11+
== Writing new tests
12+
13+
There are many kind of tests already, so the easiest way to start is
14+
to extend or copy an existing test.
15+
16+
== Sorts of tests
17+
18+
A test is specified in a `.ml` file containing a `TEST` block which is
19+
processed by our `ocamltest` testing tool, and contains a description
20+
of the testing to be performed.
21+
22+
There are two common sorts of tests:
23+
24+
- file-based tests: running them produces a `.result` file, that are
25+
compared to one (or several) `.reference` file(s) present in the
26+
repository. (Some tests, for example, have different reference
27+
results depending on whether the bytecode or native compilers are
28+
used, or depending on whether flambda is used or not). The tests
29+
succeeds if the .result and .reference files are identical.
30+
31+
- expect-style tests: those are toplevel-based tests with inline
32+
`[%%expect {|...|}]` blocks that contain the expected output for the
33+
toplevel phrases before them. The test succeeds if the toplevel
34+
output is identical to the expected output.
35+
36+
expect-style tests are typically easier to read and maintain; we
37+
recommend using then whenever the feature that you want to test can be
38+
observed from the bytecode toplevel.
39+
40+
== Promotion
41+
42+
Tests compare their current result with recorded reference results,
43+
and fail if they differ. Sometimes changes to test results are in fact
44+
expected and innocuous, they come from an intended change in output
45+
instead of a regression. Modifying each reference file by hand would
46+
be extremely time-consuming. The standard approach in this case is to
47+
automatically "promote" the current results into expected results, by
48+
overwriting the `.reference` file or `expect` payload.
49+
50+
Promoting a test is done using the `make promote DIR=tests/foo`
51+
target. In general `make promote` accepts the same arguments (`TEST`,
52+
`LIST`) as `make one` -- there is no analogue to `make all`.
53+
54+
Typical use-cases for promotion are changes to a compiler message that
55+
occurs in the reference results, or code modifications that change
56+
source locations included in reference results.
57+
58+
Whenever you promote test results, please check carefully using `git
59+
diff` that the changes really correspond to an intended output
60+
difference, and not to a regression. You then need to commit the
61+
changes to the reference files (or expect test output); consider
62+
explaining in the commit message why the output changed.
63+
364
== Useful Makefile targets
465

566
`make parallel`::
@@ -35,20 +96,8 @@ tests/baz
3596
then this will run all the tests in those three directories.
3697

3798
`make promote DIR=tests/foo`, `make promote TEST=tests/foo/bar.ml`, `make promote LIST=file.txt`::
38-
Most tests run a program and compare the result of the program, stored in a
39-
file `foo.result`, with a reference output, stored in `foo.reference`; the
40-
test fails if the two outputs differ. Similarly, many other tests are expect
41-
tests, with the expected output following the code inline in the test file. In
42-
both cases, sometimes a change in the result is innocuous, as it comes from an
43-
intended change in output instead of a regression. `make promote` is like
44-
`make one`, but for each failing test, it copies the new results into the
45-
reference files (or into the expect test expected output), making the failing
46-
test pass again. Whenever you use this rule please check carefully, using `git
47-
diff`, that the changes really correspond to an intended output difference,
48-
and not to a regression. You then need to commit the changes to the reference
49-
files (or expect test output), and your commit message should explain why the
50-
output changed. `make promote` takes the same variables as `make one` to
51-
determine which tests to run (there is no analog to `make all`).
99+
Promotes the current outputs to reference outputs for the specified tests.
100+
52101

53102
== Useful environment variables
54103

@@ -61,8 +110,6 @@ then this will run all the tests in those three directories.
61110
with `KEEP_TEST_DIR_ON_SUCCESS=1` to inspect the test output. By default
62111
`OCAMLTESTDIR` is `_ocamltest`.
63112

64-
== Creating a new test
65-
66113
== Dimensioning the tests
67114

68115
By default, tests should run well on small virtual machines (2 cores,

0 commit comments

Comments
 (0)