diff --git a/common/utilities/imgui/wrap.cpp b/common/utilities/imgui/wrap.cpp index 4f956e9f75..fc8adc0f21 100644 --- a/common/utilities/imgui/wrap.cpp +++ b/common/utilities/imgui/wrap.cpp @@ -6,7 +6,7 @@ #include #include "wrap.h" #include -#include "../third-party/imgui/imgui.h" +#include namespace utilities { namespace imgui { diff --git a/unit-tests/py/rspy/libci.py b/unit-tests/py/rspy/libci.py index e1cb24e030..ac723d777d 100644 --- a/unit-tests/py/rspy/libci.py +++ b/unit-tests/py/rspy/libci.py @@ -193,7 +193,7 @@ def derive_config_from_text( self, source, line_prefix ): # 0 | 1 | USE # 1 | 0 | USE # 1 | 1 | IGNORE - if not_context == (directive_context in self._context): + if not_context == (self._context and directive_context in self._context): # log.d( "directive", line['line'], "ignored because of context mismatch with running context", # self._context) continue diff --git a/unit-tests/rsutils/concurrency/test-scq.cpp b/unit-tests/rsutils/concurrency/test-scq.cpp index 22cc21aae6..44d8aedb00 100644 --- a/unit-tests/rsutils/concurrency/test-scq.cpp +++ b/unit-tests/rsutils/concurrency/test-scq.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2021 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include #include #include diff --git a/unit-tests/rsutils/imgui/test-wrap.cpp b/unit-tests/rsutils/imgui/test-wrap.cpp index f3715becee..a4cc615cdf 100644 --- a/unit-tests/rsutils/imgui/test-wrap.cpp +++ b/unit-tests/rsutils/imgui/test-wrap.cpp @@ -1,6 +1,7 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils //#cmake:add-file ../../../common/utilities/imgui/wrap.cpp #include "common.h" diff --git a/unit-tests/rsutils/number/stabilized/test-multi-threading.cpp b/unit-tests/rsutils/number/stabilized/test-multi-threading.cpp index c3a9233684..540e6d1e63 100644 --- a/unit-tests/rsutils/number/stabilized/test-multi-threading.cpp +++ b/unit-tests/rsutils/number/stabilized/test-multi-threading.cpp @@ -1,9 +1,11 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include #include -#include "../../../test.h" +#include #include using namespace rsutils::number; diff --git a/unit-tests/rsutils/string/test-string-to-value.cpp b/unit-tests/rsutils/string/test-string-to-value.cpp index 24fa5942d6..aa000345b9 100644 --- a/unit-tests/rsutils/string/test-string-to-value.cpp +++ b/unit-tests/rsutils/string/test-string-to-value.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include "common.h" #include #include diff --git a/unit-tests/rsutils/string/test-trim-newlines.cpp b/unit-tests/rsutils/string/test-trim-newlines.cpp index 95ebbb344c..f0f8ffde71 100644 --- a/unit-tests/rsutils/string/test-trim-newlines.cpp +++ b/unit-tests/rsutils/string/test-trim-newlines.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include "common.h" #include diff --git a/unit-tests/rsutils/time/test-periodic_timer.cpp b/unit-tests/rsutils/time/test-periodic_timer.cpp index 12f20c44da..dc095d2f9b 100644 --- a/unit-tests/rsutils/time/test-periodic_timer.cpp +++ b/unit-tests/rsutils/time/test-periodic_timer.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + // Unit Test Goals: // Test the timer utility classes: stopwatch, timer, periodic_timer. diff --git a/unit-tests/rsutils/time/test-stopwatch.cpp b/unit-tests/rsutils/time/test-stopwatch.cpp index 0a0d88378d..661fa76156 100644 --- a/unit-tests/rsutils/time/test-stopwatch.cpp +++ b/unit-tests/rsutils/time/test-stopwatch.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + // Unit Test Goals: // Test the timer utility classes: stopwatch, timer, periodic_timer. diff --git a/unit-tests/rsutils/time/test-timer.cpp b/unit-tests/rsutils/time/test-timer.cpp index fd563d896f..791d445ea3 100644 --- a/unit-tests/rsutils/time/test-timer.cpp +++ b/unit-tests/rsutils/time/test-timer.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + // Unit Test Goals: // Test the timer utility classes: stopwatch, timer, periodic_timer. diff --git a/unit-tests/rsutils/time/test-waiting-on.cpp b/unit-tests/rsutils/time/test-waiting-on.cpp index 567287cfe9..56a2e97fea 100644 --- a/unit-tests/rsutils/time/test-waiting-on.cpp +++ b/unit-tests/rsutils/time/test-waiting-on.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2021 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include // must be before catch.h! #include #include diff --git a/unit-tests/rsutils/time/test-work_week.cpp b/unit-tests/rsutils/time/test-work_week.cpp index 8504d13b6f..40c099c957 100644 --- a/unit-tests/rsutils/time/test-work_week.cpp +++ b/unit-tests/rsutils/time/test-work_week.cpp @@ -1,6 +1,8 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2020 Intel Corporation. All Rights Reserved. +//#cmake:dependencies rsutils + #include "common.h" #include #include diff --git a/unit-tests/test.h b/unit-tests/test.h index c88b9c1308..0cbc8cf67c 100644 --- a/unit-tests/test.h +++ b/unit-tests/test.h @@ -3,8 +3,11 @@ #pragma once +#ifdef LIBCI_DEPENDENCY_realsense2 #include +#endif #include "catch.h" +#include namespace test { diff --git a/unit-tests/unit-test-config.py b/unit-tests/unit-test-config.py index 6af68f8540..7883d0f39b 100644 --- a/unit-tests/unit-test-config.py +++ b/unit-tests/unit-test-config.py @@ -35,7 +35,8 @@ def usage(): print( ' --list-tests print out all available tests. This option will not run any tests' ) print( ' if both list-tags and list-tests are specified each test will be printed along' ) print( ' with what tags it has' ) - print( ' --context The context to use for test configuration' ) + print( ' --context The context to use for test configuration' ) + print( ' --live Only configure tests that are live (have test:device)' ) sys.exit(2) regex = None @@ -43,10 +44,11 @@ def usage(): list_tags = False list_tests = False context = None +live_only = False # parse command-line: try: opts, args = getopt.getopt( sys.argv[1:], 'hr:t:', - longopts=['help', 'regex=', 'tag=', 'list-tags', 'list-tests', 'context='] ) + longopts=['help', 'regex=', 'tag=', 'list-tags', 'list-tests', 'context=', 'live'] ) except getopt.GetoptError as err: log.e( err ) # something like "option -a not recognized" usage() @@ -63,6 +65,8 @@ def usage(): list_tests = True elif opt == '--context': context = arg + elif opt == '--live': + live_only = True if len( args ) != 2: usage() @@ -111,6 +115,7 @@ def generate_cmake( builddir, testdir, testname, filelist, custom_main, dependen set( SRC_FILES ''' + filelist + ''' ) add_executable( ${PROJECT_NAME} ${SRC_FILES} ) +add_definitions( ''' + ' '.join( f'-DLIBCI_DEPENDENCY_{d}' for d in dependencies.split() ) + ''' ) source_group( "Common Files" FILES ${CATCH_FILES} ''' + directory + '''/test.cpp''') if not custom_main: handle.write(' ' + directory + '/unit-test-default-main.cpp') @@ -145,42 +150,43 @@ def find_include( include, relative_to ): return include -standard_include_dirs = [ - os.path.join( root, 'include' ), - os.path.join( root, 'third-party', 'rsutils', 'include' ), - root - ] -def find_include_in_dirs( include ): +def find_include_in_dirs( include, dirs ): """ - Search for the given include in all the standard include directories + Search for the given include in all the specified directories """ - global include_dirs - for include_dir in standard_include_dirs: + for include_dir in dirs: path = find_include( include, include_dir ) if path: return path -def find_includes( filepath, filelist ): +def find_includes( filepath, filelist, dependencies ): """ Recursively searches a .cpp file for #include directives :param filelist: any previous includes already processed (pass an empty dict() if none) + :param dependencies: set of dependencies :return: a dictionary (include->source) of includes found """ + include_dirs = list() + if 'realsense2' in dependencies: + include_dirs.append( os.path.join( root, 'include' )) + include_dirs.append( os.path.join( root, 'third-party', 'rsutils', 'include' )) + include_dirs.append( root ) + filedir = os.path.dirname(filepath) try: log.debug_indent() for include_line in file.grep( r'^\s*#\s*include\s+("(.*)"|<(.*)>)\s*$', filepath ): m = include_line['match'] index = include_line['index'] - include = find_include( m.group(2), filedir ) or find_include_in_dirs( m.group(2) ) or find_include_in_dirs( m.group(3) ) + include = find_include( m.group(2), filedir ) or find_include_in_dirs( m.group(2), include_dirs ) or find_include_in_dirs( m.group(3), include_dirs ) if include: if include in filelist: log.d( m.group(0), '->', include, '(already processed)' ) else: log.d( m.group(0), '->', include ) filelist[include] = filepath - filelist = find_includes( include, filelist ) + filelist = find_includes( include, filelist, dependencies ) else: log.d( 'not found:', m.group(0) ) finally: @@ -188,7 +194,7 @@ def find_includes( filepath, filelist ): return filelist def process_cpp( dir, builddir ): - global regex, required_tags, list_only, available_tags, tests_and_tags + global regex, required_tags, list_only, available_tags, tests_and_tags, live_only found = [] shareds = [] statics = [] @@ -211,8 +217,8 @@ def process_cpp( dir, builddir ): log.d( '... found:', f ) log.debug_indent() try: + config = libci.TestConfigFromCpp( dir + os.sep + f, context ) if required_tags or list_tags: - config = libci.TestConfigFromCpp( dir + os.sep + f, context ) if not all( tag in config.tags for tag in required_tags ): continue available_tags.update( config.tags ) @@ -222,18 +228,21 @@ def process_cpp( dir, builddir ): if testname not in tests_and_tags: tests_and_tags[testname] = None + if live_only: + if not config.configurations: + continue + # Build the list of files we want in the project: # At a minimum, we have the original file, plus any common files filelist = [ dir + '/' + f, '${CATCH_FILES}' ] - # Add any includes specified in the .cpp that we can find - includes = find_includes( dir + '/' + f, dict() ) + includes = dict() # Add any files explicitly listed in the .cpp itself, like this: # //#cmake:add-file # Any files listed are relative to $dir shared = False static = False custom_main = False - dependencies = '${DEPENDENCIES}' # most will depend on realsense2 (the default in unit-tests/CMakeLists.txt) + dependencies = 'realsense2' for cmake_directive in file.grep( '^//#cmake:\s*', dir + '/' + f ): m = cmake_directive['match'] index = cmake_directive['index'] @@ -255,7 +264,7 @@ def process_cpp( dir, builddir ): filelist.append( abs_file ) if( os.path.splitext( abs_file )[0] == 'cpp' ): # Add any "" includes specified in the .cpp that we can find - includes = find_includes( abs_file, includes ) + includes = find_includes( abs_file, includes, dependencies ) elif cmd == 'static!': if len(rest): log.e( f + '+' + str(index) + ': unexpected arguments past \'' + cmd + '\'' ) @@ -278,6 +287,9 @@ def process_cpp( dir, builddir ): dependencies = ' '.join( rest ) else: log.e( f + '+' + str(index) + ': unknown cmd \'' + cmd + '\' (should be \'add-file\', \'static!\', or \'shared!\')' ) + + # Add any includes specified in the .cpp that we can find + includes = find_includes( dir + '/' + f, includes, dependencies ) for include,source in includes.items(): filelist.append( f'"{include}" # {source}' ) diff --git a/unit-tests/unit-test-default-main.cpp b/unit-tests/unit-test-default-main.cpp index 48fb7dadd5..8f972c4006 100644 --- a/unit-tests/unit-test-default-main.cpp +++ b/unit-tests/unit-test-default-main.cpp @@ -59,8 +59,11 @@ int main( int argc, char * argv[] ) if( ret ) return ret; // >0 == Error code +#ifdef LIBCI_DEPENDENCY_realsense2 + // rs2::log_to_console() is only available if realsense2 is a dependency of ours if( rslog ) rs2::log_to_console( RS2_LOG_SEVERITY_DEBUG ); +#endif return session.run(); }