-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ROSCI basic infra to enable single live_cam test #3076
Changes from 2 commits
f79904d
023476c
9c2c500
47315ed
ab9eaf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# Copyright 2023 Intel Corporation. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys, os, subprocess, re, platform, getopt, time | ||
sys.path.append( os.path.join( os.environ['WORKSPACE'], 'lrs/unit-tests/py' )) | ||
from rspy import log, file, repo, libci | ||
start_time = time.time() | ||
current_dir = os.path.dirname( os.path.abspath( __file__ ) ) | ||
print(f'{current_dir}') | ||
root = os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname( os.path.abspath( __file__ )))))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks very weird, what's going on here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. restructured in commit # 5 |
||
dir_live_tests = os.path.join( os.environ['WORKSPACE'], 'ros2/realsense2_camera/test/live_camera' ) | ||
|
||
hub_reset = False | ||
logdir = None | ||
handle = None | ||
def usage(): | ||
ourname = os.path.basename( sys.argv[0] ) | ||
print( 'Syntax: ' + ourname + ' [options] [dir]' ) | ||
print( ' dir: location of executable tests to run' ) | ||
print( 'Options:' ) | ||
print( ' --debug Turn on debugging information (does not include LibRS debug logs; see --rslog)' ) | ||
print( ' -v, --verbose Errors will dump the log to stdout' ) | ||
print( ' -q, --quiet Suppress output; rely on exit status (0=no failures)' ) | ||
print( ' -s, --stdout Do not redirect stdout to logs' ) | ||
print( ' -r, --regex Run all tests whose name matches the following regular expression' ) | ||
print( ' --list-tests Print out all available tests. This option will not run any tests' ) | ||
print( ' --repeat <#> Repeat each test <#> times' ) | ||
print( ' --config <> Ignore test configurations; use the one provided' ) | ||
print( ' --device <> Run only on the specified devices; ignore any test that does not match (implies --live)' ) | ||
print( ' --no-reset Do not try to reset any devices, with or without a hub' ) | ||
print( ' --hub-reset If a hub is available, reset the hub itself' ) | ||
print( ' --skip-disconnected Skip live test if required device is disconnected (only applies w/o a hub)' ) | ||
print( 'Examples:' ) | ||
print( 'Running: python3.10 rosci.py -s' ) | ||
print( ' Runs all tests, but direct their output to the console rather than log files' ) | ||
print( 'Running: python3.10 rosci.py --list-tests' ) | ||
print( " Will find all tests and print" ) | ||
|
||
sys.exit( 2 ) | ||
|
||
def command(dev_name): | ||
cmd = ['pytest-3'] | ||
cmd += ['-s'] | ||
cmd += ['-m', ''.join(dev_name)] | ||
cmd += ['-k', 'test_camera_imu_tests'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand for now, the test name is hardcoded. But shall we hardcode the things outside and have this function generic? So that you don't need to touch this function later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next PR will carry these these fixes |
||
#cmd += ['-m', 'd415'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaned up in commit # 5 |
||
cmd += [''.join(dir_live_tests)] | ||
cmd += ['--debug'] | ||
return cmd | ||
|
||
def run_test(cmd, dev_name, stdout=None, append =False): | ||
handle = None | ||
try: | ||
stdout = stdout + os.sep + str(dev_name) + '_' + "test_camera_imu_tests" + ".log" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here... |
||
if stdout is None: | ||
sys.stdout.flush() | ||
elif stdout and stdout != subprocess.PIPE: | ||
if append: | ||
handle = open( stdout, "a" ) | ||
handle.write( | ||
"\n----------TEST-SEPARATOR----------\n\n" ) | ||
handle.flush() | ||
else: | ||
handle = open( stdout, "w" ) | ||
|
||
result = subprocess.run( cmd, | ||
stdout=handle, | ||
stderr=subprocess.STDOUT, | ||
universal_newlines=True, | ||
timeout=200, | ||
check=True ) | ||
|
||
except Exception as e: | ||
log.w( "Error Exception:\n ",e ) | ||
|
||
finally: | ||
if handle: | ||
handle.close() | ||
|
||
device_set = None | ||
try: | ||
opts, args = getopt.getopt( sys.argv[1:], 'hvqr:st:', | ||
longopts=['help', 'verbose', 'debug', 'quiet', 'regex=', 'stdout', 'tag=', 'list-tags', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe only add option you support? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaned up in commit # 5. Not supporting any option for this PR. Test name and device name hard-coded for this PR. |
||
'list-tests', 'no-exceptions', 'context=', 'repeat=', 'config=', 'no-reset', 'hub-reset', | ||
'rslog', 'skip-disconnected', 'live', 'not-live', 'device='] ) | ||
except getopt.GetoptError as err: | ||
log.e( err ) # something like "option -a not recognized" | ||
usage() | ||
for opt, arg in opts: | ||
if opt in ('-h', '--help'): | ||
usage() | ||
elif opt == '--device': | ||
device_set = arg.split() | ||
for dev in device_set: | ||
print(dev) | ||
#Get into action | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
try: | ||
logdir = os.path.join( os.path.dirname( os.path.dirname( os.path.dirname( os.path.abspath( __file__ )))), 'log') | ||
os.makedirs( logdir, exist_ok=True ) | ||
print(logdir) | ||
|
||
|
||
|
||
#Import '_device_by_sn' from devices.py module of librealsense repo | ||
from rspy import devices | ||
if not devices.hub: | ||
assert False, 'hub not available' | ||
else: | ||
devices.hub.connect() | ||
devices.query( hub_reset = hub_reset ) | ||
#devices.map_unknown_ports() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaned-up |
||
global _device_by_sn | ||
|
||
if not devices._device_by_sn: | ||
assert False, 'No Camera Devices detected!' | ||
else: | ||
#Loop in for all devices and run tests | ||
for device in devices._device_by_sn.values(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not add a devices.py like in LibCI and query devices? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, query devices thru devices.py module which stores the device data in dict -- '_device_by_sn' , and then processing of data happens here |
||
print(f'\033[93m Device found: {device.name} \033[0]') | ||
Nir-Az marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for device in devices._device_by_sn.values(): | ||
if device.name == 'D455': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here... |
||
print('Running test on device:', device.name) | ||
cmd = command(str(device.name).lower()) | ||
run_test(cmd, device.name, stdout=logdir, append =False) | ||
elif device.name != 'D455': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This elif looks redundant, if it's not D455 it's not D455 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleaned-up |
||
print('Skipping test on device:', device.name) | ||
|
||
finally: | ||
devices.hub.disconnect() | ||
run_time = time.time() - start_time | ||
log.d( "server took", run_time, "seconds" ) | ||
|
||
sys.exit( 0 ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the current script return ~= 0 if the test failed and 0 if it pass? Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's right. Made it little more clear in commit # 3. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test ROS stage fails when the subprocess.run() returns non zero exit status. However, there is NO log processing mechanism implemented yet as to why the test failed. For now, logs have to be checked manually if test fails @ "Build artifacts": ros2/realsense2_camera/log/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected in commit # 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GHA failing for 2024, hence reverted to 2023 again w/ commit # 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Arun-Prasad-V / @SamerKhshiboun haven't we fixed that to be generic?