From ab22c1b2b2f3367bac16080f87928eeacf1e8d1c Mon Sep 17 00:00:00 2001 From: Madhukar Reddy Kadireddy Date: Fri, 19 Apr 2024 20:10:13 +0530 Subject: [PATCH 1/4] added xternal_tests param in run-unit-tests.py --- unit-tests/run-unit-tests.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index 66e8d89df2..8ca2a6cf82 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -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( ' --xternal_tests <> External tests dir other than librealsense/unit-tests' ) + print( ' ex: $HOME/my_ws/my_tests' ) 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' ) @@ -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=', 'xternal_tests='] ) except getopt.GetoptError as err: log.e( err ) # something like "option -a not recognized" usage() @@ -98,6 +100,7 @@ def usage(): rslog = False only_live = False only_not_live = False +xternal_test_dir = None for opt, arg in opts: if opt in ('-h', '--help'): usage() @@ -150,6 +153,10 @@ def usage(): log.e( "--live and --not-live are mutually exclusive" ) usage() only_not_live = True + elif opt == '--xternal_tests': + xternal_test_dir = os.path.abspath(arg) + libci.unit_tests_dir = xternal_test_dir + log.i(f'External tests path set to: {xternal_test_dir}') def find_build_dir( dir ): """ @@ -229,10 +236,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 xternal_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( xternal_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 @@ -365,6 +378,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 xternal_test_dir: + current_dir = xternal_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: From 1d3559d0ed5411a5c349a713cf5fb3897857588f Mon Sep 17 00:00:00 2001 From: Madhukar Reddy Kadireddy Date: Sun, 21 Apr 2024 23:17:27 +0530 Subject: [PATCH 2/4] added param test_dir which points tests dir from else where --- unit-tests/run-unit-tests.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index 8ca2a6cf82..94c9237086 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -52,8 +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( ' --xternal_tests <> External tests dir other than librealsense/unit-tests' ) - print( ' ex: $HOME/my_ws/my_tests' ) + 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' ) @@ -80,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=', 'xternal_tests='] ) + 'rslog', 'skip-disconnected', 'live', 'not-live', 'device=', 'test-dir='] ) except getopt.GetoptError as err: log.e( err ) # something like "option -a not recognized" usage() @@ -100,7 +100,7 @@ def usage(): rslog = False only_live = False only_not_live = False -xternal_test_dir = None +test_dir = None for opt, arg in opts: if opt in ('-h', '--help'): usage() @@ -153,10 +153,10 @@ def usage(): log.e( "--live and --not-live are mutually exclusive" ) usage() only_not_live = True - elif opt == '--xternal_tests': - xternal_test_dir = os.path.abspath(arg) - libci.unit_tests_dir = xternal_test_dir - log.i(f'External tests path set to: {xternal_test_dir}') + 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 ): """ @@ -187,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) @@ -236,13 +235,13 @@ def find_build_dir( dir ): exe_dir = dir_with_test if not to_stdout: - if not xternal_test_dir: + 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( xternal_test_dir, 'logs' ) + logdir = os.path.join( test_dir, 'logs' ) os.makedirs( logdir, exist_ok=True ) libci.logdir = logdir @@ -378,8 +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 xternal_test_dir: - current_dir = xternal_test_dir + if test_dir: + 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: From 228d029dec9e659ed861cab694517a9f342525e0 Mon Sep 17 00:00:00 2001 From: Madhukar Reddy Kadireddy Date: Tue, 23 Apr 2024 19:56:34 +0530 Subject: [PATCH 3/4] added param test_dir which points tests dir from else where --- unit-tests/run-unit-tests.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index 94c9237086..e2a9e26d7d 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -100,7 +100,8 @@ def usage(): rslog = False only_live = False only_not_live = False -test_dir = None +test_dir = current_dir +test_dir_log = False for opt, arg in opts: if opt in ('-h', '--help'): usage() @@ -157,6 +158,7 @@ def usage(): 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 ): """ @@ -235,15 +237,13 @@ def find_build_dir( dir ): exe_dir = dir_with_test if not to_stdout: - if not test_dir: - # If no test executables were found, put the logs directly in the build directory + # If no test executables were found, put the logs directly in the build directory + if not test_dir_log: 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 + os.makedirs( logdir, exist_ok=True ) + libci.logdir = logdir n_tests = 0 @@ -328,7 +328,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 @@ -362,7 +362,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 )[ @@ -377,9 +377,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): - if test_dir: - current_dir = test_dir - 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 From 15029738cba8245c20358ff838581a3a41995809 Mon Sep 17 00:00:00 2001 From: Madhukar Reddy Kadireddy Date: Tue, 23 Apr 2024 20:00:48 +0530 Subject: [PATCH 4/4] minor correction --- unit-tests/run-unit-tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unit-tests/run-unit-tests.py b/unit-tests/run-unit-tests.py index e2a9e26d7d..3bdda1ac9f 100644 --- a/unit-tests/run-unit-tests.py +++ b/unit-tests/run-unit-tests.py @@ -189,6 +189,7 @@ 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)