def find_pyrs(): """ :return: the location (absolute path) of the pyrealsense2 .so (linux) or .pyd (windows) """ global build from rspy import file if platform.system() == 'Linux': for so in file.find(build, '(^|/)pyrealsense2.*\.so$'): return os.path.join(build, so) else: for pyd in file.find(build, '(^|/)pyrealsense2.*\.pyd$'): return os.path.join(build, pyd)
def find_pyrs(): """ :return: the location (absolute path) of the pyrealsense2 .so (linux) or .pyd (windows) """ global build import platform system = platform.system() linux = ( system == 'Linux' and "microsoft" not in platform.uname()[3].lower() ) from rspy import file if linux: for so in file.find( build, '(^|/)pyrealsense2.*\.so$' ): return os.path.join( build, so ) else: for pyd in file.find( build, '(^|/)pyrealsense2.*\.pyd$' ): return os.path.join( build, pyd )
def get_tests(): global regex, target, pyrs, current_dir, linux if regex: pattern = re.compile(regex) if target: # In Linux, the build targets are located elsewhere than on Windows # Go over all the tests from a "manifest" we take from the result of the last CMake # run (rather than, for example, looking for test-* in the build-directory): if linux: manifestfile = target + '/CMakeFiles/TargetDirectories.txt' else: manifestfile = target + '/../CMakeFiles/TargetDirectories.txt' # log.d( manifestfile ) for manifest_ctx in file.grep( r'(?<=unit-tests/build/)\S+(?=/CMakeFiles/test-\S+.dir$)', manifestfile): # We need to first create the test name so we can see if it fits the regex testdir = manifest_ctx['match'].group(0) # "log/internal/test-all" # log.d( testdir ) testparent = os.path.dirname(testdir) # "log/internal" if testparent: testname = 'test-' + testparent.replace( '/', '-') + '-' + os.path.basename(testdir)[ 5:] # "test-log-internal-all" else: testname = testdir # no parent folder so we get "test-all" if regex and not pattern.search(testname): continue if linux: exe = target + '/unit-tests/build/' + testdir + '/' + testname else: exe = target + '/' + testname + '.exe' yield libci.ExeTest(testname, exe, context) # 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'): 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 else: testname = os.path.basename(py_test)[:-3] if regex and not pattern.search(testname): continue yield libci.PyTest(testname, py_test, context)
def find_image_or_exit(product_name, fw_version_regex=r'(\d+\.){3}(\d+)'): """ Searches for a FW image file for the given camera name and optional version. If none are found, exits with an error! :param product_name: the name of the camera, from get_info(rs.camera_info.name) :param fw_version_regex: optional regular expression specifying which FW version image to find :return: the image file corresponding to product_name and fw_version if exist, otherwise exit """ pattern = re.compile(r'^Intel RealSense (((\S+?)(\d+))(\S*))') match = pattern.search(product_name) if not match: raise RuntimeError("Failed to parse product name '" + product_name + "'") # For a product 'PR567abc', we want to search, in order, these combinations: # PR567abc # PR306abX # PR306aXX # PR306 # PR30X # PR3XX # Each of the above, combined with the FW version, should yield an image name like: # PR567aXX_FW_Image-<fw-version>.bin suffix = 5 # the suffix for j in range(1, 3): # with suffix, then without start_index, end_index = match.span(j) for i in range(0, len(match.group(suffix))): pn = product_name[start_index:end_index - i] image_name = '(^|/)' + pn + i * 'X' + "_FW_Image-" + fw_version_regex + r'\.bin$' for image in file.find(repo.root, image_name): return os.path.join(repo.root, image) suffix -= 1 # # If we get here, we didn't find any image... global product_line log.f("Could not find image file for", product_line)
product_line = device.get_info(rs.camera_info.product_line) cmd = None if product_line == "L500": cmd = "14 00 AB CD 0A 00 00 00 30 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00" elif product_line == "D400": cmd = "14 00 AB CD 86 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" else: log.f("Incompatible product line:", product_line) send_hardware_monitor_command(device, cmd) # find the update tool exe fw_updater_exe = None for tool in file.find(repo.build, '(^|/)rs-fw-update.exe$'): fw_updater_exe = os.path.join(repo.build, tool) if not fw_updater_exe: log.f("Could not find the update tool file (rs-fw-update.exe)") devices.query(monitor_changes=False) sn_list = devices.all() # acroname should ensure there is always 1 available device if len(sn_list) != 1: log.f("Expected 1 device, got", len(sn_list)) device = devices.get_first(sn_list).handle log.d('found:', device) product_line = device.get_info(rs.camera_info.product_line) log.d('product line:', product_line) ###############################################################################
def process_cpp(dir, builddir): global regex, required_tags, list_only, available_tags, tests_and_tags found = [] shareds = [] statics = [] if regex: pattern = re.compile(regex) for f in file.find(dir, '(^|/)test-.*\.cpp$'): testdir = os.path.splitext(f)[ 0] # "log/internal/test-all" <- "log/internal/test-all.cpp" testparent = os.path.dirname(testdir) # "log/internal" # We need the project name unique: keep the path but make it nicer: testname = 'test-' + testparent.replace( '/', '-') + '-' + os.path.basename(testdir)[ 5:] # "test-log-internal-all" if regex and not pattern.search(testname): continue if required_tags or list_tags: config = libci.TestConfigFromCpp(dir + os.sep + f) if not all(tag in config.tags for tag in required_tags): continue available_tags.update(config.tags) if list_tests: tests_and_tags[testname] = config.tags if testname not in tests_and_tags: tests_and_tags[testname] = None if list_only: continue # Each CMakeLists.txt sits in its own directory os.makedirs(builddir + '/' + testdir, exist_ok=True) # "build/log/internal/test-all" # 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, '${ELPP_FILES}', '${CATCH_FILES}'] # Add any "" includes specified in the .cpp that we can find includes = find_includes(dir + '/' + f) # 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 for context in file.grep('^//#cmake:\s*', dir + '/' + f): m = context['match'] index = context['index'] cmd, *rest = context['line'][m.end():].split() if cmd == 'add-file': for additional_file in rest: files = additional_file if not os.path.isabs(additional_file): files = dir + '/' + testparent + '/' + additional_file files = glob(files) if not files: log.e(f + '+' + str(index) + ': no files match "' + additional_file + '"') for abs_file in files: abs_file = os.path.normpath(abs_file) abs_file = abs_file.replace('\\', '/') if not os.path.exists(abs_file): log.e(f + '+' + str(index) + ': file not found "' + additional_file + '"') log.d(' add file:', abs_file) 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) elif cmd == 'static!': if len(rest): log.e(f + '+' + str(index) + ': unexpected arguments past \'' + cmd + '\'') elif shared: log.e(f + '+' + str(index) + ': \'' + cmd + '\' mutually exclusive with \'shared!\'') else: static = True elif cmd == 'shared!': if len(rest): log.e(f + '+' + str(index) + ': unexpected arguments past \'' + cmd + '\'') elif static: log.e(f + '+' + str(index) + ': \'' + cmd + '\' mutually exclusive with \'static!\'') else: shared = True else: log.e( f + '+' + str(index) + ': unknown cmd \'' + cmd + '\' (should be \'add-file\', \'static!\', or \'shared!\')') for include in includes: filelist.append(include) generate_cmake(builddir, testdir, testname, filelist) if static: statics.append(testdir) elif shared: shareds.append(testdir) else: found.append(testdir) return found, shareds, statics
list_tags = True elif opt == '--list-tests': list_tests = True if len(args) > 1: usage() target = None if len(args) == 1: if os.path.isdir( args[0] ): target = args[0] else: usage() # Trying to assume target directory from inside build directory. Only works if there is only one location with tests if not target: build = repo.root + os.sep + 'build' for executable in file.find(build, '(^|/)test-.*'): if not file.is_executable(executable): continue dir_with_test = build + os.sep + os.path.dirname(executable) if target and target != dir_with_test: log.e("Found executable tests in 2 directories:", target, "and", dir_with_test, ". Can't default to directory") usage() target = dir_with_test if target: logdir = target + os.sep + 'unit-tests' else: # no test executables were found. We put the logs directly in build directory logdir = os.path.join( repo.root, 'build', 'unit-tests' ) os.makedirs( logdir, exist_ok = True ) n_tests = 0
for image in file.find(repo.root, image_name): return os.path.join(repo.root, image) suffix -= 1 # # If we get here, we didn't find any image... global product_line log.f("Could not find image file for", product_line) # find the update tool exe fw_updater_exe = None fw_updater_exe_regex = r'(^|/)rs-fw-update' if platform.system() == 'Windows': fw_updater_exe_regex += r'\.exe' fw_updater_exe_regex += '$' for tool in file.find(repo.build, fw_updater_exe_regex): fw_updater_exe = os.path.join(repo.build, tool) if not fw_updater_exe: log.f("Could not find the update tool file (rs-fw-update.exe)") devices.query(monitor_changes=False) sn_list = devices.all() # acroname should ensure there is always 1 available device if len(sn_list) != 1: log.f("Expected 1 device, got", len(sn_list)) device = devices.get_first(sn_list).handle log.d('found:', device) product_line = device.get_info(rs.camera_info.product_line) product_name = device.get_info(rs.camera_info.name) log.d('product line:', product_line) ###############################################################################
exe_dir = None # the directory in which we expect to find exes if len(args) == 1: exe_dir = args[0] if not os.path.isdir(exe_dir): log.f('Not a directory:', exe_dir) build_dir = find_build_dir(exe_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) pyrs = "" if linux: for so in file.find(exe_dir or build_dir or repo.root, '(^|/)pyrealsense2.*\.so$'): pyrs = so else: for pyd in file.find(exe_dir or build_dir or repo.root, '(^|/)pyrealsense2.*\.pyd$'): pyrs = pyd if pyrs: # The path is relative; make it absolute and add to PYTHONPATH so it can be found by tests pyrs_path = os.path.join(exe_dir or build_dir or repo.root, pyrs) # We need to add the directory not the file itself pyrs_path = os.path.dirname(pyrs_path) log.d('found pyrealsense pyd in:', pyrs_path) if not exe_dir: build_dir = find_build_dir(pyrs_path) if linux: exe_dir = build_dir
start_index, end_index = match.span(j) for i in range(0, len(match.group(suffix))): pn = product_name[start_index:end_index - i] image_name = '(^|/)' + pn + i * 'X' + "_FW_Image-" + fw_version_regex + r'\.bin$' for image in file.find(repo.root, image_name): return os.path.join(repo.root, image) suffix -= 1 # # If we get here, we didn't find any image... global product_line log.f("Could not find image file for", product_line) # find the update tool exe fw_updater_exe = None for tool in file.find(repo.build, '(^|/)rs-fw-update.exe$'): fw_updater_exe = os.path.join(repo.build, tool) if not fw_updater_exe: log.f("Could not find the update tool file (rs-fw-update.exe)") devices.query(monitor_changes=False) sn_list = devices.all() # acroname should ensure there is always 1 available device if len(sn_list) != 1: log.f("Expected 1 device, got", len(sn_list)) device = devices.get_first(sn_list).handle log.d('found:', device) product_line = device.get_info(rs.camera_info.product_line) product_name = device.get_info(rs.camera_info.name) log.d('product line:', product_line) ###############################################################################