Video and Image Processing Suite User Guide

ID 683416
Date 4/04/2022
Public
Document Table of Contents

A.2.6. Constrained Random Test

The constrained random test example is easily assembled using the class library.
Note: The steps to run the constrained random are described at the start of this section.
Figure 87. Example of a Constrained Random Test EnvironmentThe figure below shows the constrained random test environment structure.

Randomized video, control, and user packets are generated using the SystemVerilog’s built-in constrained random features. The DUT processes the video packets and the scoreboard determines a test pass or fail result.

test.sv comprises the following code sections:

Declaration Description
1 Object Declarations  
18 c_av_st_video_control #(`BITS_PER_SYMBOL, `CHANNELS_PER_PIXEL) video_control_pkt1,  video_control_pkt2;
19 c_av_st_video_control #(`BITS_PER_SYMBOL, `CHANNELS_PER_PIXEL) video_control_dut, video_control_golden;
20 c_av_st_video_data #(`BITS_PER_SYMBOL, `CHANNELS_PER_PIXEL) video_data_dut, video_data_scoreboard;
21 c_av_st_video_data #(`BITS_PER_SYMBOL, `CHANNELS_PER_PIXEL) dut_video_pkt, scoreboard_video_pkt;
22 c_av_st_video_data video_data_real_pkt1, video_data_real_pkt2 ;
23 c_av_st_video_item dut_pkt;
24 c_av_st_video_item scoreboard_pkt;

Declare some objects to be used later in the test. Notice that the number of pixels in parallel is not needed in these definitions as that is abstracted away from the user and handled via the classes in av_st_video_source_bfm_class.sv and av_st_video_sink_bfm_class.sv.

Note that the video item class is the base class, so could hold objects of any of the more specialized classes, such as control or video data.

2 Mailbox Declarations Description
27 mailbox #(c_av_st_video_item) m_video_items_for_scoreboard[1];
28 
29 int input_frame_count = 0;
30 
31 initial
32 begin
33
34 // Construct the 0th element of the video items mailbox array
35 m_video_items_for_scoreboard[0] = new(0);
The bfm_drivers.sv file contains mailbox declarations required for transmission and receipt of video packets, but the test harness requires a mailbox for the scoreboard. It is declared in line 27 and constructed at time zero in line 35.
3 Start the Source and Sink BFMs Description
61 #0 // Delta-cycle delay to ensure the BFM drivers were constructed in bfm_drivers.sv
62 fork // .start() calls to the VIP BFM drivers are blocking. Fork the calls.
63 st_source_bfm_0.start();
64 st_sink_bfm_0.start(av_st_clk);
65 join_none;

The source and sink BFMs must be started. Once started, the source will wait for objects for sending to be pushed into its mailbox whilst the sink will push objects into its mailbox when one is received from the DUT.

4 Stimulus—Start Producing Control and Video Packets Description
109 produce_control_pkt(add_to_scoreboard,`MAX_WIDTH,`MAX_HEIGHT,quantization,ctrl_width,ctrl_height,ctrl_interlacing);
110
111 // Don't add video packet to scoreboard if a drop packet will be IMMEDIATELY following it
112 if (`COLOR_PLANES_ARE_IN_PARALLEL == 1)
113 produce_video_pkt((ctrl_width), ctrl_height, add_to_scoreboard);
114 else
115 produce_video_pkt((ctrl_width*`CHANNELS_PER_PIXEL), ctrl_height, add_to_scoreboard);

In the main loop calls are made to the tasks in class_library/tasks.sv to produce randomly sized control packets with matching video packets.

4 Packet Checker—Checking Produced Control and Video Packets Against the Scoreboard Description
161 while ((op_pkts_seen <= (input_frame_count*2)) && !timeout)
162 begin : main_checker_loop  // NB x2 for control packets
163
164 @(posedge(av_st_clk));
165
166 if (m_video_items_for_sink_bfm[0][0].try_get(dut_pkt) == 1)
167 begin : packet_found

The corresponding loop to the stimulus loop is the checker code. This polls the sink’s mailbox for video items, categorizes according to type and to which packet type is expected, compares video packets to those previously input and then marks the packet as pass or fail accordingly.

Line 161 shows that the checker loop runs until twice the input frame count has been seen (control plus video packet per input frame) and uses the try_get() call on the sink mailbox in line 166 to check for DUT packets.

174 // DUT has output a Video packet
175 if (dut_pkt.get_packet_type() != control_packet)
176 begin : possible_video_packet_found
177
178 if (dut_pkt.get_packet_type() == video_packet)
179 begin : video_packet_found
180
181 dut_video_pkt = c_av_st_video_data'(dut_pkt); //'
182
183 // First output packets should be colour bars :
184 if ((op_pkts_seen <= `MIXER_NUM_TPG_OUTPUT_FRAMES*2) && !expecting_dut_control_packet)
185 begin : absorb_colour_bars
186 $display("%t   DUT DOUT : PASS - DUT output an assumed mixer background pattern video packet %0d(VIDEO length == %0d).",$time,op_pkts_seen,dut_video_pkt.get_length());
187 end 
188
189 else
190 begin : mixed_packets
191
192 // Sledgehammer approach for example test - search all input frames for the one currently output:
193 matching_frame = 0;
194 frames_to_check = m_video_items_for_scoreboard[0].num();
195 while (frames_to_check>0 && !matching_frame) begin
196 frames_to_check--;
197 m_video_items_for_scoreboard[0].get(scoreboard_pkt);
198 if (scoreboard_pkt.get_packet_type() == video_packet) begin
199 scoreboard_video_pkt = c_av_st_video_data'(scoreboard_pkt); //'
200 if (dut_video_pkt.silent_compare(scoreboard_video_pkt) == 1)
201 matching_frame = 1;
202
203 m_tmp.put(scoreboard_pkt);
204 end
205 end

Once the packet type is determined (lines 174-179) it is cast to an object of the corresponding type (see line 181).

As earlier described, in testbench/nios2_control_model.sv, the Mixer II is set up to offset the output video from the frame buffer by zero pixels for constrained random testing, so line 184 below shows that we expect to see one frame of test pattern (while the frame buffer receives and buffers the first input frame) followed by the video packets.

The code from lines 195-205 iterates through every item in the scoreboard, casting to a video packet type as required, before comparing to the DUT video packet in line 200 (using the built-in silent_compare method from class_library/av_st_video_classes, which does not generate output if the packets do not match). A flag is set if a match is found and the scoreboard packet is pushed onto a temporary mailbox store. After the search, all scoreboard packets are popped off the temporary store ready for comparing with subsequent video frames.

Control packets are compared against a golden one in a similar way.