On this page
Scenarios: a played check from a file
A scenario turns one thing a player can see into a check that passes or fails: "a jeep can be entered and driven", "the flag's pole is drawn when you stand close", "a team that holds no point bleeds". It is a small file. The runner starts a server, starts players, lets them play a script, stops everything it started, and judges what was written down.
The parts of a run#
| Part | What it is |
|---|---|
| the server | the port's bf2_server on a level, with settings; optionally, after it, the original dedicated server with the same clients and assertions (a differential) |
| a scene | a script in the server that places things: a jeep beside the spawn, a soldier at a flag |
| headless players | a program that speaks the network protocol and plays a role without drawing anything: cheap, many at once |
| clients | the real client, off screen, with injected keys and a script (play, vehicle, gunner, watch, hud ..); as the desktop program or as the page in a headless browser |
| the probe | a script in the server that writes events (a kill, an entry, a capture) and a state snapshot every few seconds |
| artefacts | what each program wrote: the server's output, the probe's events, each client's trace, its HUD trace, its sounds, its frame times, pictures |
| assertions | the scenario's own claims over the artefacts |
| invariants | claims every scenario is held to, whatever it asserts itself |
The run folder keeps all of it, so an assertion can be evaluated again without playing again.
The file#
description = "a player enters the jeep by the spawn and drives off"
timeout = 290
servers = ["ours"] # ["ours", "retail"] makes it a differential
[server]
maps = ["strike_at_karkand gpm_cq 16"]
scene = "jeep_near"
[[client]]
name = "a"
script = "vehicle"
spawn = "1:3:0" # team : kit : spawn group
seconds = 150
[[assert]]
name = "server: entered the jeep"
kind = "events"
ev = "enter"
where = { ai = false, root = "~jep_vodnik" }
min = 1A scenario may not last more than 290 seconds of wall time, uses 127.0.0.1 only, and never joins a server it did not start.
Waiting for the game, not for a clock#
A key that must follow something the game does should wait for it, not for a frame number: keys_after presses its keys a number of frames after a given line first appears in the client's own trace. A scenario written with fixed frames passes on an idle machine and fails on a busy one; this was learned the hard way.
Assertion kinds#
| Kind | It checks |
|---|---|
events | how many probe events of a kind match a filter (an entry into a vehicle of a template, by a human) |
rate, shots_rate | events or shots per time bucket and team: "both sides keep fighting for the whole round" |
probe, moved, drawn | the client's probe: frames in a state; the soldier moved so many metres; a mesh within a distance was drawn in a share of the frames |
lines, exists, sequence | lines of an artefact matching a pattern; a file exists; steps in order in a per-frame log, each within so many frames |
expr | a Python expression over events, probes and files, for what the others cannot say |
clean_exit | no panic or fault of the server or a client |
view_enter, tag_enter, pop_audit | how many frames an object or a name tag needs to appear once it comes into view; whether the drawn level of detail follows the original's rule |
frames | frame times of named script segments |
spawn | the spawn screen opened and the soldier was alive within a time |
An assertion can be marked void = true: when it fails, the run says nothing about the game (a scripted key the server never carried out, a player who left before his script ended).
Verdicts#
| Verdict | Meaning |
|---|---|
| PASS | every assertion and every invariant holds |
| FAIL | one does not |
| VOID | only void assertions failed: the run is no record; never a pass, and it fails the runner |
| KNOWN-FAILING | it fails and is on the list of expected failures, each with the open row behind it |
| PENDING | written for something not yet ported |
The invariants#
After its own assertions every run is checked for (tools/scenarios/invariants.py):
| Invariant | It fails on |
|---|---|
exit | a panic, a fault, an early exit of the server, a client that did not end with code 0 |
hang | a client that had to be stopped at its deadline and had been silent for more than 15 s |
errors | a line of an error kind that is in no class of known harmless lines |
corrections | too many visible prediction corrections a second (prediction) |
pops | an object in view that is drawn in one probe frame and gone in the next |
sounds, loops | a sound that could not be resolved; a looping tone that did not stop |
ghosts | a vehicle the server has near the player that the client does not list |
frame_time, tick_rate, blocked_frame | frame and tick times beyond limits that scale with how busy the machine was |
A scenario can opt out of one with a reason in its file. The limits were taken from clean runs; they catch stalls and hangs, not a missed 33 ms: the machine is shared and the runner samples its load so that a starved frame is told apart from a slow one.
Differentials#
With servers = ["ours", "retail"] the same clients play the same script against the port's server and then the original's, on this machine. The assertions run on both, and a comparison script can lay the two runs side by side: positions tick for tick, damage per hit, the order of events. For motion the rule is to compare tick for tick, not at wall times: two servers never start a client's input on the same tick, so the runs are first aligned on an event both have.
Suites#
Suites are named in tools/scenarios/suites.toml (a suite's patterns and exclusions; a scenario that belongs to a suite by name says so in its own file with a suites = ["<suite>"] line, so adding a scenario changes no shared list): a smoke gate of a few minutes that runs on every merge; the regression wall (wall_a, wall_b), one scenario for each fault once found in play; actions, vehicles, hud, menus; per-game suites; and full. The tree holds more than two thousand scenario files across the three games.
powershell -File tools\scenarios\run.ps1 smoke -Parallel 3
powershell -File tools\scenarios\run.ps1 jeep_drive
powershell -File tools\scenarios\run.ps1 -Check <a run folder> # judge again, do not play againEach parallel slot has its own ports, its own server folder and its own profile homes, so runs never share a file.
A scenario as proof#
A scenario's passing run also feeds the parity count: the functions that ran in its traced run count generously (class b), and an address named in the scenario's own text counts as class f. Neither is strict. A scenario proves that something is wired and seen; that the function behind it does what the original's does is a test's job (how a port is made).
How it is tested#
The runner has its own tests (tools/scenarios, 85 test files beside it). Every scenario also runs the invariants, whatever it asserts itself. A scenario in a suite is not thereby "played": the feature ledger reads each scenario's last recorded result, and a line of what a player sees is checked only by a recorded pass whose picture was read (feature checklists).
In the code#
| What | Where |
|---|---|
| the runner | tools/scenarios/run.ps1, tools/scenarios/scn.py |
| scenarios, scenes, suites | tools/scenarios/scenarios/*.toml, tools/scenarios/scenes/, tools/scenarios/suites.toml |
| invariants and the harmless-line classes | tools/scenarios/invariants.py, tools/scenarios/benign_lines.toml |
| comparison scripts and their own tests | tools/scenarios/*_cmp.py, *_diff.py, test_*.py |
| the headless player | crates/bf2-server/examples/players_client.rs |
Notes: notes/tracks/scenarios.md, notes/tracks/validation-strategy.md, notes/tracks/qa.md.
docs/dev/testing/scenarios.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.