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 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
23 changes: 18 additions & 5 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,8 @@ def usage():
rslog = False
only_live = False
only_not_live = False
test_dir = current_dir
test_dir_log = False
for opt, arg in opts:
if opt in ('-h', '--help'):
usage()
Expand Down Expand Up @@ -150,6 +154,11 @@ 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}')
test_dir_log = True

def find_build_dir( dir ):
"""
Expand Down Expand Up @@ -230,9 +239,13 @@ def find_build_dir( dir ):

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' )
if not test_dir_log:
logdir = os.path.join( exe_dir or build_dir or os.path.join( repo.root, 'build' ), 'unit-tests' )
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 @@ -316,7 +329,7 @@ def check_log_for_fails( path_to_log, testname, configuration=None, repetition=1


def get_tests():
global regex, build_dir, exe_dir, pyrs, current_dir, linux, context, list_only
global regex, build_dir, exe_dir, pyrs, test_dir, linux, context, list_only
if regex:
pattern = re.compile( regex )
# In Linux, the build targets are located elsewhere than on Windows
Expand Down Expand Up @@ -350,7 +363,7 @@ def get_tests():
elif list_only:
# We want to list all tests, even if they weren't built.
# So we look for the source files instead of using the manifest
for cpp_test in file.find( current_dir, '(^|/)test-.*\.cpp' ):
for cpp_test in file.find( test_dir, '(^|/)test-.*\.cpp' ):
testparent = os.path.dirname( cpp_test ) # "log/internal" <- "log/internal/test-all.py"
if testparent:
testname = 'test-' + testparent.replace( '/', '-' ) + '-' + os.path.basename( cpp_test )[
Expand All @@ -365,7 +378,7 @@ 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):
for py_test in file.find( current_dir, '(^|/)test-.*\.py' ):
for py_test in file.find( test_dir, '(^|/)test-.*\.py' ):
testparent = os.path.dirname( py_test ) # "log/internal" <- "log/internal/test-all.py"
if testparent:
testname = 'test-' + testparent.replace( '/', '-' ) + '-' + os.path.basename( py_test )[5:-3] # remove .py
Expand Down
Loading