BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
On this page

Scenarios: a played check from a file

BF22142Heroes

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.

One scenario run the scenario file server, players, asserts the server a level, a scene, the probe headless players the protocol, no picture clients off screen, scripted keys artefacts events, traces, pictures assertions the file's own invariants every run's PASS, FAIL, VOID (the test's fault), KNOWN-FAILING; every started process is stopped; 290 s at most; 127.0.0.1 only tools/scenarios/run.ps1, scn.py, invariants.py
One run. Everything in the middle column is a real program of the port; nothing is mocked.

The parts of a run#

PartWhat it is
the serverthe 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 scenea script in the server that places things: a jeep beside the spawn, a soldier at a flag
headless playersa program that speaks the network protocol and plays a role without drawing anything: cheap, many at once
clientsthe 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 probea script in the server that writes events (a kill, an entry, a capture) and a state snapshot every few seconds
artefactswhat each program wrote: the server's output, the probe's events, each client's trace, its HUD trace, its sounds, its frame times, pictures
assertionsthe scenario's own claims over the artefacts
invariantsclaims 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#

toml
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 = 1

A 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#

KindIt checks
eventshow many probe events of a kind match a filter (an entry into a vehicle of a template, by a human)
rate, shots_rateevents or shots per time bucket and team: "both sides keep fighting for the whole round"
probe, moved, drawnthe 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, sequencelines of an artefact matching a pattern; a file exists; steps in order in a per-frame log, each within so many frames
expra Python expression over events, probes and files, for what the others cannot say
clean_exitno panic or fault of the server or a client
view_enter, tag_enter, pop_audithow 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
framesframe times of named script segments
spawnthe 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#

VerdictMeaning
PASSevery assertion and every invariant holds
FAILone does not
VOIDonly void assertions failed: the run is no record; never a pass, and it fails the runner
KNOWN-FAILINGit fails and is on the list of expected failures, each with the open row behind it
PENDINGwritten for something not yet ported

The invariants#

After its own assertions every run is checked for (tools/scenarios/invariants.py):

InvariantIt fails on
exita panic, a fault, an early exit of the server, a client that did not end with code 0
hanga client that had to be stopped at its deadline and had been silent for more than 15 s
errorsa line of an error kind that is in no class of known harmless lines
correctionstoo many visible prediction corrections a second (prediction)
popsan object in view that is drawn in one probe frame and gone in the next
sounds, loopsa sound that could not be resolved; a looping tone that did not stop
ghostsa vehicle the server has near the player that the client does not list
frame_time, tick_rate, blocked_frameframe 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
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 again

Each 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#

WhatWhere
the runnertools/scenarios/run.ps1, tools/scenarios/scn.py
scenarios, scenes, suitestools/scenarios/scenarios/*.toml, tools/scenarios/scenes/, tools/scenarios/suites.toml
invariants and the harmless-line classestools/scenarios/invariants.py, tools/scenarios/benign_lines.toml
comparison scripts and their own teststools/scenarios/*_cmp.py, *_diff.py, test_*.py
the headless playercrates/bf2-server/examples/players_client.rs

Notes: notes/tracks/scenarios.md, notes/tracks/validation-strategy.md, notes/tracks/qa.md.

Source: docs/dev/testing/scenarios.md · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.