One Chip Test from Reset to Pass

Follow one real test on ap_soc from the moment the power is good to the moment the chip says pass. Meet the firmware, the bench, the console and the pass word, and read every step with numbers measured on the run.

You Will Be Able To

  • Put one chip test in order: power, clocks, resets, first fetch, start-up code, main, register writes, pass word.
  • Say what the firmware does, what the bench does, and how the chip says pass.
  • Read the console and the main keys of a run's result block.
  • Explain why printed text is never the verdict of a chip test.
Lesson
VF.3
Time
28 min
Runs on
Your browser
Check
5 questions

You press run on your first chip test. For a few hundred nanoseconds nothing you wrote has happened yet, and then a line of text appears. This page walks the whole run, step by step, so the line is no longer a surprise.

One Run, Power-Good to PassStep through one real run of first_test.c on ap_soc v1.5. Times in ns come from a probe; cycles are counted by the bench from the release of the bus reset.
  • Test
  • Clock / reset
  • Memory
  • Processor
  • Peripheral
  • Control / FSM
  • Power
  • Reset
  • Data
One Run, Power-Good to PassStep through one real run of first_test.c on ap_soc v1.5. Times in ns come from a probe; cycles are counted by the bench from the release of the bus reset. test Bench clock, supply, resetpin, the program clock reset Clocks and resets PLL locked 165 ns;bus out of reset 375ns memory Boot ROM first fetch 415 ns processor Core start-up code, thenmain at cycle 156 peripheral UART0 and padIO0 byte K on the padfrom cycle 402 control Mailbox pass word at cycle720 power goodreset releasedinstructionsregister writesstatus, charactersverdict
  1. test Benchclock, supply, reset pin, the program
    • power good → Clocks and resets
  2. clock reset Clocks and resetsPLL locked 165 ns; bus out of reset 375 ns
    • reset released → Boot ROM
  3. memory Boot ROMfirst fetch 415 ns
    • instructions → Core
  4. processor Corestart-up code, then main at cycle 156
    • register writes → UART0 and pad IO0
    • status, characters → Mailbox
  5. control Mailboxpass word at cycle 720
    • verdict → Bench
  6. peripheral UART0 and pad IO0byte K on the pad from cycle 402
  1. 13 ns: power is good

    The power-on reset lets go. Every flip-flop is still held in reset while the oscillators start.

  2. 45 to 260 ns: clocks

    The oscillator gives a first clock. The PLL locks at 165 ns, and the system clock moves to it at 260 ns.

  3. 375 and 405 ns: resets let go

    The bus leaves reset first, then the core, so the bus is ready when the core asks for its first instruction.

  4. 415 ns: the first fetch

    The core asks the boot ROM for address 0. Its first instruction retires at cycle 9.

  5. Cycles 9 to 152: start-up code

    It sets the stack and writes 1 to TB_STATUS. Then it copies and clears memory and writes 2: main is about to run.

  6. Cycle 156: main

    The test says hello, reads CHIP_ID at cycle 389 and checks it.

  7. Cycles 398 and 402: two register writes

    PINMUX gives pad IO0 to the UART, and TXDATA starts the byte K. The bench's UART model reads it off the pad.

  8. Cycle 720: the pass word

    main returns 0, and the start-up code writes 0x900D to TB_STATUS. The run ends at cycle 728 with verdict pass.

Read the diagram as text
  • Bench: clock, supply, reset pin, the program
  • Clocks and resets: PLL locked 165 ns; bus out of reset 375 ns
  • Boot ROM: first fetch 415 ns
  • Core: start-up code, then main at cycle 156
  • UART0 and pad IO0: byte K on the pad from cycle 402
  • Mailbox: pass word at cycle 720
  • Bench → Clocks and resets: power good
  • Clocks and resets → Boot ROM: reset released
  • Boot ROM → Core: instructions
  • Core → UART0 and pad IO0: register writes
  • Core → Mailbox: status, characters
  • Mailbox → Bench: verdict

One run of first_test.c on ap_soc v1.5. Cycles from soc_tb on Verilator 5.052 (GCC 14.2, -Os); times in ns from Icarus 12.

Before You Start

Read An SoC as a Verifier Sees It and From IP to Chip to System first. A little C helps: a function, an if statement, a return value. If C registers are new, A Register Is an Address explains them. The companion track shows a test that can fail in The Simplest Test That Can Fail. It shows the four ways a test ends in How a Test Ends.

This site runs ap_soc v1.5 in simulation: Verilator for graded runs, Icarus for small slices. It has no emulator and no FPGA board. The run on this page is a real one: the numbers come from its recording.

Five questions this page answers
Question
1In what order does one chip test happen, from power to pass?
2What does the firmware do, and what does the bench do?
3How does the chip tell the bench that the test passed?
4What do the console and the result block show?
5Why is a line of text never the verdict?

The Idea: A Program on the Chip, Checked from Outside

A chip test with a processor is a small program that runs on the chip itself. That program is the firmware: the code the chip's own processor runs. It drives the chip from the inside, through the same registers a product's software would use. Before its first line runs, the chip must boot: its clocks start, its resets let go, and start-up code prepares memory.

Around the chip sits the bench, the simulated board. It gives the chip its clock, supply and reset pin, loads the program, and watches the pads. The bench decides the result. The firmware cannot declare itself a winner; it can only report, and the bench checks the report against what it saw.

So every run has two sides talking. The firmware writes words into a few special registers, the mailbox. The bench reads those writes and prints them as the console. One of those words, the pass word, is the chip's way of saying "my checks all held".

New Words

New words on this page
WordMeaning
FirmwareThe program the chip's own processor runs. Here, a test written in C.
BenchThe simulated board around the chip: clock, supply, reset, program loading, pad models and checks.
BootWhat happens from reset to the first line of the program: clocks start, resets let go, start-up code runs.
Power-on resetA reset that holds the whole chip while its supply comes up, then lets go.
Oscillator, PLLAn oscillator makes a first, rough clock. A PLL turns a reference clock into the fast system clock; it locks when that clock is steady.
FetchThe core reads its next instruction from memory.
RetireAn instruction retires when it has finished and its result counts.
Retire traceOne record for each retired instruction: its cycle, its address, the instruction and what it changed.
StackMemory a C program uses for local variables and return addresses.
Start-up codeThe few instructions before main that set the stack and prepare memory.
CycleOne tick of the system clock, clk_sys, here 10 ns. The bench counts cycles from the bus reset.
MailboxFour registers in ap_sysctl that the firmware writes and the bench watches.
ConsoleThe text the firmware writes to the mailbox one character at a time. The bench prints each line.
Pass wordThe value 0x900D written to TB_STATUS: the test says all its checks held.
Fail word0xBAD0_0000 plus a code: the test says which check failed.
Result blockThe lines the bench prints at the end: the verdict, the reason and counters.
CheckerBench code that watches signals and reports a broken rule, such as a wrong bus transfer.
Cycle limitThe longest a run may last. A run that reaches it without a verdict fails.
UART frameOne byte on a serial line. A start bit at 0, eight data bits with the low bit first, then a stop bit at 1.
Reference modelA program that predicts what each instruction should do, so the bench can compare.

The Test Itself, Read by Hand

Here is the whole test. Read it as a list of requests to the chip. For each one, ask what the bench can see.

first_test.c, built with the firmware kit for the ROM layout: the program sits in the boot ROM.
/* first_test.c: say hello, check the chip's identity, send one byte out of a pad, pass. */
#include "hal.h"
#include "tb.h"

int main(void)
{
    tb_puts("hello from ap_soc\n");                    /* a console line */
    unsigned id = reg_read32(SYSCTL_CHIP_ID);          /* read a register */
    if (id != 0x2A5310C5u) {
        tb_puts("wrong chip\n");
        return 1;                                      /* fail word 0xBAD00001 */
    }
    reg_write32(SYSCTL_PINMUX, 2);                     /* pad IO0 now carries UART TX */
    unsigned byte = 'K';
    reg_write32(UART0_TXDATA, byte);                   /* one byte leaves the chip */
    while ((reg_read32(UART0_STATUS) & UART0_STATUS_ROOM_MASK) == 0) { }
    tb_puts("byte sent\n");
    return 0;                                          /* pass word 0x900D */
}
What each part does, and what the bench sees
LineThe chip doesThe bench sees
tb_puts("hello ...")Writes 18 characters to TB_PUTC in the mailboxOne console line
reg_read32(SYSCTL_CHIP_ID)Reads the chip's identity registerNothing directly; the test checks it
return 1 on a wrong identityStart-up code writes the fail word 0xBAD0_0001Verdict fail, code 1
reg_write32(SYSCTL_PINMUX, 2)Gives pad IO0 to the UARTThe pad is driven high, idle
reg_write32(UART0_TXDATA, byte)Starts one byte on the UARTTen bit times on pad IO0: the byte K
while (... ROOM ...)Waits until UART0 has sent the whole frameNothing; it only waits
return 0Start-up code writes the pass word 0x900DVerdict pass, if nothing else went wrong

Count the console bytes before you look at the run. "hello from ap_soc" plus its newline is 18; "byte sent" plus its newline is 10. The result block should say console_bytes = 28.

The Rules

  1. Rule 1: The bench owns the clock, the reset and the verdict.

    The firmware cannot end a run as a pass by itself.

  2. Rule 2: The firmware reports through the mailbox.

    Console text is only text. The verdict comes from TB_STATUS.

  3. Rule 3: A pass needs three things.

    TB_STATUS = 2 (main ran) first, then the pass word, and no checker error during the run.

  4. Rule 4: Every run ends one way.

    A checker error, a fail word, the cycle limit, a stall with no progress, or the pass word. The first one decides.

Sources for These Rules

The bench's end of test, its order of authority and the mailbox: tools/soc/ap_soc/bench/soc_tb/README.md; docs/soc/ap_soc-facts.md 27.12.

The power-up numbers of the clock and reset block: docs/soc/ap_soc-facts.md 27.1 and 27.11.

Why software must run with the RTL before a chip is ready: Mehta, ASIC/SoC Functional Design Verification, section 12.1.

Now Run It: The Recorded Run

The test ran on the chip bench used by the problems of this track. The bench printed two console lines, each with the cycle of its newline:

The bench's console lines (soc_tb on Verilator 5.052; GCC 14.2, -Os).
CONSOLE 375: hello from ap_soc
CONSOLE 691: byte sent

Walk the timeline at the top of the page with the rules. Power is good at 13 ns, the PLL locks at 165 ns, and the bus leaves reset at 375 ns. The core follows at 405 ns and fetches its first instruction at 415 ns. From here the bench counts cycles.

Start-up code writes 1 to TB_STATUS at cycle 23 and 2 at cycle 152: rule 3's first condition. main starts at cycle 156, and the hello line is complete at cycle 375. The identity read returns 0x2A53_10C5 at cycle 389.

Then the two register writes, at cycles 398 and 402. A probe, bench code that only reads signals, saw pad IO0 fall for the start bit at cycle 402. Its last edge, the stop bit, came at cycle 546, nine bit times later. Each bit took 16 cycles, the reset value of UART0's divider. The test polled ROOM 24 times while the frame went out.

Six records of the retire trace: cycle, address of the instruction, instruction, effect.
   23 | 00000028 | sw t1, 0(t0)               | mem[10004020] = 00000001
  152 | 00000088 | sw t1, 0(t0)               | mem[10004020] = 00000002
  389 | 00000258 | lw a4, 0(a5)               | x14 = 2a5310c5, read mem[10004000] = 2a5310c5
  398 | 00000288 | sw a4, 16(a5)              | mem[10004010] = 00000002
  402 | 00000294 | sw a4, 0(a5)               | mem[10000000] = 0000004b
  720 | 00000200 | sw a5, 32(a4)              | mem[10004020] = 0000900d

Now read the result block, before the console, as rule 2 asks:

Keys of the result block
KeyValueMeaning
verdict, reasonpass, passHow the run ended, by the bench's rules
status0x0000900DThe word that ended the test: the pass word
main_entered1TB_STATUS = 2 was seen: the test really started
cycles, retired728, 354Cycles from the bus reset to the end; instructions finished
compares, mismatches354, 0Instructions checked against the reference model; how many differed
checker_errors0Errors from the checkers: broken bus rules and failed block checks
uart_bytes, uart_frames1, 1What the bench's UART model received on pad IO0
console_bytes28Characters written to the console
visited0099Regions touched: bit 0 ROM, 3 SRAM, 4 UART0, 7 ap_sysctl

Measured on soc_tb (Verilator 5.052; GCC 14.2, -Os). cycles and retired change with the compiler; the verdict does not.

Every key agrees with the reading by hand. Twenty-eight console bytes, one byte on the pad, the pass word, and every instruction matched the reference model.

A Slice of the Bench's Decision

The lab at the end of this page replays this run's own mailbox writes, taken from its trace. It applies rules 2 to 4. It builds the console from TB_PUTC, notes main, and stops at the first pass or fail word.

Printed by the lab (Icarus 12). It uses the cycle each store retired, so its console cycles can be one later than the bench's.
console 376: hello from ap_soc
console 692: byte sent
verdict 720: pass

Now delete the pass word from the list and run it again. Both console lines still print, and still look fine. Yet the verdict becomes a fail at the cycle limit, because no pass word ever came.

Why It Is Built This Way

Why a mailbox and not the UART for the verdict? A mailbox write is one bus transfer and works before any device is set up. A UART byte costs a whole frame on the pad, here from cycle 402 to past cycle 546. It also needs the pin mux first.

Why does the test check the chip itself, with the identity compare? Because only the firmware knows what it meant to happen. The bench checks what it can see from outside: the pad, the mailbox, the bus rules and the reference model. Together they leave little room for a false pass.

Traps

The first trap is believing the console. A test can print every line you hoped for and still fail, as the slice shows. Read verdict and reason first, then the counters, and only then the text.

The second trap is a test that passes without doing its work. Delete the TXDATA write and this test still returns 0. That is why the bench also counts the bytes on the pad, and why the problems of this track grade them.

The third trap is reading a slow first step as a broken chip. The first instruction does not retire until cycle 9 after the bus reset. That wait is boot, not a bug. The lesson on the first run shows how to climb from clocks to main when nothing prints at all.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. This run takes 728 cycles from the bus reset.

  1. Long boots

    A product boot loader can run millions of cycles before main. Teams keep a short boot for most tests and test the full one separately.

  2. Many tests, one image style

    A regression runs thousands of such tests. Each one reports through the same mailbox, so one bench decides them all the same way.

  3. First silicon

    On real chips, the same kind of test is often the first program run. The verdict then comes over a UART or a debugger.

Where This Goes Next

Each step of this tour has a lesson of its own later in the track. Start with the practice problem: change this test yourself.

Where to go from here
LessonWhat it adds
The Flow From Hand-Off to Sign-OffThe phases of a project, from the hand-off package to sign-off.
The First RunThe first run in depth: the console, the trace and the waves, and what to do when nothing prints.
Before mainStart-up code and the linker script, line by line.
The Life of a C TestThe life of a C test, stage by stage.
Parameters From the BenchParameters from the bench, as the practice problem uses one.
Ending a Test HonestlyEnding a test honestly: every way a run can end.

Try It

Run the slice and compare its console lines with the bench's lines above.

Delete the pass word, the last write in the list, and predict the verdict before you run it.

Change the 2 written to TB_STATUS into a 3, and predict what the pass word now means.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: console 376: hello from ap_soc console 692: byte sent verdict 720: pass

Check Yourself

Predict the outputThe pass word is removed from the run's mailbox writes. What is the last line the slice prints?
// The mailbox writes one run of first_test.c made, in order, from its retire trace (cycle, offset in
// ap_sysctl, data). A slice of the bench's end-of-test rules: the console is only text; the verdict
// comes from TB_STATUS. A pass needs "main entered" first; with no pass or fail word, the cycle limit ends the run.
module tb;
  localparam int N = 30, LIMIT = 400000;
  int cycle [N]; logic [7:0] offset [N]; logic [31:0] data [N];
  string line = ""; bit main_entered = 0, done = 0;
  initial begin
    cycle[0] = 23; offset[0] = 8'h20; data[0] = 32'h00000001;
    cycle[1] = 152; offset[1] = 8'h20; data[1] = 32'h00000002;
    cycle[2] = 172; offset[2] = 8'h24; data[2] = 32'h00000068;
    cycle[3] = 184; offset[3] = 8'h24; data[3] = 32'h00000065;
    cycle[4] = 196; offset[4] = 8'h24; data[4] = 32'h0000006c;
    cycle[5] = 208; offset[5] = 8'h24; data[5] = 32'h0000006c;
    cycle[6] = 220; offset[6] = 8'h24; data[6] = 32'h0000006f;
    cycle[7] = 232; offset[7] = 8'h24; data[7] = 32'h00000020;
    cycle[8] = 244; offset[8] = 8'h24; data[8] = 32'h00000066;
    cycle[9] = 256; offset[9] = 8'h24; data[9] = 32'h00000072;
    cycle[10] = 268; offset[10] = 8'h24; data[10] = 32'h0000006f;
    cycle[11] = 280; offset[11] = 8'h24; data[11] = 32'h0000006d;
    cycle[12] = 292; offset[12] = 8'h24; data[12] = 32'h00000020;
    cycle[13] = 304; offset[13] = 8'h24; data[13] = 32'h00000061;
    cycle[14] = 316; offset[14] = 8'h24; data[14] = 32'h00000070;
    cycle[15] = 328; offset[15] = 8'h24; data[15] = 32'h0000005f;
    cycle[16] = 340; offset[16] = 8'h24; data[16] = 32'h00000073;
    cycle[17] = 352; offset[17] = 8'h24; data[17] = 32'h0000006f;
    cycle[18] = 364; offset[18] = 8'h24; data[18] = 32'h00000063;
    cycle[19] = 376; offset[19] = 8'h24; data[19] = 32'h0000000a;
    cycle[20] = 584; offset[20] = 8'h24; data[20] = 32'h00000062;
    cycle[21] = 596; offset[21] = 8'h24; data[21] = 32'h00000079;
    cycle[22] = 608; offset[22] = 8'h24; data[22] = 32'h00000074;
    cycle[23] = 620; offset[23] = 8'h24; data[23] = 32'h00000065;
    cycle[24] = 632; offset[24] = 8'h24; data[24] = 32'h00000020;
    cycle[25] = 644; offset[25] = 8'h24; data[25] = 32'h00000073;
    cycle[26] = 656; offset[26] = 8'h24; data[26] = 32'h00000065;
    cycle[27] = 668; offset[27] = 8'h24; data[27] = 32'h0000006e;
    cycle[28] = 680; offset[28] = 8'h24; data[28] = 32'h00000074;
    cycle[29] = 692; offset[29] = 8'h24; data[29] = 32'h0000000a;
    for (int i = 0; i < N && !done; i++) begin
      if (offset[i] == 8'h24) begin                         // TB_PUTC: one character of the console
        if (data[i][7:0] == 8'h0a) begin $display("console %0d: %s", cycle[i], line); line = ""; end
        else line = $sformatf("%s%c", line, data[i][7:0]);
      end else if (data[i] == 32'h2) main_entered = 1;       // TB_STATUS = 2: start-up code reached main
      else if (data[i] == 32'h900d) begin
        if (main_entered) $display("verdict %0d: pass", cycle[i]);
        else $display("verdict %0d: fail, a pass word before main", cycle[i]);
        done = 1;
      end else if (data[i][31:16] == 16'hbad0) begin $display("verdict %0d: fail, code %0d", cycle[i], data[i][15:0]); done = 1; end
    end
    if (!done) $display("verdict %0d: fail, the cycle limit ended the run", LIMIT);
  end
endmodule
ConceptWhich comes first in a run of ap_soc?
ConceptWho decides that a run passed?
ConceptThe result block shows reason = checker, and the console shows every expected line. Did the test pass?
ConceptWhat does the pass word mean?

Common Mistakes

Wrong Call a run passed because the console looks right.

The console is only what the firmware wrote.

Fix Read verdict and reason first.

Wrong Let the firmware decide the result alone.

A test can skip its work and still return 0.

Fix Have the bench check effects it can see: pads, bus rules, the model compare.

Wrong Count cycles from time 0.

Power-up takes a fixed time no test can change.

Fix Count from the bus reset, as the bench does.

Remember

  • A chip test is firmware on the chip and a bench around it.
  • Order: power good, clocks, resets, first fetch, start-up code, main, register writes, pass word.
  • The firmware reports through the mailbox; the bench prints the console and decides.
  • Read the result block before the console: text is never the verdict.

Practice

Report a problem with this page