Every test stage catches some bugs and misses others. In this toy, unit tests and simulation alone let 66 of 100 bugs reach the field. Add hardware in the loop, log replay and a robot test, and 19 get through.
Learn what a robotics test engineer builds: the stages that catch bugs, the statistics that say how sure you are, and the gate that decides what ships.
Switch test stages on and off. Watch which bugs fall through to the field. Then we build, piece by piece, each stage, the numbers behind a pass rate, flaky tests, regression gates, replay, deadlines and safety bounds.
You need some Python and what a probability is. We build the rest from zero.
Illustrative toy. We made up the catch rate of each stage for each kind of bug. The shape is the point: each stage sees only the bugs whose cause it makes real. Chapter 0 gives the rule and Chapter 1 the reason.
Chapter 0
See what a robotics test engineer builds, and why bugs that pass one stage must meet another
A warehouse robot drops a box at 3 a.m. The planner logs a confident grasp. The gripper opened 200 ms early. The code passed every unit test last week. Where should the bug have been caught?
A robotics test engineer builds the machinery that answers that question before the robot does. The job is a chain of stages between a code change and a robot at work. Each stage is a different kind of test, and each sees a different part of reality.
| What the role builds | What it is for |
|---|---|
| Test harness and CI | Run every test on every change, the same way each time. This is continuous integration (CI). |
| Scenario library | The situations the robot must handle, as data. |
| Simulation and HIL rigs | Run the robot's software against a fake or partly real world. |
| Log replay tools | Feed recorded sensor data through new code. |
| Gates and dashboards | Turn pass rates into a ship or block decision. |
How many bugs get past the whole chain? Call the share of bugs that stage i catches its catch rate, ci. A bug escapes only if every stage misses it.
E equals the product over i of one minus c-i.
For each stage, take the share it misses, 1 minus c-i. Multiply those shares together. The result E is the share that slips through every stage.
With made-up numbers: unit tests catch 0.6, simulation 0.5, HIL 0.3. E = 0.4 × 0.5 × 0.7 = 0.14. So 14 of 100 bugs reach the field.
Each slider is one stage. The bar shows 100 bugs; each stage takes its share of what is left. Push one stage to 0 and see the escapes jump.
Illustrative catch rates. The product rule assumes the stages miss bugs independently.
Where it breaks: the product assumes each stage misses bugs for its own reasons. Unit tests and simulation share one physics model, so they miss the same physics bugs. The hero shows it: 22 of 25 physics bugs pass both. The symptom is a field failure that no stage ever flagged. The measurement is to tag each field bug with the first stage that could have caught it. The fix is a stage that makes that cause real.
Chapter 1
Sort each test stage by which parts of the robot it makes real, and predict which bugs it can see
The control loop runs fine on your laptop. On the robot's own computer, it takes 12 ms out of a 10 ms budget. No simulation on the laptop will ever show that. The cause lives in the robot's computer, and the laptop test does not include it.
That is the rule for every stage: a test can only see a bug whose cause is real in that test. So sort the stages by what each one makes real.
Warm cells are real, blue cells are simulated. Pick a bug. Its cause lights up in one row, and only columns where that cell is warm can catch it.
The grid is a simplified, typical setup. Some HIL rigs also use real sensors or motor drivers; then those cells turn warm.
The price runs the other way. A unit test costs a fraction of a second and runs thousands of times a day. A robot test needs a cell, a person to reset the scene and minutes per run. The engineer's skill is to push each bug to the cheapest stage that makes its cause real.
| Stage | Real | Simulated | Catches |
|---|---|---|---|
| Unit | one function | its inputs | logic slips |
| SIL | all the code | world, sensors, computer | integration, behaviour |
| HIL | code, computer, wiring | world, sensors | timing, drivers, I/O |
| Robot | everything in the cell | the customer site | physics, wear, sensors |
The failure here is the sim-to-real gap: the simulator's friction, contact and camera noise differ from the real ones. The symptom is a policy that passes 98% in SIL and 80% on the robot. To measure it, run the same scenarios in both and plot pass rate against pass rate. To fix it, tune the simulator to the robot data, and vary its parameters so no single wrong value decides the result.
Chapter 2
Count the situations a robot can meet, and cover every pair of conditions with a few runs
A picking robot must handle bright light and dim light, a box or a bag, a slow belt or a fast one. A scenario is one setting of every condition, such as "dim, bag, fast belt, object on the left". Each condition is a parameter, and each of its values is a level.
How many scenarios exist? Call the number of levels of parameter i ni.
N-full equals the product over i of n-i.
Each new parameter multiplies the grid by its own level count n-i. The total N-full grows fast with every parameter you add.
With four parameters of 3 levels each, N-full = 3 × 3 × 3 × 3 = 81. At 3 minutes per simulated run, that is 4 hours 3 minutes for one pass.
Most bugs need only one or two conditions together: a bag and glare, not a bag and glare and a fast belt and the left side. So a cheaper goal is pairwise coverage: every level of every parameter meets every level of every other parameter in at least one run. For four 3-level parameters, a known table called the L9 orthogonal array does it in 9 runs instead of 81.
Each toggle adds a parameter. Yellow is the full grid, teal is a pairwise set. Add all six and compare the two bars.
The pairwise count comes from a simple greedy picker run live in your browser. It finds 9 runs for four 3-level parameters, which matches the L9 table; on other mixes the best known set can be a run or two smaller.
The failure is a scenario list that only holds the cases someone thought of. The symptom is a field bug in a combination the suite never ran. Measure pair coverage: the share of all level pairs that appear in at least one run. Fix gaps with a pairwise generator, then add every field failure as a new scenario so it can never return unseen.
Chapter 3
Put an error bar on a pass rate, and see why 47 of 50 does not mean 94%
The grasp scenario passed 47 of 50 runs in simulation. Is the true pass rate 94%? Run 50 more and you might get 45 or 49. A robot run has random parts: sensor noise, object pose, timing. So a pass rate from n runs is an estimate of the true rate, and it needs an error bar.
Call the number of runs n and the passes k. The measured rate is p̂ = k/n. Its typical error is the standard error.
S-E equals the square root of p-hat times one minus p-hat, divided by n.
Multiply the pass rate p-hat by the fail rate. Divide by the run count n. Take the square root. A 95% band is about p-hat plus or minus 1.96 times SE.
47 of 50: p-hat = 0.94. SE = √(0.94 × 0.06 / 50) = 0.034. The band is 94% ± 6.6 points. At 470 of 500 it shrinks to ± 2.1 points.
The dashed line is the true pass rate. Each press runs one batch and draws its 95% band. Try 10 runs, then 1000.
Simulated coin flips at the true rate you set. Bands use the Wilson interval from the next paragraph, so they never run past 100%.
Look at the 47 of 50 band again: 94% plus 6.6 points is 100.6%. That is the failure of the shortcut. Near 0% or 100% the band runs off the scale, and at 50 of 50 the SE is zero, which claims perfect certainty. Use the Wilson interval instead. For 47 of 50 it gives 83.8% to 97.9%. Chapter 8 handles the case with zero failures.
Chapter 4
Compute how often a clean suite goes red, and how many reruns it takes to catch a rare flake
Friday, 6 p.m. CI is red. Nobody changed the failing code. You rerun it and it passes. A flaky test is a test that passes and fails on the same code. Typical causes are a fixed sleep instead of a wait for readiness, state left over by an earlier test, and a shared GPU under load.
One rare flake looks harmless. A suite has many tests. Call the number of tests M and the chance that one test flakes on a run f.
R equals one minus, one minus f, to the power M.
One test stays green with chance 1 minus f. All M tests stay green with that chance multiplied M times. R is whatever is left.
With made-up numbers: M = 200 tests, f = 0.5%. R = 1 − 0.995200 = 0.63. Nearly two runs in three are red with no bug.
Every night runs the same correct code. Pink nights went red from flakes alone. Grow the suite and watch the curve climb.
Simulated nights with independent flakes at the rate you set. Real flakes cluster, for example on one busy CI machine.
When red is normal, people rerun by reflex and real failures slip through. So find flakes on purpose. How many reruns prove a test is not flaky? Call the flake rate you want to detect F and the confidence C.
N is at least the natural log of one minus C, divided by the natural log of one minus F.
A test with flake rate F passes N runs in a row with chance (1 minus F) to the N. Make that chance at most 1 minus C, then solve for N.
F = 5%, C = 95%: N ≥ ln 0.05 / ln 0.95 = 58.4, so 59 reruns. For F = 1% it is 299 reruns.
The failure is a red-is-normal culture. Measure the rerun rate: the share of CI runs someone restarted by hand. The fix is a quarantine: a flaky test moves to a non-blocking job with an owner and a deadline. It comes back only after its clean reruns.
Chapter 5
Decide whether a new build is worse than the old one, or only unlucky
Last night's build passed 94% of the scenario suite. Tonight's candidate passed 90%. Is it a regression, a real drop in quality, or noise? A regression gate is the rule in CI that blocks a merge when the drop is larger than noise can explain.
Call the baseline pass rate pb, the candidate's pc, the runs per build n, and the drop D = pb − pc. Pick a strictness z.
Block if D is greater than z times the square root of p-b times one minus p-b over n, plus p-c times one minus p-c over n.
The square root is the standard error of the drop D, from both builds' noise. Multiply it by z. If D is bigger, block.
p-b = 0.94, p-c = 0.90, n = 400: the root is √(0.000141 + 0.000225) = 0.0191, and 2 × 0.0191 = 0.038. D = 0.04 is larger, so block. At n = 100 the bar is 0.077, and the same drop ships.
Teal is the baseline at a true 94%, blue the candidate. The green line is the bar the drop must clear. Run several times at 100 runs, then at 1600.
Simulated runs at the true rates you set, gate strictness z = 2. The tally resets when you change a setting.
The failure runs both ways. Too few runs, and a real 4-point drop ships most nights. A gate that blocks on any drop blocks good builds half the time. Measure both rates on known cases: rerun an unchanged build to count false blocks, and plant a known bug to count misses. Chapter 9 runs this for 30 nights.
Chapter 6
Feed recorded sensor data through new code, and find the moment the recording stops being true
The robot failed at a customer site on Tuesday. It recorded every camera frame, joint reading and command into a log: timestamped messages in a file, such as a ROS 2 bag or an MCAP file. Log replay plays those messages into new code at their recorded times and compares the outputs.
Replay gives you real sensor data, with real glare and real noise, at the cost of a laptop. Every field failure becomes a test that runs on every change.
Step 4 is the determinism check. If two replays of one log differ, the code has a race between threads, or it reads the wall clock instead of the log's clock. Fix that first, or no replay result means anything.
Replay has one hard limit. It is open loop: the log cannot react. A detector does not change the next camera frame, so replay tests it well. A planner does. If the new planner turns left where the old robot went straight, the log still shows the view from straight ahead.
Purple is the logged path. Teal is where the new planner would drive. Raise the change and watch the green valid window shrink.
Illustrative toy. The gap grows as change × (t − 4 s)² / 4 metres after the new planner first acts at 4 s; the tolerance is 0.3 m.
With a change of 0.2, the gap reaches 0.3 m at 4 + √(1.2 / 0.2) = 6.4 s. After that, the replay scores the new planner against a world it would never see. That is the failure: a planner change that passes replay and fails on the robot. The fix is to trust replay up to the split, then start a closed-loop simulation from the logged state.
Chapter 7
Read the tail of a latency histogram, and turn a tiny miss rate into misses per hour
An arm's control loop runs at 100 Hz. Each cycle must read the sensors, compute and send a command within 1/100 s, which is 10 ms. That limit is the deadline. A cycle that runs past it is a deadline miss: the motors get a stale command, and the arm jerks.
The average cycle takes 6 ms, so all is well? No. A rare stall, such as a memory allocation or a busy GPU, can take 13 ms. Call the loop rate f and the chance that one cycle misses p.
H equals f times three thousand six hundred times p.
The loop runs f times 3600 cycles each hour. A share p of them miss. Multiply to get H.
f = 100 Hz and p = 0.1%: H = 100 × 3600 × 0.001 = 360 misses per hour. A one-in-a-thousand event happens six times a minute.
The bars are cycle times. The warm line is the deadline. Raise the loop rate or the stalls and count the red cycles.
Illustrative model: normal cycles have a median of 6 ms; stalls have a median of 13 ms. The page computes the percentiles and the miss chance exactly from that model.
At 100 Hz with 0.5% stalls, the 99th percentile, p99, is 8.8 ms: under budget. The 99.9th percentile is 15.4 ms. That is the failure. A dashboard of the mean and p99 looks green, while the arm misses about 1,700 deadlines an hour. Measure every cycle on the real robot computer, in HIL, and report p99.9, the maximum and the miss count. Fix the stall itself: no memory allocation inside the loop, a real-time thread priority, and a safe fallback command when a cycle runs late.
Chapter 8
Turn hours without a failure into a bound on the failure rate, and know which standard asks for what
The robot ran 1,000 hours in the test cell with no unsafe event. How safe is it? Zero failures does not mean a zero rate. It means the rate is probably below some bound. Call the hours tested T and the confidence C.
Lambda-up equals minus the natural log of one minus C, divided by T.
At 95% confidence, divide 3 by the hours T. This is the rule of three. Its inverse is a lower bound on the mean time between failures (MTBF).
T = 1,000 h, C = 0.95: λ-up = 3.0 / 1,000 = 0.0030 per hour. The MTBF is at least 334 hours. To show 10,000 hours you need about 30,000 clean hours.
The bar is the range the true failure rate can still be in. The warm tick is a target of 1 failure per 10,000 h. Add hours until the bar falls left of the tick.
Exact Poisson bound at 95% confidence. With k failures it uses the rate at which k or fewer failures would happen only 5% of the time.
The same rule sets the scale for self-driving cars. Kalra and Paddock (RAND, 2016) used a human rate of 1.09 deaths per 100 million miles. Dividing 3 by that rate gives 275 million failure-free miles to show a car is as safe at 95% confidence. No test fleet drives that far before each release. So safety arguments combine field miles, simulation, scenario tests and design analysis in a safety case: a structured argument, with evidence, that the system is safe enough.
| Standard | What it covers |
|---|---|
| IEC 61508 | Functional safety of electrical and electronic systems; safety integrity levels SIL 1 to 4. |
| ISO 13849 | Safety parts of machine control systems; performance levels PL a to e. |
| ISO 10218 | Safety of industrial robots and robot cells. |
| ISO/TS 15066 | Robots that work beside people. |
| ISO 26262 | Functional safety of road vehicle electronics; ASIL A to D. |
| ISO 21448 (SOTIF) | Hazards from a function's limits with no fault, such as a missed detection. |
| UL 4600 | The safety case for autonomous products with no human supervisor. |
The failure is safety theatre: an analysis filed once and never checked. The fix is to tie each hazard to a test that runs in CI, so the evidence stays current.
Chapter 9
Run a regression gate for 30 nights and count its wrong calls in both directions
Every night, CI runs the baseline and the candidate through the scenario suite and the gate decides. A gate makes two kinds of wrong call. A false block stops a build that is as good as the baseline. A missed regression ships a build that is worse. You set four knobs: the truth, the runs, the flakes and the strictness.
Each cell is one night. Green is a right call, red a wrong one. Pick a setting, press Run, and compare the red count with the expected rate.
Simulated nights. A flake fails a run at the given rate on both builds. The expected rate uses the normal shortcut from Chapter 5.
Four runs to try, with the expected rate for each:
| Setting | Expected |
|---|---|
| Real drop, 400 runs, z = 2 | caught on 54% of nights |
| Real drop, 1600 runs, z = 2 | caught on 98% of nights |
| Real drop, 400 runs, 5% flakes | caught on 35% of nights |
| No change, z = 1 | false block on 16% of nights |
Strictness trades one error for the other. Flakes hurt both. More runs is the only knob that cuts both at once, and runs cost machine hours. That is why the test engineer's first job is making runs cheap and clean.
Chapter 10
Keep the numbers, the skills, the checklist and the code in one place
A robotics test engineer builds a chain of stages, each of which makes a different part of reality real. Then the engineer measures what the chain says, with error bars, and turns the result into ship or block.
| Idea | Rule | Worked number |
|---|---|---|
| Escape rate | product of (1 − c) over stages | 0.4 × 0.5 × 0.7 = 0.14 |
| Full grid | product of level counts | 34 = 81; pairwise 9 |
| Pass-rate error | √(p(1 − p)/n) | 47 of 50: 84% to 98% (Wilson) |
| Suite red rate | 1 − (1 − f)M | 200 tests, 0.5%: 63% |
| Reruns to clear a flake | ln(1 − C)/ln(1 − F) | 5% at 95%: 59 |
| Gate | block if drop > z × SE | 0.04 > 0.038 at n = 400 |
| Misses per hour | f × 3600 × p | 100 Hz, 0.1%: 360 |
| Zero-failure bound | 3 / T at 95% | 1,000 h: MTBF ≥ 334 h |
| Skill | Used for |
|---|---|
| Python and pytest | Test harnesses, fixtures, scenario runners. |
| CI systems and containers | The same test the same way on every change. |
| Statistics of rates | Error bars, flake detection, gates, safety bounds. |
| Simulators | SIL scenarios and the plant side of HIL. |
| Robot middleware and logs | Recording, cutting and replaying bags. |
| Real-time basics | Deadlines, priorities, latency tails. |
| Reading safety standards | Tying hazards to tests in the safety case. |
pythonimport math def wilson(k, n, z=1.96): # k passes of n runs -> (low, high) p, d = k / n, 1 + z * z / n mid = (p + z * z / (2 * n)) / d half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / d return mid - half, mid + half # wilson(47, 50) -> (0.838, 0.979) def reruns_needed(flake_rate, confidence=0.95): return math.ceil(math.log(1 - confidence) / math.log(1 - flake_rate)) # 0.05 -> 59 def gate(k_base, k_cand, n, z=2.0): # same n runs for each build pb, pc = k_base / n, k_cand / n se = math.sqrt(pb * (1 - pb) / n + pc * (1 - pc) / n) return "block" if pb - pc > z * se else "ship" # gate(376, 360, 400) -> block def zero_failure_bound(hours, confidence=0.95): # failures per hour return -math.log(1 - confidence) / hours # 1000 h -> 0.0030
Now press Present or Teach and explain from memory: what each stage makes real, how to put an error bar on a pass rate, and how a gate trades its two errors. Then go back to the sieve and predict, before you press, how many bugs each set of stages lets through.