# How to write SV checker for verifying if a DUT produced right image

**URL:** <https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [July 12, 2020, 3:56pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832 "2020-07-12T15:56:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![n347](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/9de0a6/32.png) [@n347](https://verificationacademy.com/forums/u/n347)\
**Post date:** [July 12, 2020, 3:56pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/1 "2020-07-12T15:56:18Z")

</div>

Suppose a DUT is producing image as below.

9x9 image with each pixel can be a enumerated value (typedef enum {on,off,random} pixel\_t}.

1. the number of off has to be less than 10%.
2. The 3x3 array’s internal to 9x9 image should not have all off pixels.

I understand how to write constraints to generate this image, but how to verify if DUT is producing the image corectly?

Any idea/hints/suggestion?

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [July 12, 2020, 8:13pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/2 "2020-07-12T20:13:14Z")

</div>

_In reply to [n347](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832):_

Since the image is generated using an algorithm imposed on the input data, isn’t the comparison of the generated DUT image with an image generated by simulation of the algorithm sufficient?

If you are talking about a randomly generated image, you can impose that image against a reference model that creates the expected results.  
If you only want to check that the statistics on the quality of the image produced (_the items 1 and 2 in your list_), then a simple count of the types of pixels produced should be sufficient. Of course, that does not guarantee that the filtering requirements are met.

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [Home - My cvcblr](http://cvcblr.com/home)

- SVA Handbook 4th Edition, 2016 ISBN 978-1518681448
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

1. SVA Alternative for Complex Assertions  
[Verification Horizons - March 2018 Issue | Verification Academy](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
2. [SVA: Package for dynamic and range delays and repeats | Verification Academy](https://verificationacademy.com/forums/systemverilog/sva-package-dynamic-and-range-delays-and-repeats)
3. SVA in a UVM Class-based Environment  
[SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)
4. [FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy](https://verificationacademy.com/forums/announcements/free-book-component-design-example-%E2%80%A6-step-step-process-using-vhdl-uart-vehicle)

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [July 12, 2020, 9:04pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/3 "2020-07-12T21:04:47Z")

</div>

_In reply to [n347](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/2):_

If you already understand how to write the constraint expression, then you already know how to write the checker expression—they are both the same thing. You can even call randomize(null) which checks the constraints using the current values of all your variables.

---

<div class="post-metadata">

**Author:** ![n347](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/9de0a6/32.png) [@n347](https://verificationacademy.com/forums/u/n347)\
**Post date:** [July 12, 2020, 9:42pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/4 "2020-07-12T21:42:33Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/3):_

Thanks Dave! I think i have a methodology question.

Monitor will get the DUT output image and can send it to scoreboard, Should the check be in the scoreboard?

pixel\_t image[9][9] → output of the DUT

But in the scoreboard how can it check for the number of pixels to be in the below constraints below:

1. The number of off has to be less than 10%. (if (image.sum \< 8) good, else error?)
2. The 3x3 array’s internal to 9x9 image should not have all off pixels.  
(how to do this, may be grab the image3x3[7][7][3][3] and do the checks? )

reference model can generate the output image as well and scoreboard can compare them…

---

<div class="post-metadata">

**Author:** ![n347](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/9de0a6/32.png) [@n347](https://verificationacademy.com/forums/u/n347)\
**Post date:** [July 12, 2020, 9:47pm UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/5 "2020-07-12T21:47:14Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/4):_

Thanks Ben!  
I looked at your paper , Do you think i can consider such assertions in my testbench?

> **[sva4scoreboarding.pdf](https://systemverilog.us/papers/sva4scoreboarding.pdf)**
>
> 167.29 KB

The model holds an image in a 25x25 matrix array.  
Each pixel in that image is an unsigned integer. The image is partitioned into 25 slices or  
quadrants, and the scoreboard needs to compute within a 5x5 slice the number of pixels  
greater than 3. The image is loaded when done\_image is true, and the slice to be selected  
is determined at a new ld signal. The done\_image occurs within 1 to 3 cycles after the ld  
signal.

How can i achieve this?  
_If you are talking about a randomly generated image, you can impose that image against a reference model that creates the expected results._

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [July 13, 2020, 3:23am UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/6 "2020-07-13T03:23:05Z")

</div>

_In reply to [n347](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/5):_

> Do you think I can consider such assertions in my testbench?

There is a saying that ALL ROADS LEAD TO ROME.

- The word “assertion” is only a testimony that a property (or something) is true.
- The techniques in specifying an assertion in SystemVerilog include SVA and plain SystemVerilog code.
- SVA is constrained to be in modules, checkers, or interfaces.
- In my paper _SVA Alternative for Complex Assertions_ I demonstrate a technique to emulate SVA anywhere in the design environment, including classes.  
[https://verificationacademy.com/news/verification-horizons-march-2018-issue](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- In the next 2020 issue of the Verification Horizons I believe that my next paper _Understanding the SVA Engine Using fork-join Model_ will be published.

In any case, the point that I am making is that if your verification environment is in a class, then use SVA model emulation using tasks. The paper [http://systemverilog.us/papers/sva4scoreboarding.pdf](http://systemverilog.us/papers/sva4scoreboarding.pdf) demonstrates how SVA is used to trigger the needed functions to do complex computations and verification. But in the end, it all boils down to the same thing. It’s interesting that my model has a lot of similarities to your requirements.  
Thus, yes, you can use a similar approach for your verification.

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [Home - My cvcblr](http://cvcblr.com/home)

- [SVA Handbook 4th Edition, 2016 ISBN 978-1518681448](http://goo.gl/JOfuEB)
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- [Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712](https://goo.gl/d10QHh)
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

1. SVA Alternative for Complex Assertions  
[https://verificationacademy.com/news/verification-horizons-march-2018-issue](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
2. [SVA: Package for dynamic and range delays and repeats - SystemVerilog - Verification Academy](https://verificationacademy.com/forums/systemverilog/sva-package-dynamic-and-range-delays-and-repeats)
3. SVA in a UVM Class-based Environment  
[https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [July 13, 2020, 4:28am UTC](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/7 "2020-07-13T04:28:51Z")

</div>

_In reply to [n347](https://verificationacademy.com/forums/t/how-to-write-sv-checker-for-verifying-if-a-dut-produced-right-image/37832/6):_  
The sum constraint expression can be used directly as an assertion

```verilog
assert ( pixel_t image.sum(D1) with (D1.sum(D2) with (int'(D2==OFF)) ) < 8);

```

This is what I meant by using a procedural for-loop in my [other post](https://verificationacademy.com/forums/systemverilog/8x8-matrix-constraint#reply-91570)

```verilog
pass == 1;
for (int i=1;i<9 && pass;i++)
  for (int j=1;j<9 && pass;j++) begin
     int count = 0;
     for(int g=i-1;g<=i+1;g++)
       for(int h=j-1;h<=j+1;h++)
          count += pixel_t image[g][h] == OFF;
     if (count == 9) pass = 10;
  end
assert (pass);

```
