Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic test for validating fw version #214

Merged
merged 6 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions test/run_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

'''
This script helps running the tests using pytest.
'''

import sys, os, subprocess, re, getopt, time

start_time = time.time()
running_on_ci = False
if 'WORKSPACE' in os.environ:
running_on_ci = True

#logs are stored @ ./realsense_mipi_driver_platform/test/logs
logdir = os.path.join( '/'.join(os.path.abspath( __file__ ).split( os.path.sep )[0:-1]), 'logs')
dir_live_tests = os.path.dirname(__file__)

regex = None
handle = None
test_ran = False

def usage():
ourname = os.path.basename( sys.argv[0] )
print( 'Syntax: ' + ourname + ' [options] ' )
print( 'Options:' )
print( ' -h, --help Usage help' )
print( ' -r, --regex Run all tests whose name matches the following regular expression' )
print( ' e.g.: --regex test_fw_version; -r test_fw_version')

sys.exit( 0 )

def command(dev_name, test=None):
cmd = ['pytest']
cmd += ['-vs']
cmd += ['-m', ''.join(dev_name)]
if test:
cmd += ['-k', f'{test}']
cmd += [''.join(dir_live_tests)]
cmd += ['--debug']
cmd += [f'--junit-xml={logdir}/{dev_name.upper()}_pytest.xml']
return cmd

def run_test(cmd):
try:
subprocess.run( cmd,
timeout=200,
check=True )
except Exception as e:
print( "Exception occurred.")


def run_tests_on_d457():
global logdir

try:
os.makedirs( logdir, exist_ok=True )
device = "D457"

testname = regex if regex else None

cmd = command(device.lower(), testname)
run_test(cmd)

finally:
if running_on_ci:
print("Log path- \"Build Artifacts\":/realsense_mipi_driver_platform/test/logs ")
run_time = time.time() - start_time
print( "server took", run_time, "seconds" )

if __name__ == '__main__':
try:
opts, args = getopt.getopt( sys.argv[1:], 'hr:', longopts=['help', 'regex=' ] )
except getopt.GetoptError as err:
print( err )
usage()

for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
elif opt in ('-r', '--regex'):
regex = arg

run_tests_on_d457()

sys.exit( 0 )
34 changes: 34 additions & 0 deletions test/test_fw_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import subprocess
import pytest

@pytest.mark.d457
@pytest.mark.parametrize("device", {'0'})
def test_fw_version(device):
try:
result = subprocess.check_call(["v4l2-ctl", "-d"+device, "-C", "fw_version"])
assert result == 0

std_output = subprocess.check_output(["v4l2-ctl", "-d"+device, "-C", "fw_version"])
assert "fw version: " in std_output, "Couldn't fetch FW version"

# Remove the 'fw version: ' string from std output
fw_version = int(std_output.replace("fw version: ", ""))

fw_version_str = str(fw_version>>24 & 0xFF) + "." + str(fw_version>>16 & 0xFF) + "." + str(fw_version>>8 & 0xFF) + "." + str(fw_version & 0xFF)
print ("fw_version:", fw_version_str)

# Check if the FW version matching with 5.x.x.x
assert fw_version == (fw_version & 0x05FFFFFF), "Expected FW version is 5.x.x.x, but received {}".format(fw_version_str)

# Get DFU device name
dfu_device = subprocess.check_output(["ls", "/sys/class/d4xx-class/"])
assert "d4xx-dfu-" in dfu_device, "D4xx DFU device not found"

# Get FW version from DFU device info
dfu_device_info = subprocess.check_output(["cat", "/dev/"+dfu_device.strip()])

# Check whether the DFU info also has same FW version
assert fw_version_str in dfu_device_info, "FW versions read through v4l2-ctl utility and DFU device info doesn't match"

except Exception as e:
assert False, e
Loading