HyperDbg Debugger
Loading...
Searching...
No Matches
test_DebuggerModuleTestingBRAM Namespace Reference

Functions

 extract_number (s)
 
 print_bram_content (dut)
 
 get_symbol_value (dut, value)
 
 get_symbol_type (dut, type)
 
 get_stage_index (dut, stage_index)
 
 extract_stage_details (dut)
 
 set_input_pins (dut)
 
 DebuggerModuleTestingBRAM_test (dut)
 

Variables

int maximum_number_of_clock_cycles = 1000
 

Function Documentation

◆ DebuggerModuleTestingBRAM_test()

test_DebuggerModuleTestingBRAM.DebuggerModuleTestingBRAM_test ( dut)
Test hwdbg module (with pre-defined BRAM)
425async def DebuggerModuleTestingBRAM_test(dut):
426 """Test hwdbg module (with pre-defined BRAM)"""
427
428 #
429 # Assert initial output is unknown
430 #
431 assert LogicArray(dut.io_outputPin_0.value) == LogicArray("X")
432 assert LogicArray(dut.io_outputPin_1.value) == LogicArray("X")
433 assert LogicArray(dut.io_outputPin_2.value) == LogicArray("X")
434 assert LogicArray(dut.io_outputPin_3.value) == LogicArray("X")
435 assert LogicArray(dut.io_outputPin_4.value) == LogicArray("X")
436 assert LogicArray(dut.io_outputPin_5.value) == LogicArray("X")
437 assert LogicArray(dut.io_outputPin_6.value) == LogicArray("X")
438 assert LogicArray(dut.io_outputPin_7.value) == LogicArray("X")
439 assert LogicArray(dut.io_outputPin_8.value) == LogicArray("X")
440 assert LogicArray(dut.io_outputPin_9.value) == LogicArray("X")
441 assert LogicArray(dut.io_outputPin_10.value) == LogicArray("X")
442 assert LogicArray(dut.io_outputPin_11.value) == LogicArray("X")
443 assert LogicArray(dut.io_outputPin_12.value) == LogicArray("X")
444 assert LogicArray(dut.io_outputPin_13.value) == LogicArray("X")
445 assert LogicArray(dut.io_outputPin_14.value) == LogicArray("X")
446 assert LogicArray(dut.io_outputPin_15.value) == LogicArray("X")
447 assert LogicArray(dut.io_outputPin_16.value) == LogicArray("X")
448 assert LogicArray(dut.io_outputPin_17.value) == LogicArray("X")
449 assert LogicArray(dut.io_outputPin_18.value) == LogicArray("X")
450 assert LogicArray(dut.io_outputPin_19.value) == LogicArray("X")
451 assert LogicArray(dut.io_outputPin_20.value) == LogicArray("X")
452 assert LogicArray(dut.io_outputPin_21.value) == LogicArray("X")
453 assert LogicArray(dut.io_outputPin_22.value) == LogicArray("X")
454 assert LogicArray(dut.io_outputPin_23.value) == LogicArray("X")
455 assert LogicArray(dut.io_outputPin_24.value) == LogicArray("X")
456 assert LogicArray(dut.io_outputPin_25.value) == LogicArray("X")
457 assert LogicArray(dut.io_outputPin_26.value) == LogicArray("X")
458 assert LogicArray(dut.io_outputPin_27.value) == LogicArray("X")
459 assert LogicArray(dut.io_outputPin_28.value) == LogicArray("X")
460 assert LogicArray(dut.io_outputPin_29.value) == LogicArray("X")
461 assert LogicArray(dut.io_outputPin_30.value) == LogicArray("X")
462 assert LogicArray(dut.io_outputPin_31.value) == LogicArray("X")
463
464 #
465 # Create a 10ns period clock on port clock
466 #
467 clock = Clock(dut.clock, 10, units="ns")
468
469 #
470 # Start the clock. Start it low to avoid issues on the first RisingEdge
471 #
472 cocotb.start_soon(clock.start(start_high=False))
473
474 dut._log.info("Initialize and reset module")
475
476 #
477 # Initial values
478 #
479 dut.io_en.value = 0
480 dut.io_plInSignal.value = 0
481
482 #
483 # Reset DUT
484 #
485 dut.reset.value = 1
486 for _ in range(10):
487 await Timer(10, units="ns")
488 dut.reset.value = 0
489
490
491 dut._log.info("Enabling an interrupting chip to receive commands from BRAM")
492
493 #
494 # Enable chip
495 #
496 dut.io_en.value = 1
497
498 #
499 # Set initial input value to prevent it from floating
500 #
501 dut._log.info("Initializing input pins")
502 # set_input_pins(dut)
503
504 #
505 # Tell the hwdbg to receive BRAM results
506 #
507 dut.io_plInSignal.value = 1
508 await Timer(10, units="ns")
509 dut.io_plInSignal.value = 0
510
511 #
512 # Synchronize with the clock. This will regisiter the initial `inputPinX` value
513 #
514 await Timer(10, units="ns")
515
516 #
517 # Wait until the debuggee sends an interrupt to debugger
518 #
519 clock_counter = 0
520 interrupt_not_delivered = False
521
522 while str(dut.io_psOutInterrupt) != "1":
523
524 # print("State of interrupt: '" + str(dut.io_psOutInterrupt) + "'")
525
526 if clock_counter % 10 == 0:
527 print("Number of clock cycles spent in debuggee (PL): " + str(clock_counter))
528
529 clock_counter = clock_counter + 1
530 await Timer(10, units="ns")
531
532 #
533 # Apply a limitation to the number of clock cycles that
534 # can be executed to avoid infinite time
535 #
536 if (clock_counter >= maximum_number_of_clock_cycles):
537 interrupt_not_delivered = True
538 break
539
540 #
541 # Being here means either the debuggee sent an interrupt to the PS
542 # or the maximum clock cycles reached
543 #
544 if interrupt_not_delivered:
545 print("Maximum clock cycles reached")
546 else:
547 print("Debuggee (PL) interrupted Debugger (PS)")
548
549 #
550 # Run one more clock cycle to apply the latest BRAM modifications
551 #
552 await Timer(10, units="ns")
553
554 #
555 # Print contents of BRAM
556 #
557 print_bram_content(dut)
558
559 #
560 # Print the script stage configuration
561 #
562 extract_stage_details(dut)
563
564 #
565 # Check the final input on the next clock and run the circuit for a couple
566 # of more clock cycles
567 #
568 for _ in range(100):
569 set_input_pins(dut)
570 await Timer(10, units="ns")

◆ extract_number()

test_DebuggerModuleTestingBRAM.extract_number ( s)
102def extract_number(s):
103 return int(s.split('_')[1])
104

◆ extract_stage_details()

test_DebuggerModuleTestingBRAM.extract_stage_details ( dut)
278def extract_stage_details(dut):
279
280 print("Script Stage Registers Configuration:\n")
281 all_elements = dir(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule)
282
283 #
284 # Define the pattern to match
285 #
286 pattern_value = re.compile(r'stageRegs_\d+_stageSymbol_Value')
287 pattern_type = re.compile(r'stageRegs_\d+_stageSymbol_Type')
288 pattern_stage_index = re.compile(r'stageRegs_\d+_stageIndex')
289
290 #
291 # Filter the list using the patterns
292 #
293 filtered_strings_values = [s for s in all_elements if pattern_value.match(s)]
294 filtered_strings_types = [s for s in all_elements if pattern_type.match(s)]
295 filtered_strings_stage_index = [s for s in all_elements if pattern_stage_index.match(s)]
296
297 #
298 # Sort the lists
299 #
300 sorted_values = sorted(filtered_strings_values, key=extract_number)
301 sorted_types = sorted(filtered_strings_types, key=extract_number)
302 sorted_stage_index = sorted(filtered_strings_stage_index, key=extract_number)
303
304 #
305 # Print the filtered strings
306 #
307 # print(sorted_values)
308 # print(sorted_types)
309 # print(sorted_stage_index)
310
311 for index, element in enumerate(sorted_values):
312
313 try:
314 final_string_type = get_symbol_type(dut, sorted_types[index])
315
316 #
317 # Print the type
318 #
319 print(final_string_type)
320 except:
321 print("This stage does not contain a 'type'")
322
323 try:
324 final_string_value = get_symbol_value(dut, sorted_values[index])
325
326 #
327 # Print the value
328 #
329 print(final_string_value)
330 except:
331 print("Unable to get stage 'value' configuration details")
332
333 try:
334 final_string_stage_index = get_stage_index(dut, index)
335
336 #
337 # Print the stage index
338 #
339 print("index: " + final_string_stage_index)
340
341 except:
342 print("index: " + str(index) +": This stage does not contain a 'stage index'")
343
344 print("\n")
345
346
347 #
348 # Check stage enable bit
349 #
350 try:
351 stage_enabled = "stageRegs_" + str(index) + "_stageEnable"
352 is_stage_enabled = getattr(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule, stage_enabled)
353 print("\t Stage enabled bit: " + str(is_stage_enabled))
354 except:
355 print("\t Stage enabled bit: (unavailable)")
356
357 try:
358 final_string_value = get_symbol_value(dut, "stageRegs_" + str(index) + "_getOperatorSymbol_0_Value")
359 final_string_type = get_symbol_type(dut, "stageRegs_" + str(index) + "_getOperatorSymbol_0_Type")
360
361 print("\t Get (0) | " + final_string_type)
362 print("\t Get (0) | " + final_string_value)
363 except:
364 print("\t stage at:" + str(index) + " does not contain a Get (0) buffer")
365
366 print("\n")
367
368 try:
369 final_string_value = get_symbol_value(dut, "stageRegs_" + str(index) + "_getOperatorSymbol_1_Value")
370 final_string_type = get_symbol_type(dut, "stageRegs_" + str(index) + "_getOperatorSymbol_1_Type")
371
372 print("\t Get (1) | " + final_string_type)
373 print("\t Get (1) | " + final_string_value)
374 except:
375 print("\t stage at:" + str(index) + " does not contain a Get (1) buffer")
376
377 print("\n")
378
379 try:
380 final_string_value = get_symbol_value(dut, "stageRegs_" + str(index) + "_setOperatorSymbol_0_Value")
381 final_string_type = get_symbol_type(dut, "stageRegs_" + str(index) + "_setOperatorSymbol_0_Type")
382
383 print("\t Set (0) | " + final_string_type)
384 print("\t Set (0) | " + final_string_value)
385 except:
386 print("\t stage at:" + str(index) + " does not contain a Set (0) buffer")
387
388 print("\n\n")
389

◆ get_stage_index()

test_DebuggerModuleTestingBRAM.get_stage_index ( dut,
stage_index )
262def get_stage_index(dut, stage_index):
263 stage_index_str = "stageRegs_" + str(stage_index) + "_stageIndex"
264 element_stage_index = getattr(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule, stage_index_str)
265 hex_string_stage_index = ""
266 try:
267 int_content_stage_index = int(str(element_stage_index.value), 2)
268 hex_string_stage_index = f'{int_content_stage_index:x}'
269 except:
270 hex_string_stage_index = str(element_stage_index.value)
271
272 final_string_stage_index = f'{stage_index}: 0x{hex_string_stage_index}' + " (bin: " + str(element_stage_index.value) + ")"
273 return final_string_stage_index
274
275#
276# Define a function to extract content of stages
277#

◆ get_symbol_type()

test_DebuggerModuleTestingBRAM.get_symbol_type ( dut,
type )
247def get_symbol_type(dut, type):
248 element_type = getattr(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule, type)
249 hex_string_type = ""
250 try:
251 int_content_type = int(str(element_type.value), 2)
252 hex_string_type = f'{int_content_type:x}'
253 except:
254 hex_string_type = str(element_type.value)
255
256 final_string_type = f'{type} : 0x{hex_string_type}' + " (bin: " + str(element_type.value) + ")"
257 return final_string_type
258
259#
260# Define a function to extract stage index
261#

◆ get_symbol_value()

test_DebuggerModuleTestingBRAM.get_symbol_value ( dut,
value )
232def get_symbol_value(dut, value):
233 element_value = getattr(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule, value)
234 hex_string_value = ""
235 try:
236 int_content_value = int(str(element_value.value), 2)
237 hex_string_value = f'{int_content_value:x}'
238 except:
239 hex_string_value = str(element_value.value)
240
241 final_string_value = f'{value}: 0x{hex_string_value}' + " (bin: " + str(element_value.value) + ")"
242 return final_string_value
243
244#
245# Define a function to extract type of symbol
246#

◆ print_bram_content()

test_DebuggerModuleTestingBRAM.print_bram_content ( dut)
Printing contents of Block RAM and saving them to a file
105def print_bram_content(dut):
106 """Printing contents of Block RAM and saving them to a file"""
107
108 #
109 # Print the instances and signals (which includes the ports) of the design's toplevel
110 #
111 print("===================================================================")
112 # print("Onstances and signals (which includes the ports) of the design's toplevel:")
113 # print(dir(dut))
114 # print("===================================================================")
115
116 #
117 # Print the instances and signals of "inst_sub_block" under the toplevel
118 # which is the instance name of a Verilog module or VHDL entity/component
119 #
120 # print("Onstances and signals of 'dataOut_initRegMemFromFileModule' under the toplevel:")
121 # print(dir(dut.dataOut_initRegMemFromFileModule))
122
123 items_inside_bram_emulator = dir(dut.dataOut_initRegMemFromFileModule)
124 mem_items = []
125
126 for item in items_inside_bram_emulator:
127 if item.startswith("mem_"):
128 mem_items.append(item)
129
130 #
131 # Sort the list using the custom key function
132 #
133 sorted_list = sorted(mem_items, key=extract_number)
134
135 with open("script_buffer_response.txt", "w") as file:
136 # with open("bram_instance_info.txt", "w") as file:
137 file.write("Content of BRAM after emulation:\n")
138 print("Content of BRAM after emulation:")
139
140 #
141 # The second half of the BRAM is used for PL to PS communication
142 #
143 address_of_ps_to_pl_communication = "mem_0"
144 address_of_ps_to_pl_communication_checksum1 = "mem_0"
145 address_of_ps_to_pl_communication_checksum2 = "mem_1"
146 address_of_ps_to_pl_communication_indicator1 = "mem_2"
147 address_of_ps_to_pl_communication_indicator2 = "mem_3"
148 address_of_ps_to_pl_communication_type_of_packet = "mem_4"
149 address_of_ps_to_pl_communication_requested_action_of_the_packet = "mem_5"
150 address_of_ps_to_pl_communication_start_of_data = "mem_6"
151
152 len_of_sorted_list_div_by_2 = int(len(sorted_list) / 2)
153 address_of_pl_to_ps_communication = "mem_" + str(len_of_sorted_list_div_by_2)
154 address_of_pl_to_ps_communication_checksum1 = "mem_" + str(len_of_sorted_list_div_by_2 + 0)
155 address_of_pl_to_ps_communication_checksum2 = "mem_" + str(len_of_sorted_list_div_by_2 + 1)
156 address_of_pl_to_ps_communication_indicator1 = "mem_" + str(len_of_sorted_list_div_by_2 + 2)
157 address_of_pl_to_ps_communication_indicator2 = "mem_" + str(len_of_sorted_list_div_by_2 + 3)
158 address_of_pl_to_ps_communication_type_of_packet = "mem_" + str(len_of_sorted_list_div_by_2 + 4)
159 address_of_pl_to_ps_communication_requested_action_of_the_packet = "mem_" + str(len_of_sorted_list_div_by_2 + 5)
160 address_of_pl_to_ps_communication_start_of_data = "mem_" + str(len_of_sorted_list_div_by_2 + 6)
161
162 print("Address of PL to PS communication: " + address_of_pl_to_ps_communication)
163
164 for item in sorted_list:
165 element = getattr(dut.dataOut_initRegMemFromFileModule, item)
166
167 #
168 # Print the target register in binary format
169 #
170 # print(str(element))
171
172 #
173 # Convert binary to int
174 #
175 int_content = int(str(element.value), 2)
176
177 #
178 # Convert integer to hexadecimal string with at least 8 characters
179 #
180 hex_string = f'{int_content:08x}'
181
182 final_string = ""
183 if len(item) == 5:
184 final_string = item + ": " + hex_string
185 elif len(item) == 6:
186 final_string = item + ": " + hex_string
187 else:
188 final_string = item + ": " + hex_string
189
190 #
191 # Make a separation between PS and PL area
192 #
193 if item == address_of_ps_to_pl_communication:
194 file.write("\nPS to PL area:\n")
195 print("\nPS to PL area:")
196 elif item == address_of_pl_to_ps_communication:
197 file.write("\nPL to PS area:\n")
198 print("\nPL to PS area:")
199
200 if item == address_of_ps_to_pl_communication_checksum1 or \
201 item == address_of_ps_to_pl_communication_checksum2 or \
202 item == address_of_pl_to_ps_communication_checksum1 or \
203 item == address_of_pl_to_ps_communication_checksum2:
204 final_string = final_string + " | Checksum"
205 elif item == address_of_ps_to_pl_communication_indicator1 or \
206 item == address_of_ps_to_pl_communication_indicator2 or \
207 item == address_of_pl_to_ps_communication_indicator1 or \
208 item == address_of_pl_to_ps_communication_indicator2:
209 final_string = final_string + " | Indicator"
210 elif item == address_of_ps_to_pl_communication_type_of_packet or \
211 item == address_of_pl_to_ps_communication_type_of_packet:
212 final_string = final_string + " | TypeOfThePacket"
213 elif item == address_of_ps_to_pl_communication_requested_action_of_the_packet or \
214 item == address_of_pl_to_ps_communication_requested_action_of_the_packet:
215 final_string = final_string + " | RequestedActionOfThePacket"
216 elif item == address_of_ps_to_pl_communication_start_of_data or \
217 item == address_of_pl_to_ps_communication_start_of_data:
218 final_string = final_string + " | Start of Optional Data"
219
220 #
221 # Print contents of BRAM
222 #
223 file.write(final_string + "\n")
224 print(final_string)
225
226 print("\n===================================================================\n")
227
228
229#
230# Define a function to extract value of symbol
231#

◆ set_input_pins()

test_DebuggerModuleTestingBRAM.set_input_pins ( dut)
390def set_input_pins(dut):
391 dut.io_inputPin_0.value = 0
392 dut.io_inputPin_1.value = 0
393 dut.io_inputPin_2.value = 1
394 dut.io_inputPin_3.value = 1
395 dut.io_inputPin_4.value = 1
396 dut.io_inputPin_5.value = 1
397 dut.io_inputPin_6.value = 1
398 dut.io_inputPin_7.value = 1
399 dut.io_inputPin_8.value = 1
400 dut.io_inputPin_9.value = 1
401 dut.io_inputPin_10.value = 1
402 dut.io_inputPin_11.value = 1
403 dut.io_inputPin_12.value = 1
404 dut.io_inputPin_13.value = 1
405 dut.io_inputPin_14.value = 1
406 dut.io_inputPin_15.value = 1
407 dut.io_inputPin_16.value = 1
408 dut.io_inputPin_17.value = 1
409 dut.io_inputPin_18.value = 1
410 dut.io_inputPin_19.value = 1
411 dut.io_inputPin_20.value = 1
412 dut.io_inputPin_21.value = 1
413 dut.io_inputPin_22.value = 1
414 dut.io_inputPin_23.value = 1
415 dut.io_inputPin_24.value = 1
416 dut.io_inputPin_25.value = 1
417 dut.io_inputPin_26.value = 1
418 dut.io_inputPin_27.value = 1
419 dut.io_inputPin_28.value = 1
420 dut.io_inputPin_29.value = 1
421 dut.io_inputPin_30.value = 1
422 dut.io_inputPin_31.value = 1
423
424@cocotb.test()

Variable Documentation

◆ maximum_number_of_clock_cycles

int test_DebuggerModuleTestingBRAM.maximum_number_of_clock_cycles = 1000