test-fw-updater.py
Go to the documentation of this file.
1 # License: Apache 2.0. See LICENSE file in root directory.
2 # Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
4 # we want this test to run first so that all tests run with updated FW versions, so we give it priority 0
5 #test:priority 0
6 #test:device each(L500*)
7 #test:device each(D400*)
8 
9 import pyrealsense2 as rs, sys, os, subprocess, re
10 from rspy import devices, log, test, file, repo
11 
12 if not devices.acroname:
13  log.i( "No Acroname library found; skipping device FW update" )
14  sys.exit(0)
15 # Following will throw if no acroname module is found
16 from rspy import acroname
17 try:
18  devices.acroname.discover()
19 except acroname.NoneFoundError as e:
20  log.f( e )
21 # Remove acroname -- we're likely running inside run-unit-tests in which case the
22 # acroname hub is likely already connected-to from there and we'll get an error
23 # thrown ('failed to connect to acroname (result=11)'). We do not need it -- just
24 # needed to verify it is available above...
25 devices.acroname = None
26 
27 def send_hardware_monitor_command( device, command ):
28  command_input = [] # array of uint_8t
29 
30  # Parsing the command to array of unsigned integers(size should be < 8bits)
31  # threw out spaces
32  command = command.lower()
33  command = command.replace(" ", "")
34  current_uint8_t_string = ''
35  for i in range(0, len(command)):
36  current_uint8_t_string += command[i]
37  if len(current_uint8_t_string) >= 2:
38  command_input.append(int('0x' + current_uint8_t_string, 0))
39  current_uint8_t_string = ''
40  if current_uint8_t_string != '':
41  command_input.append(int('0x' + current_uint8_t_string, 0))
42 
43  # byte_index = -1
44  raw_result = rs.debug_protocol( device ).send_and_receive_raw_data( command_input )
45 
46  return raw_result[4:]
47 
48 def get_update_counter( device ):
49  product_line = device.get_info( rs.camera_info.product_line )
50  cmd = None
51 
52  if product_line == "L500":
53  cmd = "14 00 AB CD 09 00 00 00 30 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00"
54  elif product_line == "D400":
55  cmd = "14 00 AB CD 09 00 00 00 30 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00"
56  else:
57  log.f( "Incompatible product line:", product_line )
58 
59  counter = send_hardware_monitor_command( device, cmd )
60  return counter[0]
61 
62 def reset_update_counter( device ):
63  product_line = device.get_info( rs.camera_info.product_line )
64  cmd = None
65 
66  if product_line == "L500":
67  cmd = "14 00 AB CD 0A 00 00 00 30 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00"
68  elif product_line == "D400":
69  cmd = "14 00 AB CD 86 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
70  else:
71  log.f( "Incompatible product line:", product_line )
72 
73  send_hardware_monitor_command( device, cmd )
74 
75 
76 # find the update tool exe
77 fw_updater_exe = None
78 for tool in file.find( repo.root, '(^|/)rs-fw-update.exe$' ):
79  fw_updater_exe = os.path.join( repo.root, tool)
80 if not fw_updater_exe:
81  log.f( "Could not find the update tool file (rs-fw-update.exe)" )
82 
83 devices.query( monitor_changes = False )
84 sn_list = devices.all()
85 # acroname should ensure there is always 1 available device
86 if len( sn_list ) != 1:
87  log.f( "Expected 1 device, got", len( sn_list ) )
88 device = devices.get( list( sn_list )[0] )
89 log.d( 'found:', device )
90 current_fw_version = repo.pretty_fw_version( device.get_info( rs.camera_info.firmware_version ))
91 log.d( 'FW version:', current_fw_version )
92 product_line = device.get_info( rs.camera_info.product_line )
93 log.d( 'product line:', product_line )
94 bundled_fw_version = repo.pretty_fw_version( device.get_info( rs.camera_info.recommended_firmware_version ) )
95 log.d( 'bundled FW version:', bundled_fw_version )
96 
97 update_counter = get_update_counter( device )
98 log.d( 'update counter:', update_counter )
99 if get_update_counter( device ) >= 19:
100  log.d( 'resetting update counter' )
101  reset_update_counter( device )
102 
103 # finding file containing image for FW update
104 image_name = product_line[0:2] + "XX_FW_Image-" + bundled_fw_version + ".bin"
105 image_mask = '(^|/)' + image_name + '$'
106 image_file = None
107 for image in file.find( repo.root, image_mask ):
108  image_file = os.path.join( repo.root, image)
109 if not image_file:
110  log.f( "Could not find image file for " + product_line + " device with FW version: " + bundled_fw_version )
111 test.start( "Update FW" )
112 try:
113  cmd = [fw_updater_exe, '-f', image_file]
114  log.d( 'running:', cmd )
115  subprocess.run( cmd )
116 except Exception as e:
117  test.unexpected_exception()
118 
119 # make sure update worked
120 devices.query( monitor_changes = False )
121 sn_list = devices.all()
122 device = devices.get( list( sn_list )[0] )
123 current_fw_version = repo.pretty_fw_version( device.get_info( rs.camera_info.firmware_version ))
124 test.check_equal( current_fw_version, bundled_fw_version )
125 if update_counter < 19:
126  test.check_equal( get_update_counter( device ), update_counter + 1)
127 else:
128  test.check_equal( get_update_counter( device ), 1)
129 
130 test.finish()
131 
132 test.print_results_and_exit()
def send_hardware_monitor_command(device, command)
def get_update_counter(device)
virtual frame finish(frame f)
def reset_update_counter(device)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11