Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Start Here6
    • Who This Course Is For
    • How the Lessons and Examples Work
    • Words You Will Meet
    • The Testbench Picture
    • The PacketFIFO Project
    • What the Open Simulators Run
  • SystemVerilog Language Foundations35
  • Object-Oriented SystemVerilog for Verification35
  • Constraint Randomization — Interview-Critical Deep Dive66
  • SystemVerilog Assertions — Interview-Critical Deep Dive63
  • Functional Coverage in SystemVerilog28
  • Testbench Architecture in SystemVerilog38
  • Advanced Language & Integration30
  • Senior & Interview Preparation34
  • Principal-Level Verification28
Loading lesson

‹Start Here
  1. Topics
  2. SystemVerilog
  3. Start Here
  4. How the Lessons and Examples Work

Part 0 · Start Here · Beginner

How the Lessons and Examples Work

The parts of a lesson, how to run an example in Code Lab, how to read its verdict, and what not run means.

On this page

    Why this matters

    A testbench that has never failed has never been tested. Knowing how to run an example, read its verdict and break it on purpose is what makes every later lesson worth trusting.

    After this lesson you can: run a lesson example in Code Lab, read its PASS or FAIL line and exit status, and plant a bug to prove the testbench can fail.

    The parts of a lesson

    Most lessons follow the same order, so you always know where you are.

    Block

    What it is for

    Why this matters

    The problem the lesson solves, and what you can do after it.

    Predict first

    A question asked before the answer or the run. Commit to an answer, then open it.

    Terminal

    The output the simulator really printed when the example ran.

    Common pitfall and Interview

    The mistake people make, and how the idea is asked in interviews.

    Check yourself

    A question after the idea, to test that it stuck.

    Project step

    One optional piece of the PacketFIFO project that uses this lesson.

    Remember

    Three lines to keep. The part hubs collect them into a revision sheet.

    How this was checked

    Collapsed. Which simulator ran the example, and what the run does not prove.

    Running an example

    A complete example has a design and a testbench in one listing. Its code block has an Open in Code Lab button that copies it into the editor, where you pick a simulator and run it.

    From listing to verdict. The last step, breaking a line on purpose, is the one that teaches you to trust a testbench.

    Simulator

    Use it for

    Icarus Verilog 13

    Plain Verilog, and examples that show X values (it models 0, 1, X and Z).

    Verilator 5.048

    Classes, randomization, assertions and most SystemVerilog. It models only 0 and 1, so X shows as 0.

    Each listing that needs a particular simulator says so. When neither free simulator can run a listing, the lesson says what is missing, and it never shows invented output.

    Reading the verdict

    Every runnable testbench in the course ends the same way: one line that starts with PASS or FAIL. The FAIL branch uses $fatal, which also makes the simulator exit with an error status, so a script running many tests sees the failure too.

    majority3.v
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    module majority3 (
      input  wire a,
      input  wire b,
      input  wire c,
      output wire y
    );
      assign y = (a & b) | (a & c) | (b & c);
    endmodule
    
    module tb_majority3;
      reg a, b, c;
      wire y;
      integer i;
      integer errors = 0;
      majority3 dut (.a(a), .b(b), .c(c), .y(y));
      initial begin
        for (i = 0; i < 8; i = i + 1) begin
          {a, b, c} = i[2:0];
          #1;
          if (y !== ((a + b + c) >= 2)) begin
            errors = errors + 1;
            $display("  mismatch: a=%b b=%b c=%b y=%b", a, b, c, y);
          end
        end
        if (errors == 0) $display("PASS: majority3 matched the reference on all 8 inputs");
        else $fatal(1, "FAIL: majority3 differed on %0d of 8 inputs", errors);
        $finish;
      end
    endmodule
    Terminal
    PASS: majority3 matched the reference on all 8 inputs

    Verilator printed this, and exited with status 0:

    Terminal
    PASS: majority3 matched the reference on all 8 inputs
    - majority3.sv:27: Verilog $finish

    Break it on purpose

    A testbench that cannot fail proves nothing. So the course often asks you to plant a bug and run again. Here, change (a & c) to (a | c) in the design.

    Predict first How many of the 8 input combinations will now disagree with the reference?

    Two. a | c is 1 whenever a or c is 1. It only changes the answer when exactly one of a and c is 1 and b is 0: inputs 001 and 100.

    With the planted bug, Verilator printed this and exited with status 1:

    Terminal
    mismatch: a=0 b=0 c=1 y=1
      mismatch: a=1 b=0 c=0 y=1
    [8] %Fatal: majority3.sv:26: Assertion failed in tb_majority3: FAIL: majority3 differed on 2 of 8 inputs
    %Error: majority3.sv:26: Verilog $stop
    Aborting...

    Common pitfall

    Trusting a PASS you have never seen turn into a FAIL. A checker can be wired to the wrong signal, compare the design with itself, or never run at all, and it still prints PASS. Break one line and watch it fail once.

    Check yourself A run prints no PASS line and no FAIL line, then stops. Did the test pass?

    No. A missing verdict is a failure: the run crashed, hung or ended early. Only a PASS line, with an exit status of 0, counts as a pass.

    Remember

    • Every runnable bench ends in one PASS or FAIL line; FAIL uses $fatal, so the exit status is non-zero.

    • Icarus models X values; Verilator runs classes, randomization and assertions but shows X as 0.

    • Break one line on purpose and watch the bench fail before you trust its PASS.

    Rule of thumb: no verdict line means the test failed.

    How this was checked

    Run with Icarus Verilog 13 (iverilog -g2012) and Verilator 5.048 (--binary --timing) on 2026-10-18; both printed the PASS line shown, with no warnings.

    The planted bug ((a | c) in place of (a & c)) was run on Verilator 5.048: it printed the two mismatches and the $fatal line shown, and exited with status 1. Icarus 13 reported the same two mismatches.

    Related topics

    • Next: Words You Will Meet

    • Self-Checking Discipline (Part 7)

    Previous

    2 / 363

    Next: Words You Will Meet

    Up next

    Up nextWords You Will Meet

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • The Testbench Picture
    • The PacketFIFO Project
    • What the Open Simulators Run