Week 4 · Day 17 · 7 hours

Verilog Verification – Self-Checking

Testbenches, self-checking, regression, debugging

Daily plan

What you will learn and practise

Complete the stages in order and retain the requested evidence.

Theory · 2h

Expected-value generation
Reference model concept
Automatic checking
Boundary/corner testing
Result summaries

Guided lab · 2h

1. Self-check adder/MUX/comparator
2. ALU reference model
3. Counter/shift register checkers
4. Timer checker
5. FSM checker

Independent lab · 2h

6. Register-block checking
7. FIFO checker
8. Arbiter checker
9. IRQ controller checker
10. Auto summary TOTAL/PASS/FAIL/ERROR

Debug and assignment · 1h

Inject one DUT bug and prove checker catches it
Write test plan for timer or FIFO

Expected deliverable

Self-checking TB + test plan

Practical work

Extend the reusable Day 16 testbench into a self-checking Verilog environment with an explicit expected-value model, automatic comparisons, boundary/corner tests, error accounting, and a concise test plan.

Setup
  1. Create project_workspace/week4_verilog_verification/day17_self_checking with rtl, tb, sim, logs and docs directories.
  2. Reuse the deterministic clock/reset and PASS/FAIL discipline established on Day 16.
  3. Use plain Verilog verification constructs only; SystemVerilog classes/interfaces, SVA, coverage and UVM are outside Week 4.
Execution steps
  1. Create a parameterized ALU DUT with arithmetic, logical and compare operations suitable for deterministic checking.
  2. Define expected-result generation independently in the testbench rather than copying DUT implementation structure.
  3. Create a reusable check task that compares actual and expected result and updates TOTAL/PASS/FAIL/ERROR counters.
  4. Run nominal directed tests for every supported ALU operation.
  5. Add boundary vectors: all-zero, all-one, maximum positive, sign-boundary and carry/overflow-relevant operands where applicable.
  6. Add repeated vector execution so every check is reported consistently without manual waveform inspection.
  7. Adapt the same checker pattern conceptually to counter, timer, FSM, register block, FIFO, arbiter and IRQ-controller outputs from earlier weeks.
  8. Inject one intentional DUT defect, prove that the checker reports failure, save the failing evidence, restore the DUT and rerun to PASS.
  9. Generate a final TOTAL/PASS/FAIL/ERROR summary and retain log/VCD evidence.
  10. Write a compact timer-or-FIFO test plan mapping requirements to nominal, boundary, negative and error-oriented tests.
Written assignment
  1. Explain the difference between DUT implementation logic and an independent reference/expected-value model.
  2. Prepare a test matrix containing requirement, stimulus, expected result and evidence for at least eight cases.
  3. Explain why boundary and corner tests are necessary even when nominal tests pass.
  4. Document the injected defect, the exact checker failure, root cause and clean rerun result.
Debug challenge

Inject a single functional defect into the ALU (for example, an incorrect operation selection or arithmetic result), demonstrate that the self-checker catches it without relying on visual waveform inspection, then patch and rerun with FAIL=0.

Evidence to retain
  • rtl/alu.v and tb/tb_alu_selfcheck.v
  • logs/day17_selfcheck_fail.log showing the injected defect was detected
  • logs/day17_selfcheck_pass.log showing the corrected DUT passes
  • sim/day17_selfcheck.vcd
  • docs/test_plan.md mapping requirements to tests and expected results
Completion criteria
  • Expected values are generated independently from DUT implementation structure.
  • Nominal and boundary/corner cases are automatically checked.
  • Injected DUT bug produces at least one deterministic FAIL/ERROR result.
  • Corrected DUT rerun reports TOTAL > 0 and FAIL=0.
  • Test plan and simulation evidence are retained in project_workspace.
Technical visuals

Understand the architecture and debug flow

Self-Checking Verification Flow
Self-Checking Verification Flow
Independent expected-value generation is compared automatically with DUT output.
Injected-Bug Detection Proof
Injected-Bug Detection Proof
The unchanged checker must expose the defect before patching and then prove the clean rerun.
Executable lab

Build, run and retain evidence

project_workspace/week4_verilog_verification/day17_self_checking/

Required files
  • rtl/alu.v
  • tb/tb_alu_selfcheck.v
  • sim/day17_selfcheck.vvp
  • sim/day17_selfcheck.vcd
  • logs/day17_selfcheck_pass.log
  • docs/test_plan.md
Mandatory tests
  • Every documented ALU operation has at least one nominal self-checking test.
  • Zero, all-one and arithmetic boundary vectors are exercised.
  • Expected result is computed in the testbench and compared automatically.
  • TOTAL/PASS/FAIL/ERROR counters are printed at completion.
  • An intentionally injected DUT bug is detected without manual waveform judgement.
  • After repair, the same regression finishes with FAIL=0.
  • Test-plan entries identify requirement, stimulus, expected result and evidence.
Compile
iverilog -g2012 -Wall -o sim/day17_selfcheck.vvp rtl/alu.v tb/tb_alu_selfcheck.v
Run
vvp sim/day17_selfcheck.vvp | tee logs/day17_selfcheck_pass.log
Waveform
gtkwave sim/day17_selfcheck.vcd
PASS criteria
  • Compile completes without errors.
  • Injected-bug run records a deterministic checker failure.
  • Clean run reports TOTAL > 0, PASS = TOTAL and FAIL = 0.
  • Boundary/corner cases are present in the retained test list.
  • Test plan, logs and waveform are retained under project_workspace.
Knowledge check

Review before completing Day 17

  1. Concept

    What makes a Verilog testbench self-checking?

    Review answer

    It generates or stores expected behavior, compares DUT outputs automatically, records pass/fail status, and produces an objective summary without requiring a person to judge every waveform.

  2. Reasoning

    Why should a reference model avoid simply duplicating the DUT implementation?

    Review answer

    Duplicating the same structure can reproduce the same design mistake in both places. An independently expressed expected model improves the chance that implementation defects are detected.

  3. Coverage reasoning

    What is the purpose of boundary and corner tests on Day 17?

    Review answer

    They exercise values and transitions where width, sign, carry, reset, limit and state-related defects commonly appear even when ordinary nominal vectors pass.

  4. Debug

    What evidence proves that the checker itself is capable of detecting a defect?

    Review answer

    An intentionally injected DUT defect must produce a deterministic FAIL/ERROR result, followed by a corrected DUT run using the same checker that finishes with FAIL=0.

Skills and assessment traceability

Self-checking Verilog verification

  • Generate expected values independently from DUT implementation.
  • Automate actual-versus-expected comparison and result accounting.
  • Design nominal, boundary and corner tests from requirements.
  • Demonstrate checker effectiveness through controlled defect injection.
  • Produce a requirement-to-test plan and retain reproducible evidence.

Assessment: Week 4 automated self-checking testbench, injected-bug detection, test-plan evidence