What is Constrained random verification?

Verification that generates random input values within constraints allowed by the specification, broadly exercising cases people might not think of.

Field: HDL & Verification

Japanese name: 制約付きランダム検証

How it works

The conditions that the inputs must satisfy are written in the testbench as constraints. Examples are 'the address is a multiple of 4' and 'the length is from 1 to 256'. The simulator builds inputs by choosing randomly among the values that satisfy the constraints. Running with a different random seed exercises a different sequence of inputs. Expected values are hard to write by hand, so outputs are checked automatically. A reference model is used for this, or assertions, which state conditions that must hold. SystemVerilog has features for this built into the language.

Combining with coverage

With random inputs it is not obvious which cases were exercised. The cases to be exercised are therefore listed in advance, and whether each one occurred is recorded. This record is called functional coverage. If some cases have not occurred, the constraints are changed or directed tests, whose inputs are chosen by a person, are added. When a failure appears, the seed is recorded. As long as the testbench, the design and the simulator are unchanged, the same seed reproduces the same inputs.

Conditions that are hard to hit

Random choice rarely hits narrow conditions. If an 8-bit value is chosen uniformly, the probability that it is 255 is 1 in 256. The probability that a 32-bit value equals one particular value is about 1 in 4.3 billion. Boundary values such as the maximum and 0 are prone to bugs, so their share is weighted to make them more likely to be chosen. The constraints themselves also need care. If they are too tight, part of the legal input space does not appear and that part goes unverified.

Try it: questions about Constrained random verification

Which describes constrained random verification in SystemVerilog?

  1. AInput values are generated randomly within constraints allowed by the specification, broadly exercising cases people might not think of
  2. BInput values are generated completely at random, including many values outside the specification
  3. CPeople write every input value by hand
Show answer and explanation

Answer: A. Input values are generated randomly within constraints allowed by the specification, broadly exercising cases people might not think of

Tests people devise (directed tests) tend to miss bugs in combinations the designer did not anticipate. Constrained random verification states constraints such as "addresses are multiples of 4" or "length is 1 to 256" and generates random inputs within them, exercising many cases with only meaningful inputs. Coverage measures which cases were hit, and gaps are filled by adjusting constraints or adding directed tests.

FAQ

Do directed tests, whose inputs are chosen by a person, become unnecessary?

No. Directed tests suit basic checks during design bring-up and conditions that random choice rarely hits. The two are used together.

Would fully random inputs without constraints not work?

In most cases they are inefficient. For inputs the specification does not allow, the correct behavior is often undefined, so results cannot be judged and the functions deeper inside are seldom reached. To examine the response to illegal inputs, separate constraints that generate them are written.

Books on HDL & Verification Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary