コード例 #1
0
ファイル: devices.py プロジェクト: krbeverx/librealsense
def wait_until_all_ports_disabled(timeout=5):
    """
    Waits for all ports to be disabled
    """
    for retry in range(timeout):
        if len(enabled()) == 0:
            return True
        time.sleep(1)
    log.w('Timed out waiting for 0 devices')
    return False
コード例 #2
0
    def find_source_path(self):
        """
        :return: The relative path from unit-tests directory to the test's source file (cpp or py). If the source
                 file is not found None will be returned
        """
        # TODO: this is limited to a structure in which .cpp files and directories do not share names
        # For example:
        #     unit-tests/
        #         func/
        #             ...
        #         test-func.cpp
        # test-func.cpp will not be found!

        global unit_tests_dir
        split_testname = self.name.split('-')
        path = unit_tests_dir
        relative_path = ""
        found_test_dir = False

        while not found_test_dir:
            # index 0 should be 'test' as tests always start with it
            found_test_dir = True
            for i in range(
                    2, len(split_testname)
            ):  # Checking if the next part of the test name is a sub-directory
                possible_sub_dir = '-'.join(
                    split_testname[1:i]
                )  # The next sub-directory could have several words
                sub_dir_path = path + os.sep + possible_sub_dir
                if os.path.isdir(sub_dir_path):
                    path = sub_dir_path
                    relative_path += possible_sub_dir + os.sep
                    del split_testname[1:i]
                    found_test_dir = False
                    break

        path += os.sep + '-'.join(split_testname)
        relative_path += '-'.join(split_testname)
        if os.path.isfile(path + ".cpp"):
            relative_path += ".cpp"
        elif os.path.isfile(path + ".py"):
            relative_path += ".py"
        else:
            log.w(
                log.red + self.name + log.reset + ':',
                'No matching .cpp or .py file was found; no configuration will be used!'
            )
            return None

        return relative_path
コード例 #3
0
def devices_by_test_config( test ):
    """
    Yield <configuration,serial-numbers> pairs for each valid configuration under which the
    test should run.

    The <configuration> is a list of ('test:device') designations, e.g. ['L500*', 'D415'].
    The <serial-numbers> is a set of device serial-numbers that fit this configuration.

    :param test: The test (of class type Test) we're interested in
    """
    for configuration in test.config.configurations:
        try:
            serial_numbers = devices.by_configuration( configuration )
        except RuntimeError as e:
            if devices.acroname:
                log.e( log.red + test.name + log.reset + ': ' + str(e) )
            else:
                log.w( log.yellow + test.name + log.reset + ': ' + str(e) )
            continue
        yield configuration, serial_numbers
コード例 #4
0
    def __init__( self, testname, exe ):
        """
        :param testname: name of the test
        :param exe: full path to executable
        """
        global current_dir
        Test.__init__(self, testname)
        self.exe = exe

        # Finding the c/cpp file of the test to get the configuration
        # TODO: this is limited to a structure in which .cpp files and directories do not share names
        # For example:
        #     unit-tests/
        #         func/
        #             ...
        #         test-func.cpp
        # test-func.cpp will not be found!
        split_testname = testname.split( '-' )
        cpp_path = current_dir
        found_test_dir = False

        while not found_test_dir:
            # index 0 should be 'test' as tests always start with it
            found_test_dir = True
            for i in range(2, len(split_testname) ): # Checking if the next part of the test name is a sub-directory
                sub_dir_path = cpp_path + os.sep + '-'.join(split_testname[1:i]) # The next sub-directory could have several words
                if os.path.isdir(sub_dir_path):
                    cpp_path = sub_dir_path
                    del split_testname[1:i]
                    found_test_dir = False
                    break

        cpp_path += os.sep + '-'.join( split_testname )
        if os.path.isfile( cpp_path + ".cpp" ):
            cpp_path += ".cpp"
            self._config = TestConfigFromText(cpp_path, r'//#\s*test:')
        else:
            log.w( log.red + testname + log.reset + ':', 'No matching .cpp file was found; no configuration will be used!' )
コード例 #5
0
    #
    # Have to add site-packages, just in case: if -S was used, or parent script played with
    # sys.path (as run-unit-tests does), then we may not have it!
    sys.path += [os.path.join( os.path.dirname( sys.executable ), 'lib', 'site-packages')]
    #
    try:
        from rspy import acroname
    except ModuleNotFoundError:
        # Error should have already been printed
        # We assume there's no brainstem library, meaning no acroname either
        log.d( 'sys.path=', sys.path )
        acroname = None
    #
    sys.path = sys.path[:-1]  # remove what we added
except ModuleNotFoundError:
    log.w( 'No pyrealsense2 library is available! Running as if no cameras available...' )
    import sys
    log.d( 'sys.path=', sys.path )
    rs = None
    acroname = None

import time

_device_by_sn = dict()
_context = None


class Device:
    def __init__( self, sn, dev ):
        self._sn = sn
        self._dev = dev
コード例 #6
0
ファイル: repo.py プロジェクト: krbeverx/librealsense
root = os.path.dirname(
    os.path.dirname(os.path.dirname(os.path.dirname(
        os.path.abspath(__file__)))))

# Usually we expect the build directory to be directly under the root, named 'build'
# ... but first check the expected LibCI build directories:
#
if platform.system() == 'Linux':
    build = os.path.join(root, 'x86_64', 'static')
else:
    build = os.path.join(root, 'win10', 'win64', 'static')
if not os.path.isdir(build):
    #
    build = os.path.join(root, 'build')
    if not os.path.isdir(build):
        log.w('repo.build directory wasn\'t found')
        log.d('repo.root=', root)
        build = None


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$'):
コード例 #7
0
ファイル: devices.py プロジェクト: krbeverx/librealsense
def map_unknown_ports():
    """
    Fill in unknown ports in devices by enabling one port at a time, finding out which device
    is there.
    """
    if not acroname:
        return
    global _device_by_sn
    devices_with_unknown_ports = [
        device for device in _device_by_sn.values() if device.port is None
    ]
    if not devices_with_unknown_ports:
        return
    #
    ports = acroname.ports()
    known_ports = [
        device.port for device in _device_by_sn.values()
        if device.port is not None
    ]
    unknown_ports = [port for port in ports if port not in known_ports]
    try:
        log.d('mapping unknown ports', unknown_ports, '...')
        log.debug_indent()
        #log.d( "active ports:", ports )
        #log.d( "- known ports:", known_ports )
        #log.d( "= unknown ports:", unknown_ports )
        #
        for known_port in known_ports:
            if known_port not in ports:
                log.e("A device was found on port", known_port,
                      "but the port is not reported as used by Acroname!")
        #
        if len(unknown_ports) == 1:
            device = devices_with_unknown_ports[0]
            log.d('... port', unknown_ports[0], 'has', device.handle)
            device._port = unknown_ports[0]
            return
        #
        acroname.disable_ports(ports)
        wait_until_all_ports_disabled()
        #
        # Enable one port at a time to try and find what device is connected to it
        n_identified_ports = 0
        for port in unknown_ports:
            #
            log.d('enabling port', port)
            acroname.enable_ports([port], disable_other_ports=True)
            sn = None
            for retry in range(5):
                if len(enabled()) == 1:
                    sn = list(enabled())[0]
                    break
                time.sleep(1)
            if not sn:
                log.d('could not recognize device in port', port)
            else:
                device = _device_by_sn.get(sn)
                if device:
                    log.d('... port', port, 'has', device.handle)
                    device._port = port
                    n_identified_ports += 1
                    if len(devices_with_unknown_ports) == n_identified_ports:
                        #log.d( 'no more devices; stopping' )
                        break
                else:
                    log.w("Device with serial number", sn, "was found in port",
                          port, "but was not in context")
            acroname.disable_ports([port])
            wait_until_all_ports_disabled()
    finally:
        log.debug_unindent()
コード例 #8
0
    "Visual Preset": 1
}
"""

test.start("Trying to load settings with default preset from json")
try:
    sd.load_json(low_ambient_data_with_default_preset)
    visual_preset_number = depth_sensor.get_option(rs.option.visual_preset)
    visual_preset_name = rs.l500_visual_preset(int(visual_preset_number))

    # if this check fails it is most likely because FW changed the default settings
    equal = test.check_equal(visual_preset_name,
                             rs.l500_visual_preset.low_ambient_light)
    if not equal:
        log.w(
            "It is possible that FW changed the default settings of the camera."
        )
        log_settings_differences(low_ambient_data_with_default_preset)
except:
    test.unexpected_exception()
test.finish()

#############################################################################################
# There is no default preset: so when one is specified, the code should calculate the preset!
# Here, we intentionally should not fit into any of the defined presets, and check that the result is CUSTOM

wrong_data_with_default_preset = """
{
    "Alternate IR": 0.0,
    "Apd Temperature": -9999,
    "Confidence Threshold": 1,
コード例 #9
0
 #
 log.d( 'found', test.name, '...' )
 try:
     log.debug_indent()
     test.debug_dump()
     #
     if tag and tag not in test.config.tags:
         log.d( 'does not fit --tag:', test.tags )
         continue
     #
     if not test.is_live():
         test_wrapper( test )
         continue
     #
     if skip_live_tests:
         log.w( test.name + ':', 'is live and there are no cameras; skipping' )
         continue
     #
     for configuration, serial_numbers in devices_by_test_config( test ):
         try:
             log.d( 'configuration:', configuration )
             log.debug_indent()
             devices.enable_only( serial_numbers, recycle = True )
         except RuntimeError as e:
             log.w( log.red + test.name + log.reset + ': ' + str(e) )
         else:
             test_wrapper( test, configuration )
         finally:
             log.debug_unindent()
     #
 finally:
コード例 #10
0
ファイル: acroname.py プロジェクト: ylemzang/librealsense
    try:
        opts, args = getopt.getopt(sys.argv[1:],
                                   '',
                                   longopts=['help', 'recycle'])
    except getopt.GetoptError as err:
        print('-F-', err)  # something like "option -a not recognized"
        usage()
    if args or not opts:
        usage()
    # See the end of the file for all the option handling

try:
    import brainstem
except ModuleNotFoundError:
    log.w('No acroname library is available!')
    raise

hub = None


class NoneFoundError(RuntimeError):
    """
    """
    def __init__(self, message=None):
        super().__init__(self, message or 'no Acroname module found')


def discover():
    """
    Return all Acroname module specs in a list. Raise NoneFoundError if one is not found!
コード例 #11
0
#     [Depth/0 #2 @33.333333]
#     [Color/1 #2 @33.333333]
#     [Depth/0 #3 @50.000000]    <--- the frame that was "lost"
#
from rspy import repo
rs_convert = repo.find_built_exe( 'tools/convert', 'rs-convert' )
if rs_convert:
    import subprocess
    subprocess.run( [rs_convert, '-i', filename, '-T'],
                    stdout=None,
                    stderr=subprocess.STDOUT,
                    universal_newlines=True,
                    timeout=10,
                    check=False )  # don't fail on errors
else:
    log.w( 'no rs-convert was found!' )
    log.d( 'sys.path=\n' + '\n    '.join( sys.path ) )

test.finish()
#
#############################################################################################
#
test.start( "Play it back, with syncer -- lose last frame" )

sw.playback( filename )
sw.start()

sw.expect( depth_frame = 0 )                          # syncer doesn't know about color yet
sw.expect( color_frame = 0 )                          # less than next expected of D
sw.expect( depth_frame = 1, color_frame = 1 )
sw.expect( depth_frame = 2, color_frame = 2 )