---
title: Testing and fault models
heading: Finding the chips that came out of the factory broken
eyebrow: C7 · Lesson 32 · Testing and fault models
xp: 40
---

::: hook
Every wafer has defects: a speck of dust, a short between wires, a missing contact. Some chips come out broken, and the only way to find them is to apply inputs and compare the outputs with what a good chip would give. A chip with millions of gates can't be tested exhaustively, so test engineers use a model of what goes wrong, choose inputs that would expose each modeled fault, and design the chip so those inputs can reach deep inside.

::: play
- The circuit computes $y = AB + C$. Switch F on to break it: the AND gate's output becomes stuck at 0.
- With the fault on, compare y with the fault-free output y0 in the table. Which input rows show a difference?
- Only those rows are tests for this fault. Find the one input that exposes it.
:::
:::

```sim logic
input A, B, C, F
output y, y0
assign y = (A & B & ~F) | C
assign y0 = (A & B) | C
table: on
```

::: predict
## In $y = AB + C$, the AND gate's output is stuck at 0. Which input exposes the fault?

- [ ] A = 0, B = 0, C = 0
- [x] A = 1, B = 1, C = 0
- [ ] A = 1, B = 1, C = 1
- [ ] Any input with C = 1

::: reveal
A = 1, B = 1, C = 0. The test must do two things: **excite** the fault, by making the good AND output 1 so that stuck-at-0 differs from it (A = B = 1), and **propagate** the difference to the output, by holding the OR's other input at 0 (C = 0) so the OR passes it through. With C = 1 the output is 1 either way and the fault hides.
:::
:::

::: nameit
## The stuck-at model

Each node of the circuit might be **stuck at 0** or **stuck at 1**: two faults per node. Real defects (shorts, opens, slow transitions) are more varied, but tests that catch every stuck-at fault catch most of them too. A test vector detects a fault if the faulty circuit's output differs from the good one's; finding it means **exciting** the fault (driving the node to the opposite value) and **propagating** the difference to an output (setting the other inputs of every gate on the way so they pass it).

## Coverage and defect level

**Fault coverage** is the fraction of modeled faults the test set detects. Untested faults let some bad chips escape. With a manufacturing yield Y (the fraction of good chips) and coverage FC, the fraction of shipped chips that are bad is about

$$DL = 1 - Y^{1 - FC},$$

the Williams–Brown defect level, usually quoted in parts per million.

## Design for test

- **Scan:** every flip-flop gets a multiplexer that, in test mode, links them into a long shift register. Patterns are shifted in, one clock captures the logic's response, and the result is shifted out. Sequential logic becomes combinational logic for testing.
- **Built-in self-test (BIST):** an LFSR (lesson 31) generates pseudorandom patterns on the chip, and a multiple-input signature register compresses the responses into one word to compare with the good chip's signature.
:::

::: example
## Find a minimal test set for all ten single stuck-at faults of $y = AB + C$ (A, B, C, the AND output n, and y).

::: solution
1. **Vector 110.** It excites n stuck-at-0 and also exposes A and B stuck-at-0 and y stuck-at-0: four faults, 40% coverage.
2. **Vector 010.** The good output is 0, so it exposes A stuck-at-1 (n becomes 1), n stuck-at-1, C stuck-at-1 and y stuck-at-1.
3. **Vector 100.** It exposes B stuck-at-1.
4. **Vector 001.** It exposes C stuck-at-0.
5. **Put them together.** {110, 010, 100, 001} detect all ten: four vectors instead of all eight.

**Answer:** {110, 010, 100, 001}, four vectors.
:::
:::

::: example
## A chip has a yield of 90%. What defect level ships with 95% fault coverage, and with 99%?

::: solution
1. **At 95% coverage.**
   $$\begin{aligned} DL &= 1 - 0.9^{0.05} \\ &= 0.53\% \end{aligned}$$
   or 5250 parts per million.
2. **At 99% coverage.**
   $$\begin{aligned} DL &= 1 - 0.9^{0.01} \\ &= 0.11\% \end{aligned}$$
   or 1050 ppm.
3. **Why the last percent matters.** Each extra percent of coverage near the top removes a large share of the escapes, which is why automotive parts, which aim at a few ppm, push coverage close to 100%.
4. **At a lower yield.** At 50% yield, the same 95% coverage would ship 3.4% bad parts.

**Answer:** 0.53% (5250 ppm) at 95% coverage, and 0.11% (1050 ppm) at 99%.
:::
:::

::: example
## A chip has 10,000 scan flip-flops in 10 chains of 1000, and needs 2000 patterns. At a 50 MHz scan clock, how long does the test take?

::: solution
1. **Clocks per pattern.** Each pattern shifts 1000 bits into every chain at once (the next pattern's shift-in overlaps the last one's shift-out), so about 1000 clocks per pattern.
2. **Total clocks.**
   $$2000 \times 1000 = 2 \times 10^6$$
3. **Time.**
   $$\frac{2 \times 10^6}{50\ \text{MHz}} = 40\ \text{ms}$$
4. **Why it matters.** Test time is money on an expensive tester, so designs use many short chains and compress the patterns on the chip.

**Answer:** about 40 ms.
:::
:::

::: check
kind: parts
given: Y = 0.5 | 0.8 | 0.95; FC = 0.9 | 0.98 | 0.999

## A chip yields {Y} and is tested with {FC} fault coverage.

::: part
answer: (1 - Y^(1 - FC))*1e6
unit: ppm
tolerance: 0.5%

### What defect level ships?

::: misses
- [(1 - Y)*(1 - FC)*1e6] Use the Williams–Brown formula, $1 - Y^{1 - FC}$.
- [any] $DL = 1 - Y^{1 - FC}$.
:::
:::

::: part
answer: (1 - Y)*1e6
unit: ppm
tolerance: 0.5%

### How many bad parts per million would ship with no testing at all?

::: misses
- [any] Coverage 0 gives $1 - Y$.
:::
:::
:::

::: check
kind: parts
given: N = 2000 | 50000; c = 10 | 50; p = 1000 | 5000; f = 25 | 100

## A chip has {N} scan flip-flops in {c} equal chains and needs {p} patterns, shifted at {f} MHz.

::: part
answer: N/c
tolerance: 0

### How long is each chain?

::: misses
- [any] $\frac{N}{c}$.
:::
:::

::: part
answer: p*N/c/(f*1e6)*1000
unit: ms
tolerance: 0.5%

### About how long does the test take?

::: misses
- [p*N/(f*1e6)*1000] The chains shift in parallel.
- [any] Patterns × chain length × clock period.
:::
:::
:::

::: check
given: n = 10 | 1000 | 100000
answer: 2*n
tolerance: 0

## A netlist has {n} nodes. How many single stuck-at faults does the model list?

::: right
Right: two per node, {answer}.
:::

::: misses
- [n] Each node can be stuck at 0 or at 1.
- [any] Two per node.
:::
:::

::: check
kind: choice

## A test for a stuck-at-1 fault on input A of a two-input AND gate must set:

- [ ] A = 1, B = 1
- [x] A = 0, B = 1
- [ ] A = 0, B = 0
- [ ] A = 1, B = 0

::: right
Right. A = 0 excites the fault (the good value differs from the stuck 1), and B = 1 lets the AND pass the difference.
:::

::: misses
- [1] With A = 1 the good and faulty A agree: nothing is excited.
- [3] With B = 0 the AND outputs 0 either way: the fault doesn't propagate.
- [4] A = 1 doesn't excite it, and B = 0 blocks it.
:::
:::

::: check
kind: derivation
vars: Y = 0.1..0.99, F = 0.5..0.99999, D = 0.000001..0.01

## A chip yields Y and is tested with fault coverage F.

::: step
answer: 1 - Y^(1 - F)

### What fraction of shipped chips is bad?
:::

::: step
answer: 1 - ln(1 - D)/ln(Y)

### What coverage achieves a defect level D?
:::

::: right
Right. The required coverage climbs toward 1 as the target defect level falls.
:::
:::

::: check
kind: python

## Write `coverage(tests)` for the circuit $y = AB + C$: each test is a 3-bit integer ABC (A the top bit); consider the ten single stuck-at faults on A, B, C, n = AB and y, and return the fraction detected.

```python starter
def coverage(tests):
    return len(set(tests)) / 8

print(coverage([0b110]))
```

```python solution
def evaluate(v, fault=None):
    a, b, c = (v >> 2) & 1, (v >> 1) & 1, v & 1
    if fault and fault[0] == 'A': a = fault[1]
    if fault and fault[0] == 'B': b = fault[1]
    if fault and fault[0] == 'C': c = fault[1]
    n = a & b
    if fault and fault[0] == 'n': n = fault[1]
    y = n | c
    if fault and fault[0] == 'y': y = fault[1]
    return y

def coverage(tests):
    faults = [(node, s) for node in 'ABCny' for s in (0, 1)]
    found = [f for f in faults if any(evaluate(t, f) != evaluate(t) for t in tests)]
    return len(found) / len(faults)

print(coverage([0b110]))
```

```python tests
assert abs(coverage([0b110]) - 0.4) < 1e-12, f"110 alone detects 4 of 10; got {coverage([0b110])}"
assert abs(coverage([0b110, 0b010, 0b100, 0b001]) - 1.0) < 1e-12, "The four-vector set detects all ten."
assert abs(coverage([0b110, 0b010, 0b100]) - 0.9) < 1e-12, "Without 001, C stuck-at-0 escapes."
```

::: right
Right. Fault simulation, inject each fault and compare, is exactly what test tools do, on millions of nodes.
:::
:::

::: explain
## Why does a test vector for a fault have to both excite the fault and propagate it?

::: model
A fault only matters if it makes the circuit compute something different. To see a stuck-at-0 fault on a node, the test must drive that node to 1 in the good circuit, otherwise the good and faulty circuits agree there and nothing is different to see. Then the difference has to reach an output: every gate between the node and the output must have its other inputs set so it passes the change through, like a 1 on the other input of an AND or a 0 on the other input of an OR. If any gate on the way masks it, the outputs agree and the fault stays hidden, so a test must do both at once.
:::
:::

::: practice

::: check
given: Y = 0.6 | 0.9; FC = 0.95 | 0.995
answer: (1 - Y^(1 - FC))*1e6
unit: ppm
tolerance: 0.5%

## Yield {Y}, coverage {FC}. Defect level?

::: misses
- [any] $1 - Y^{1 - FC}$.
:::
:::
:::
