From 768db83e188a075256038524434632ce2e9b42b6 Mon Sep 17 00:00:00 2001
From: Leon Hiemstra <hiemstra@astron.nl>
Date: Thu, 6 Nov 2014 15:55:52 +0000
Subject: [PATCH] enhanced

---
 .../unb1_test/tb/python/tc_unb1_test.py       | 214 +++++++++++-------
 1 file changed, 130 insertions(+), 84 deletions(-)

diff --git a/boards/uniboard1/designs/unb1_test/tb/python/tc_unb1_test.py b/boards/uniboard1/designs/unb1_test/tb/python/tc_unb1_test.py
index b719c82327..8546069a24 100644
--- a/boards/uniboard1/designs/unb1_test/tb/python/tc_unb1_test.py
+++ b/boards/uniboard1/designs/unb1_test/tb/python/tc_unb1_test.py
@@ -66,25 +66,26 @@ from common import *
 from pi_common import *
 
 
-def compare_arrays(a,b):
+def show_compare_arrays(tc,a,b):
     import numpy as np
-    print 'Compare array A:\n',np.asarray(a)
-    print 'With array B:\n',np.asarray(b)
+    tc.append_log(6, 'Compare array A:\n%s' % np.asarray(a))
+    tc.append_log(6, 'With array B:\n%s' % np.asarray(b))
     compared = (np.asarray(a) == np.asarray(b))
-    print 'Result:\n',compared
+    tc.append_log(5, 'Result:\n%s' % compared)
     return (not False in compared)
 
-def test_bg(tc, io):
+def test_BG_to_DB(tc,io,cmd,use_pps=False):
     tc.set_section_id('Test BG - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the peripherals BG (pi_diag_block_gen.py) and DB (pi_diag_data_buffer.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
-    ppsh = pi_ppsh.PiPpsh(tc, io)
+    if use_pps==True: ppsh = pi_ppsh.PiPpsh(tc, io)
 
     tc.set_section_id('Read - ')
     nof_streams=3
-    Bg = pi_diag_block_gen.PiDiagBlockGen(tc,io,nofChannels=nof_streams,ramSizePerChannel=1000)
+    blocksize=0
+    Bg = pi_diag_block_gen.PiDiagBlockGen(tc,io,nofChannels=nof_streams,ramSizePerChannel=blocksize)
     Bg.write_disable()
 
     settings = Bg.read_block_gen_settings()
@@ -97,17 +98,18 @@ def test_bg(tc, io):
     resetptrn = [7]*samples_per_packet + [0]*(blocksize-samples_per_packet)
     Db.overwrite_all_data_buffers(resetptrn, vLevel=9)
 
-    Bg.write_enable()  # or Bg.write_enable_pps()
-    ppsh.wait_until_pps(vLevel=6)
+    if use_pps==True:
+        Bg.write_enable_pps()
+        ppsh.wait_until_pps(vLevel=6)
+    else:
+        Bg.write_enable()
 
     bg_ram = []
     for s in range(nof_streams):
         ram = Bg.read_waveform_ram(channelNr=s,vLevel=5)
-        lram=[]
-        for r in ram: lram.append(list(r)) # () -> []
-        bg_ram.append(lram)
-
-    bg_ram[0][0][2]=0
+        rram=[]
+        for r in ram: rram.append(list(r)) # () -> []
+        bg_ram.append(rram)
 
     db_ram = []
     for s in range(nof_streams):
@@ -119,32 +121,41 @@ def test_bg(tc, io):
     tc.append_log(1, '>>> (BG==DB): %s' % compared)
     tc.append_log(3, '')
     if compared==False: tc.set_result('FAILED')
-    compare_arrays(bg_ram,db_ram)
+    show_compare_arrays(tc,bg_ram,db_ram)
+
+def test_BG_to_DB_pps(tc,io,cmd):
+    return test_BG_to_DB(tc,io,cmd,use_pps=True)
+
 
-def test_tr_xaui(tc, io):
+
+def test_tr_xaui(tc,io,cmd):
     tc.set_section_id('Read tr xaui status - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the REG_TR_XAUI peripheral (pi_tr_xaui.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
     tc.append_log(3, '')
     from pi_tr_xaui import REGMAP,PiTrXaui
     on_execute(class_definition=PiTrXaui,regmap=REGMAP)
 
-def test_tr_10GbE(tc, io):
+
+
+def test_tr_10GbE(tc,io,cmd):
     tc.set_section_id('Read tr 10GbE status - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the REG_TR_10GBE peripheral (pi_tr_10GbE.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
     tc.append_log(3, '')
     from pi_tr_10GbE import REGMAP,PiTr10GbE
     on_execute(class_definition=PiTr10GbE,regmap=REGMAP)
 
-def test_bsn_mon(tc, io):
+
+
+def test_bsn_mon(tc,io,cmd):
     tc.set_section_id('Read BSN monitor status - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the REG_BSN_MONITOR peripheral (pi_bsn_monitor.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
     Bsn = pi_bsn_monitor.PiBsnMonitor(tc,io)
@@ -152,32 +163,44 @@ def test_bsn_mon(tc, io):
     tc.append_log(3, '')
 
 
-def test_info(tc, io):
+
+def test_info(tc,io,cmd):
     tc.set_section_id('Read System Info - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the PIO_SYSTEM_INFO peripheral (pi_system_info.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
     
     info = pi_system_info.PiSystemInfo(tc, io)
 
     info.make_register_info()
     tc.append_log(3, '')
-    info.read_reg_map()
-    tc.append_log(3, '')
+    #info.read_reg_map()
+    #tc.append_log(3, '')
     info.read_system_info()
     tc.append_log(3, '')
     info.read_use_phy()
     tc.append_log(3, '')
-    info.read_design_name()
+    design_name = info.read_design_name()
     tc.append_log(3, '')
     info.read_stamps()
     tc.append_log(3, '')
     info.read_design_note()
+
+    expected_design_name = tc.gpString
+    if cmd==3 and expected_design_name != '':
+        tc.set_section_id('Verify System Info - ')
+        tc.append_log(1, '>>> Verifying design_name == %s' % expected_design_name)
+        for name in design_name:
+            if (name != expected_design_name): 
+                tc.set_result('FAILED')
+                tc.append_log(2, '>>> design_name mismatch!! (%s != %s)' % (name,expected_design_name))
+
+
     
-def test_sensors(tc, io):
+def test_sensors(tc,io,cmd):
     tc.set_section_id('Read sensors - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the REG_UNB_SENS peripheral (pi_unb_sens.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
     
     sens = pi_unb_sens.PiUnbSens(tc, io)
@@ -193,10 +216,11 @@ def test_sensors(tc, io):
     sens.read_unb_power()
 
 
-def test_ppsh(tc,io):
+
+def test_ppsh(tc,io,cmd):
     tc.set_section_id('Read PPSH capture count - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the PIO_PPS peripheral (pi_ppsh.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
     
     Ppsh = pi_ppsh.PiPpsh(tc, io)
@@ -204,10 +228,11 @@ def test_ppsh(tc,io):
     tc.append_log(3, '')
 
 
-def test_wdi(tc,io):
+
+def test_wdi(tc,io,cmd):
     tc.set_section_id('Reset to image in bank 0 using WDI - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Access the REG_WDI peripheral (pi_wdi.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
     Wdi = pi_wdi.PiWdi(tc, io)
@@ -215,10 +240,11 @@ def test_wdi(tc,io):
     tc.append_log(3, '')
 
 
-def test_remu(tc,io):
+
+def test_remu(tc,io,cmd):
     tc.set_section_id('REMU start image in bank 1 - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> REMU (pi_remu.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
 
     dummy_tc = test_case.Testcase('Dummy TB - ', '')
@@ -236,10 +262,11 @@ def test_remu(tc,io):
     tc.append_log(3, '')
 
 
-def test_eth(tc,io):
+
+def test_eth(tc,io,cmd):
     tc.set_section_id('ETH status - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> ETH (pi_eth.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
     
     eth = pi_eth.PiEth(tc, io)
@@ -248,10 +275,11 @@ def test_eth(tc,io):
     tc.append_log(3, '')
 
 
-def test_flash(tc,io):
+
+def test_flash(tc,io,cmd):
     tc.set_section_id('Flash write to bank 1 - ')
     tc.append_log(3, '>>>')
-    tc.append_log(1, '>>> Write to flash (pi_epcs.py)')
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
     tc.append_log(3, '>>>')
     
     Epcs = pi_epcs.PiEpcs(tc, io)
@@ -269,52 +297,73 @@ def test_flash(tc,io):
     tc.append_log(3, '')
 
 
-def sleep(tc,io):
-    tc.set_section_id('SLEEP - ')
-    tc.append_log(3, 'sleeping 1 second')
-    tc.sleep(1.0)
 
+def sleep(tc,io,cmd):
+    tc.set_section_id('%s - ' % cmd_text(cmd))
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
+    if cmd == 0:
+        tc.sleep(1.0)
+    elif cmd == 1:
+        tc.sleep(5.0)
+
+def show_help(tc,io,cmd):
+    help_text(tc,io,100)
 
-def show_help(tc,io):
-    help_text(tc,io)
+def show_example(tc,io,cmd):
+    tc.append_log(1, '>>> %s' % help_text(tc,io,cmd))
+    help_text(tc,io,101)
 
 
 # Avaliable commands
 Cmd = {
-    0 : ('SLEEP'  , sleep,        'Sleep 1 second'),
-    1 : ('INFO'   , test_info,    'using pi_system_info to read system info'),
-    2 : ('SENSORS', test_sensors, 'using pi_unb_sens to readout sensors'),
-    3 : ('PPSH'   , test_ppsh,    'using pi_ppsh to read PPSH capture count'),
-    4 : ('WDI'    , test_wdi,     'using pi_wdi to reset to image in bank 0'),
-    5 : ('FLASH'  , test_flash,   'using pi_epcs to program/verify flash'),
-    6 : ('REMU'   , test_remu,    'using pi_remu to load user image'),
-    7 : ('ETH'    , test_eth,     'using pi_eth to read eth status'),
-    8 : ('XAUI'   , test_tr_xaui, 'using pi_tr_xaui to read xaui status'),
-    9 : ('10GBE'  , test_tr_10GbE,'using pi_tr_10GbE to read 10GbE status'),
-   10 : ('BSN'    , test_bsn_mon, 'using pi_bsn_monitor to read BSN monitor'),
-   11 : ('BG'     , test_bg,      'using pi_diag_block_gen.py to read BG'),
-  100 : ('HELP'   , show_help,    'show help on commands')
+    0 : ('SLEEP1' , sleep,        'Sleep 1 second',''),
+    1 : ('SLEEP5' , sleep,        'Sleep 5 seconds',''),
+    2 : ('INFO'   , test_info,    'using pi_system_info to read system info (access PIO_SYSTEM_INFO)',''),
+    3 : ('INFO+'  , test_info,    'using pi_system_info to read system info (access PIO_SYSTEM_INFO)','(-s for expected design_name)'),
+    4 : ('FLASH'  , test_flash,   'using pi_epcs to program/verify flash','(-s for .rbf file)'),
+    5 : ('SENSORS', test_sensors, 'using pi_unb_sens to readout sensors (access REG_UNB_SENS)',''),
+    6 : ('PPSH'   , test_ppsh,    'using pi_ppsh to read PPSH capture count (access PIO_PPS)',''),
+    7 : ('ETH'    , test_eth,     'using pi_eth to read eth status',''),
+    8 : ('REMU'   , test_remu,    'using pi_remu to load user image (access REG_REMU)',''),
+    9 : ('WDI'    , test_wdi,     'using pi_wdi to reset to image in bank 0 (access REG_WDI)',''),
+   10 : ('XAUI'   , test_tr_xaui, 'using pi_tr_xaui to read xaui status (access REG_TR_XAUI)',''),
+   11 : ('10GBE'  , test_tr_10GbE,'using pi_tr_10GbE to read 10GbE status (access REG_TR_10GBE)',''),
+   12 : ('BSN'    , test_bsn_mon, 'using pi_bsn_monitor to read BSN monitor (access REG_BSN_MONITOR)',''),
+   13 : ('BGDB'   , test_BG_to_DB,'using BG (pi_diag_block_gen.py) and DB (pi_diag_data_buffer.py)',''),
+   14 : ('BGDBpps', test_BG_to_DB_pps,'using BG (pi_diag_block_gen.py) and DB (pi_diag_data_buffer.py) using PPS',''),
+   15 : ('EXAMPLE', show_example, 'show several example commands',''),
+  100 : ('HELP'   , show_help,    'show help on commands','')
 }
 
-
-
-def help_text(tc,io):
-    tc.append_log(0, '>>> Usage [--cmd <command number or series of numbers>]:')
-    for cmd in sorted(Cmd):
-        tc.append_log(0, '    .  %d : %s: %s' % (cmd,Cmd[cmd][0],Cmd[cmd][2]))
-    tc.append_log(0, '')
-    tc.append_log(0, '[full test]            sequence: --cmd 1,4,0,0,0,0,1,0,5,6,0,0,0,0,1,2,3 -s file.rbf')
-    tc.append_log(0, '[image start and test] sequence: --cmd 1,4,0,0,0,0,1,6,0,0,0,0,1,2,3')
-    tc.append_log(0, '[re-read info,sensors] sequence: --cmd 1,2,3 --rep 10')
-    tc.append_log(0, '[reset to factory]     sequence: --cmd 1,4,0,0,0,0,1')
-    tc.append_log(0, '[program user image]   sequence: --cmd               5 -s file.rbf')
-    tc.append_log(0, '[load user image]      sequence: --cmd 6,0,0,0,0,1')
-
-
-
-###############################################################################
-# Setup
-    
+def cmd_text(cmd):
+    return Cmd[cmd][0]
+
+def help_text(tc,io,cmd):
+    str=''
+    if cmd == 100:
+        tc.append_log(0, '>>> Usage [--cmd <command number or series of numbers>]:')
+        for cmd in sorted(Cmd):
+            tc.append_log(0, '    .  %d : %s: %s : %s' % (cmd,Cmd[cmd][0],Cmd[cmd][2],Cmd[cmd][3]))
+    elif cmd == 101: # examples
+        tc.append_log(0, '')
+        tc.append_log(0, '[reset, load user img] sequence: --cmd 2,9,1,2,9,1,2,8,1,2')
+        #                                                          ^fact ^fact ^user
+        tc.append_log(0, '[flash+start user img] sequence: --cmd 2,4,9,1,2,8,1,2 -s file.rbf')
+        #                                                            ^fact ^user
+        tc.append_log(0, '[re-read info,sensors] sequence: --cmd 3,5,6 --rep 10 -s expected_design_name')
+        tc.append_log(0, '[reset to factory]     sequence: --cmd 2,9,1,2')
+        tc.append_log(0, '[program user image]   sequence: --cmd 4 -s file.rbf')
+        tc.append_log(0, '[load user image]      sequence: --cmd 8,1,2')
+    else:
+        str = Cmd[cmd][2]
+    return str
+
+
+
+
+##################################################################################################################
+# Main
+#
 # Create a test case object
 tc = test_case.Testcase('TB - ', '')
 tc.set_result('PASSED')
@@ -324,32 +373,29 @@ tc.append_log(1, '>>> Title : Test bench for tc_unb1_test.py on nodes %s, %s' %
 tc.append_log(3, '>>>')
     
 
-
 # Create access object for nodes
 io = node_io.NodeIO(tc.nodeImages, tc.base_ip)
 
 
 
+##################################################################################################################
+# Run tests
 rep = 0
 while rep < tc.repeat:
     rep += 1
     tc.append_log(3, '')
     tc.append_log(2, 'Rep = %d' % rep)
     
-
     for cmd in tc.commands:
         if cmd > len(Cmd): cmd = 100 # default to help_text
         tc.append_log(3, 'Next command: %d : %s: %s' % (cmd,Cmd[cmd][0],Cmd[cmd][2]))
 
-        Cmd[cmd][1](tc,io)
+        Cmd[cmd][1](tc,io,cmd)
 
 
 
 
-
-
-###############################################################################
-###############################################################################
+##################################################################################################################
 # End
 tc.set_section_id('')
 tc.append_log(3, '')
-- 
GitLab