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

enable unit-test-config --live #12239

Merged
merged 3 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion common/utilities/imgui/wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <sstream>
#include "wrap.h"
#include <rsutils/string/split.h>
#include "../third-party/imgui/imgui.h"
#include <third-party/imgui/imgui.h>

namespace utilities {
namespace imgui {
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/py/rspy/libci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/concurrency/test-scq.cpp
Original file line number Diff line number Diff line change
@@ -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 <unit-tests/test.h>
#include <rsutils/time/timer.h>
#include <rsutils/concurrency/concurrency.h>
Expand Down
1 change: 1 addition & 0 deletions unit-tests/rsutils/imgui/test-wrap.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <thread>
#include <chrono>
#include "../../../test.h"
#include <unit-tests/test.h>
#include <rsutils/number/stabilized-value.h>

using namespace rsutils::number;
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/string/test-string-to-value.cpp
Original file line number Diff line number Diff line change
@@ -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 <rsutils/string/string-utilities.h>
#include <ostream>
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/string/test-trim-newlines.cpp
Original file line number Diff line number Diff line change
@@ -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 <rsutils/string/trim-newlines.h>

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/time/test-periodic_timer.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/time/test-stopwatch.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/time/test-timer.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/time/test-waiting-on.cpp
Original file line number Diff line number Diff line change
@@ -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 <rsutils/string/chrono.h> // must be before catch.h!
#include <unit-tests/catch.h>
#include <rsutils/time/waiting-on.h>
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/rsutils/time/test-work_week.cpp
Original file line number Diff line number Diff line change
@@ -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 <rsutils/time/work-week.h>
#include <ctime>
Expand Down
3 changes: 3 additions & 0 deletions unit-tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

#pragma once

#ifdef LIBCI_DEPENDENCY_realsense2
#include <librealsense2/rs.hpp>
#endif
#include "catch.h"
#include <sstream>


namespace test {
Expand Down
52 changes: 32 additions & 20 deletions unit-tests/unit-test-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ 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
required_tags = []
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()
Expand All @@ -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()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -145,50 +150,51 @@ 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:
log.debug_unindent()
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 = []
Expand All @@ -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 )
Expand All @@ -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 <filename>
# 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']
Expand All @@ -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 + '\'' )
Expand All @@ -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}' )

Expand Down
3 changes: 3 additions & 0 deletions unit-tests/unit-test-default-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}