Skip to content

Commit 29c0bb4

Browse files
authored
PR #214 from Arun-Prasad-V: basic test for validating fw version
2 parents bd44de8 + a45edcc commit 29c0bb4

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

test/run_ci.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
3+
'''
4+
This script helps running the tests using pytest.
5+
'''
6+
7+
import sys, os, subprocess, re, getopt, time
8+
9+
start_time = time.time()
10+
running_on_ci = False
11+
if 'WORKSPACE' in os.environ:
12+
running_on_ci = True
13+
14+
#logs are stored @ ./realsense_mipi_driver_platform/test/logs
15+
logdir = os.path.join( '/'.join(os.path.abspath( __file__ ).split( os.path.sep )[0:-1]), 'logs')
16+
dir_live_tests = os.path.dirname(__file__)
17+
18+
regex = None
19+
handle = None
20+
test_ran = False
21+
22+
def usage():
23+
ourname = os.path.basename( sys.argv[0] )
24+
print( 'Syntax: ' + ourname + ' [options] ' )
25+
print( 'Options:' )
26+
print( ' -h, --help Usage help' )
27+
print( ' -r, --regex Run all tests whose name matches the following regular expression' )
28+
print( ' e.g.: --regex test_fw_version; -r test_fw_version')
29+
30+
sys.exit( 0 )
31+
32+
def command(dev_name, test=None):
33+
cmd = ['pytest']
34+
cmd += ['-vs']
35+
cmd += ['-m', ''.join(dev_name)]
36+
if test:
37+
cmd += ['-k', f'{test}']
38+
cmd += [''.join(dir_live_tests)]
39+
cmd += ['--debug']
40+
cmd += [f'--junit-xml={logdir}/{dev_name.upper()}_pytest.xml']
41+
return cmd
42+
43+
def run_test(cmd):
44+
try:
45+
subprocess.run( cmd,
46+
timeout=200,
47+
check=True )
48+
except Exception as e:
49+
print( "Exception occurred.")
50+
51+
52+
def run_tests_on_d457():
53+
global logdir
54+
55+
try:
56+
os.makedirs( logdir, exist_ok=True )
57+
device = "D457"
58+
59+
testname = regex if regex else None
60+
61+
cmd = command(device.lower(), testname)
62+
run_test(cmd)
63+
64+
finally:
65+
if running_on_ci:
66+
print("Log path- \"Build Artifacts\":/realsense_mipi_driver_platform/test/logs ")
67+
run_time = time.time() - start_time
68+
print( "server took", run_time, "seconds" )
69+
70+
if __name__ == '__main__':
71+
try:
72+
opts, args = getopt.getopt( sys.argv[1:], 'hr:', longopts=['help', 'regex=' ] )
73+
except getopt.GetoptError as err:
74+
print( err )
75+
usage()
76+
77+
for opt, arg in opts:
78+
if opt in ('-h', '--help'):
79+
usage()
80+
elif opt in ('-r', '--regex'):
81+
regex = arg
82+
83+
run_tests_on_d457()
84+
85+
sys.exit( 0 )

test/test_fw_version.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import subprocess
2+
import pytest
3+
4+
@pytest.mark.d457
5+
@pytest.mark.parametrize("device", {'0'})
6+
def test_fw_version(device):
7+
try:
8+
result = subprocess.check_call(["v4l2-ctl", "-d"+device, "-C", "fw_version"])
9+
assert result == 0
10+
11+
std_output = subprocess.check_output(["v4l2-ctl", "-d"+device, "-C", "fw_version"])
12+
assert "fw version: " in std_output, "Couldn't fetch FW version"
13+
14+
# Remove the 'fw version: ' string from std output
15+
fw_version = int(std_output.replace("fw version: ", ""))
16+
17+
fw_version_str = str(fw_version>>24 & 0xFF) + "." + str(fw_version>>16 & 0xFF) + "." + str(fw_version>>8 & 0xFF) + "." + str(fw_version & 0xFF)
18+
print ("fw_version:", fw_version_str)
19+
20+
# Check if the FW version matching with 5.x.x.x
21+
assert fw_version == (fw_version & 0x05FFFFFF), "Expected FW version is 5.x.x.x, but received {}".format(fw_version_str)
22+
23+
# Get DFU device name
24+
dfu_device = subprocess.check_output(["ls", "/sys/class/d4xx-class/"])
25+
assert "d4xx-dfu-" in dfu_device, "D4xx DFU device not found"
26+
27+
# Get FW version from DFU device info
28+
dfu_device_info = subprocess.check_output(["cat", "/dev/"+dfu_device.strip()])
29+
30+
# Check whether the DFU info also has same FW version
31+
assert fw_version_str in dfu_device_info, "FW versions read through v4l2-ctl utility and DFU device info doesn't match"
32+
33+
except Exception as e:
34+
assert False, e

0 commit comments

Comments
 (0)