Skip to content

Commit 71a14a9

Browse files
committed
e2e: add an option to test a branch with our own tooling.
A run hands over to the revision it tests: it re-executes that revision's e2e-runner and builds e2e-report out of its worktree. That is right when the revision is what we are testing, and backwards when the tooling is. Tooling changes have nowhere to be exercised -- on a branch they are tested against whatever else is on it, and against main they are thrown away at the handover. --own-tooling keeps both tools ours. The worktree is still the branch's, so the tests and the plugins still are too. Both tools or neither: it is the runner which records what a report reads. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
1 parent f4c18f3 commit 71a14a9

4 files changed

Lines changed: 99 additions & 5 deletions

File tree

scripts/testing/nightly/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ environment:
4949
| `PACK_RESULTS` | `--pack-results` | off, see below |
5050
| `K8SCRI` | `--runtime` | containerd and cri-o on alternating days |
5151
| `FULL_BUILD` | `--full-build`, `--minimal-build` | everything once a week |
52+
| `OWN_TOOLING` | `--own-tooling` | off, the tested revision's tooling runs |
5253
| `RUN_IF_CHANGED` | `--run-if-changed` | off, test whenever asked |
5354
| `FORCE_AFTER` | `--force-after` | `24h`, with `--run-if-changed` |
5455

@@ -132,6 +133,40 @@ read -r verdict _ < "$RESULT_ROOT/latest/status.txt"
132133
[ "$verdict" = PASS ] || echo "e2e run $verdict, see $RESULT_ROOT/latest/"
133134
```
134135

136+
## Testing a branch with your own tooling
137+
138+
A run hands over to the tested revision: it adds the worktree, then re-executes
139+
the `e2e-runner` it finds there and builds `e2e-report` out of it, so a run is
140+
driven and reported on by the revision under test. That is what you want when the
141+
revision is what you are testing.
142+
143+
It is the wrong way round when the *tooling* is what you are testing. Changes to
144+
the runner or to `e2e-report` have nowhere to be exercised: putting them on a
145+
branch and testing that branch tests them against whatever else is on it, and
146+
testing `main` throws them away at the handover. `--own-tooling` keeps them:
147+
148+
```shell
149+
scripts/testing/nightly/e2e-runner --branch main --own-tooling \
150+
--results /opt/e2e-test/nri-plugins/results
151+
```
152+
153+
The worktree is still added at the branch, and the tests and the plugins are
154+
still the branch's -- only the tooling is ours. So the line above runs `main`'s
155+
tests against `main`'s plugins, with the runner and the reporter of the tree it
156+
was started from. `E2E_OWN_TOOLING=1` in the `e2e-cron-job` settings does the same
157+
from cron.
158+
159+
Both tools or neither, deliberately: it is the runner which records what a report
160+
reads, so a run driven by one revision's runner and reported on by another's
161+
loses whatever the two do not agree about. Asking for it from a tree which has no
162+
`test/e2e/cmd/e2e-report` in it is refused before the run rather than after the
163+
tests, when there would be nothing left to report them with.
164+
165+
The alternative is to keep a tooling branch rebased on `main` and test that,
166+
which works as long as the branch touches nothing outside the tooling --
167+
`git diff --name-only main..<branch>` says whether it does. `--own-tooling` is
168+
what saves the rebasing.
169+
135170
## Serving the results
136171

137172
`e2e-report serve` is what serves the results, and the only thing which can: the

scripts/testing/nightly/e2e-cron-job

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ E2E_PACK_RESULTS="${E2E_PACK_RESULTS-1}"
6868
# E2E_OPTIONS: anything else to pass the runner, as it would be on its command
6969
# line, for what this script has no setting of its own
7070
E2E_OPTIONS="${E2E_OPTIONS:-}"
71+
# E2E_OWN_TOOLING: test the branch with the tooling in the tree this script is
72+
# installed from, rather than the branch's. The tests and the plugins are still
73+
# the branch's, so this is how to exercise runner or e2e-report changes against a
74+
# branch which knows nothing of them.
75+
E2E_OWN_TOOLING="${E2E_OWN_TOOLING-}"
7176
# E2E_UPDATE_CLONE: bring the clone up to the branch before running, so that the
7277
# copy of the runner which parses our options is the branch's too. Off by
7378
# default: it is a reset --hard of a directory which may be someone's tree.
@@ -151,6 +156,12 @@ case "$E2E_PACK_RESULTS" in
151156
;;
152157
esac
153158

159+
case "$E2E_OWN_TOOLING" in
160+
1|true|yes|y)
161+
opts+=(--own-tooling)
162+
;;
163+
esac
164+
154165
if [ -n "$E2E_PROXIES" ]; then
155166
opts+=(--source-proxies "$E2E_PROXIES")
156167
fi

scripts/testing/nightly/e2e-cron-job.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
# flags in one value are fine.
4444
#E2E_OPTIONS=--runtime crio --retention-days 30
4545

46+
# Test the branch with the tooling in the tree this script is installed from,
47+
# rather than the branch's own: the tests and the plugins stay the branch's, the
48+
# runner and e2e-report are ours. This is how to exercise tooling changes against
49+
# a branch which knows nothing about them -- E2E_BRANCH=main with this on tests
50+
# main's plugins and main's tests with your runner.
51+
#E2E_OWN_TOOLING=1
52+
4653
# Bring the clone up to the branch before running. The runner already re-execs
4754
# itself out of the worktree it makes, so the tests, the framework and the report
4855
# tool are the branch's whatever is checked out here -- but the copy which parses

scripts/testing/nightly/e2e-runner

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ K8SCRI="${K8SCRI:-}"
4545
# FULL_BUILD: 1 to build all binaries and images, 0 for the minimal set of
4646
# them, empty to build everything once a week and the minimal set otherwise
4747
FULL_BUILD="${FULL_BUILD:-}"
48+
# OWN_TOOLING: run the tests of the branch with the tooling in the tree we were
49+
# started from rather than the branch's own.
50+
OWN_TOOLING="${OWN_TOOLING:-}"
4851
# RUN_IF_CHANGED: only test if the remote branch has moved since we last tried,
4952
# which is what makes it sane to trigger us from cron every few minutes
5053
RUN_IF_CHANGED="${RUN_IF_CHANGED:-}"
@@ -116,6 +119,7 @@ RUN_LOCK_FD="E2E_RUN_LOCK_FD"
116119
# E2E_REPORT_DIR: where it was built, ours to remove
117120
# VMS_LEFT_RUNNING: test VMs we failed to destroy, if any
118121
# RE_EXECED: whether we are the copy the bootstrap re-execed into
122+
# OWN_TREE: the tree we were started from, for --own-tooling
119123

120124
RESULT_DIR=""
121125
LOG=""
@@ -133,6 +137,11 @@ if [ -n "${!RUN_LOCK_FD}" ]; then
133137
RE_EXECED=1
134138
fi
135139

140+
# The tree we were started from, which --own-tooling takes the tooling from:
141+
# three levels up from scripts/testing/nightly, resolved so that being invoked
142+
# through a relative path or a symlink makes no difference.
143+
OWN_TREE="$(realpath -m "$(dirname "$(realpath "$SELF")")/../../..")"
144+
136145
usage() {
137146
local exit_code="${exit_code:-0}"
138147

@@ -159,6 +168,11 @@ usage() {
159168
echo " --no-pack-results publish the results as plain files"
160169
echo " --runtime <runtime> containerd or crio, by default the two of"
161170
echo " them on alternating days"
171+
echo " --own-tooling test the branch with the tooling in the"
172+
echo " tree we were started from, not the"
173+
echo " branch's: the tests and the plugins are"
174+
echo " the branch's, the runner and e2e-report"
175+
echo " stay ours"
162176
echo " --run-if-changed do nothing unless the remote branch has"
163177
echo " moved since we last tried to test it"
164178
echo " --force-after <time> with --run-if-changed, test anyway once this"
@@ -469,6 +483,14 @@ prepare_worktree() {
469483
fatal "failed to add git worktree $WORKTREE"
470484
fi
471485

486+
# Asked to be the runner of this run ourselves, so there is nothing to hand
487+
# over to: the worktree is there to supply the tests and the plugins only.
488+
if [ -n "$OWN_TOOLING" ]; then
489+
info "testing $TEST_BRANCH with our own tooling..."
490+
must-cd "$WORKTREE"
491+
return 0
492+
fi
493+
472494
if [ -x "$WORKTREE/scripts/testing/nightly/e2e-runner" ]; then
473495
# The options below are passed on, the rest default from the
474496
# environment, so export those to keep them across the re-exec.
@@ -823,10 +845,18 @@ policies_tested() {
823845
}
824846

825847
build_e2e_report() {
826-
local dir
848+
local dir tree="$WORKTREE"
849+
850+
# Reported on by the revision which was tested, so that a report says what
851+
# that revision knew to say -- unless the tooling of this run is ours, in
852+
# which case the reporting is ours too. Half of the tooling would be worse
853+
# than neither: it is the runner which records what the report reads.
854+
if [ -n "$OWN_TOOLING" ]; then
855+
tree="$OWN_TREE"
856+
fi
827857

828-
if [ ! -d "$WORKTREE/$E2E_REPORT" ]; then
829-
info "no $E2E_REPORT in $WORKTREE, leaving the results unreported..."
858+
if [ ! -d "$tree/$E2E_REPORT" ]; then
859+
info "no $E2E_REPORT in $tree, leaving the results unreported..."
830860
return 0
831861
fi
832862

@@ -836,8 +866,8 @@ build_e2e_report() {
836866
fi
837867
E2E_REPORT_DIR="$dir"
838868

839-
info "building $E2E_REPORT..."
840-
must-cd "$WORKTREE"
869+
info "building $E2E_REPORT out of $tree..."
870+
must-cd "$tree"
841871
if ! go build -o "$dir/e2e-report" "./$E2E_REPORT"; then
842872
error "failed to build $E2E_REPORT"
843873
return 1
@@ -1220,6 +1250,10 @@ while [ "$#" -gt 0 ] && [ "${1#-}" != "$1" ]; do
12201250
K8SCRI="$2"
12211251
shift 2
12221252
;;
1253+
--own-tooling)
1254+
OWN_TOOLING=1
1255+
shift
1256+
;;
12231257
--run-if-changed)
12241258
RUN_IF_CHANGED=1
12251259
shift
@@ -1263,6 +1297,13 @@ case "$K8SCRI" in
12631297
;;
12641298
esac
12651299

1300+
# Said up front rather than when we get to it: asking for our tooling from a
1301+
# tree which has none of it is a mistake worth hearing about before a run, not
1302+
# after the tests have been run and there is nothing to report them with.
1303+
if [ -n "$OWN_TOOLING" ] && [ ! -d "$OWN_TREE/$E2E_REPORT" ]; then
1304+
fatal "no $E2E_REPORT in $OWN_TREE, so there is no tooling of ours to use"
1305+
fi
1306+
12661307
# Packing keeps everything in one archive, and everything is what makes it
12671308
# worth serving: keep the artifacts of every test and the coverage data of each
12681309
# as well, unless we were told what to keep with them.

0 commit comments

Comments
 (0)