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

added param test_dir in run-unit-tests.py #12874

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Changes from 2 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
26 changes: 20 additions & 6 deletions unit-tests/run-unit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def usage():
print( ' --hub-reset If a hub is available, reset the hub itself' )
print( ' --rslog Enable LibRS logging (LOG_DEBUG etc.) to console in each test' )
print( ' --skip-disconnected Skip live test if required device is disconnected (only applies w/o a hub)' )
print( ' --test-dir <> Path to test dir; default: librealsense/unit-tests' )
print( ' ex: --test-dir $HOME/my_ws/my_tests; logs are stored in the same dir' )
print( 'Examples:' )
print( 'Running: python run-unit-tests.py -s' )
print( ' Runs all tests, but direct their output to the console rather than log files' )
Expand All @@ -78,7 +80,7 @@ def usage():
opts, args = getopt.getopt( sys.argv[1:], 'hvqr:st:',
longopts=['help', 'verbose', 'debug', 'quiet', 'regex=', 'stdout', 'tag=', 'list-tags',
'list-tests', 'no-exceptions', 'context=', 'repeat=', 'config=', 'no-reset', 'hub-reset',
'rslog', 'skip-disconnected', 'live', 'not-live', 'device='] )
'rslog', 'skip-disconnected', 'live', 'not-live', 'device=', 'test-dir='] )
except getopt.GetoptError as err:
log.e( err ) # something like "option -a not recognized"
usage()
Expand All @@ -98,6 +100,7 @@ def usage():
rslog = False
only_live = False
only_not_live = False
test_dir = None
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
Expand Down Expand Up @@ -150,6 +153,10 @@ def usage():
log.e( "--live and --not-live are mutually exclusive" )
usage()
only_not_live = True
elif opt == '--test-dir':
test_dir = os.path.abspath(arg)
libci.unit_tests_dir = test_dir
log.i(f'Tests dir changed from default to: {test_dir}')

def find_build_dir( dir ):
"""
Expand Down Expand Up @@ -180,7 +187,6 @@ def find_build_dir( dir ):
else:
build_dir = repo.build # may not actually contain exes
#log.d( 'repo.build:', build_dir )

# Python scripts should be able to find the pyrealsense2 .pyd or else they won't work. We don't know
# if the user (Travis included) has pyrealsense2 installed but even if so, we want to use the one we compiled.
# we search the librealsense repository for the .pyd file (.so file in linux)
Expand Down Expand Up @@ -229,10 +235,16 @@ def find_build_dir( dir ):
exe_dir = dir_with_test

if not to_stdout:
# If no test executables were found, put the logs directly in the build directory
logdir = os.path.join( exe_dir or build_dir or os.path.join( repo.root, 'build' ), 'unit-tests' )
os.makedirs( logdir, exist_ok=True )
libci.logdir = logdir
if not test_dir:
# If no test executables were found, put the logs directly in the build directory
logdir = os.path.join( exe_dir or build_dir or os.path.join( repo.root, 'build' ), 'unit-tests' )
os.makedirs( logdir, exist_ok=True )
libci.logdir = logdir
else:
logdir = os.path.join( test_dir, 'logs' )
os.makedirs( logdir, exist_ok=True )
libci.logdir = logdir

n_tests = 0

# Figure out which sys.path we want the tests to see, assuming we have Python tests
Expand Down Expand Up @@ -365,6 +377,8 @@ def get_tests():

# Python unit-test scripts are in the same directory as us... we want to consider running them
# (we may not if they're live and we have no pyrealsense2.pyd):
if test_dir:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the global variable current_dir, it's used as the script directory also. Use a local variable to assign test_dir or current_dir to search for the tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Point taken and incorporated these comments.

current_dir = test_dir
for py_test in file.find( current_dir, '(^|/)test-.*\.py' ):
testparent = os.path.dirname( py_test ) # "log/internal" <- "log/internal/test-all.py"
if testparent:
Expand Down
Loading