def setup_iteration_comm(self, comm=None): r"""Perform setup associated with a comm iteration.""" assert (comm is not None) if not tools.is_comm_installed(comm): raise unittest.SkipTest("%s library not installed." % comm) self.set_default_comm(default_comm=comm) return comm
def deco(func): deco_list = [ timeout_dec(timeout=timeout), unittest.skipIf( (not tools.check_environ_bool('YGG_ENABLE_EXAMPLE_TESTS')), "Example tests not enabled."), ] for i, k in enumerate(iter_over): v = x[i] flag = None msg = None if k == 'comm': flag = tools.is_comm_installed(v) elif k == 'language': flag = True for vv in get_example_languages(name, language=v): if not tools.is_lang_installed(vv): flag = False break if flag is not None: if msg is None: msg = "%s %s not installed." % (k.title(), v) deco_list.append(unittest.skipIf(not flag, msg)) for v in deco_list: func = v(func) return func
def get_zmq_flags(for_cmake=False, for_api=False): r"""Get the necessary flags for compiling & linking with zmq libraries. Args: for_cmake (bool, optional): If True, the returned flags will match the format required by cmake. Defaults to False. for_api (bool, optional): If True, the returned flags will match those required for compiling the API static library. Defaults to False. Returns: tuple(list, list): compile and linker flags. """ _compile_flags = [] _linker_flags = [] # ZMQ library if tools.is_comm_installed('ZMQComm', language='c'): if platform._is_win: # pragma: windows for l in ["libzmq", "czmq"]: plib = ygg_cfg.get('windows', '%s_static' % l, False) pinc = ygg_cfg.get('windows', '%s_include' % l, False) if not (plib and pinc): # pragma: debug raise Exception("Could not locate %s .lib and .h files." % l) pinc_d = os.path.dirname(pinc) plib_d, plib_f = os.path.split(plib) _compile_flags.append("-I%s" % pinc_d) if for_cmake: _linker_flags.append(plib) else: _linker_flags += ['/LIBPATH:%s' % plib_d, plib_f] else: _linker_flags += ["-lczmq", "-lzmq"] _compile_flags += ["-DZMQINSTALLED"] return _compile_flags, _linker_flags
def get_ipc_flags(for_cmake=False, for_api=False): r"""Get the necessary flags for compiling & linking with ipc libraries. Args: for_cmake (bool, optional): If True, the returned flags will match the format required by cmake. Defaults to False. for_api (bool, optional): If True, the returned flags will match those required for compiling the API static library. Defaults to False. Returns: tuple(list, list): compile and linker flags. """ _compile_flags = [] _linker_flags = [] if tools.is_comm_installed('IPCComm', language='c'): _compile_flags += ["-DIPCINSTALLED"] return _compile_flags, _linker_flags
def run_iteration(self, language=None, datatype=None, comm=None): r"""Run a test for the specified parameters.""" if not tools.check_environ_bool('YGG_ENABLE_EXAMPLE_TESTS'): raise unittest.SkipTest("Example tests not enabled.") if comm and (not tools.is_comm_installed(comm)): raise unittest.SkipTest("%s library not installed." % comm) if language is not None: check_enabled_languages(language) self.language = language self.datatype = datatype if comm is None: self.comm = _default_comm else: self.comm = comm self.set_default_comm(default_comm=comm) try: self.run_example() finally: self.language = None self.datatype = None self.comm = None self.reset_default_comm()
def test_is_comm_installed(): r"""Test is_comm_installed for any.""" assert (tools.is_comm_installed('zmq', language='any'))
def description_prefix(self): r"""Prefix message with test name.""" out = super(ExampleTimedPipeTestBase, self).description_prefix out += '(%s)' % self._new_default_comm return out @property def results(self): r"""Result that should be found in output files.""" siz = int(self.env['PIPE_MSG_COUNT']) * int(self.env['PIPE_MSG_SIZE']) res = '0' * siz return [res] @property def output_files(self): r"""Output file.""" return [os.path.join(self.tempdir, 'output_timed_pipe.txt')] # Dynamically add test classes for comm types for c in tools.get_installed_comm(): if c == _default_comm: continue new_cls = unittest.skipIf(not tools.is_comm_installed(c), "%s library not installed." % c)(type( 'TestExampleTimedPipe%s' % c, (ExampleTimedPipeTestBase, ), {'__new_default_comm': c})) globals()[new_cls.__name__] = new_cls del new_cls
def test_get_ipc_flags(): r"""Test get_ipc_flags.""" cc, ld = get_ipc_flags() if not tools.is_comm_installed('IPCComm', language='c'): # pragma: windows assert_equal(len(cc), 0) assert_equal(len(ld), 0)
def test_get_zmq_flags(): r"""Test get_zmq_flags.""" cc, ld = get_zmq_flags() if not tools.is_comm_installed('ZMQComm', language='c'): assert_equal(len(cc), 0) assert_equal(len(ld), 0)
def get_flags(for_cmake=False, for_api=False, cpp=False): r"""Get the necessary flags for compiling & linking with Ygg libraries. Args: for_cmake (bool, optional): If True, the returned flags will match the format required by cmake. Defaults to False. for_api (bool, optional): If True, the returned flags will match those required for compiling the API static library. Defaults to False. cpp (bool, optional): If True, flags for compiling a C++ model are returned. Otherwise, flags for compiling a C model are returned. Defaults to False. Returns: tuple(list, list): compile and linker flags. """ if cpp: _compile_flags = os.environ.get('CXXFLAGS', '').split() else: _compile_flags = os.environ.get('CFLAGS', '').split() _linker_flags = os.environ.get('LDFLAGS', '').split() if not _c_installed: # pragma: windows logging.warning("No library installed for models written in C") return _compile_flags, _linker_flags if platform._is_win: # pragma: windows _compile_flags += ["/nologo", "-D_CRT_SECURE_NO_WARNINGS"] _compile_flags += ['-I' + _top_dir] _compile_flags += ['-I' + _incl_interface] if not for_cmake: _regex_win32 = os.path.split(_regex_win32_lib) _compile_flags += ['-I' + _regex_win32[0]] if tools.is_comm_installed('ZMQComm', language='c'): zmq_flags = get_zmq_flags(for_cmake=for_cmake, for_api=for_api) _compile_flags += zmq_flags[0] _linker_flags += zmq_flags[1] if tools.is_comm_installed('IPCComm', language='c'): ipc_flags = get_ipc_flags(for_cmake=for_cmake, for_api=for_api) _compile_flags += ipc_flags[0] _linker_flags += ipc_flags[1] # Include dir for x in [ _incl_interface, _incl_io, _incl_comm, _incl_seri, _incl_regex, _incl_dtype ]: _compile_flags += ["-I" + x] # Interface library if not for_api: if cpp: plib = _api_static_cpp else: plib = _api_static_c plib_d, plib_f = os.path.split(plib) if for_cmake: _linker_flags.append(plib) # _linker_flags += [_api_static_c, _api_static_cpp] elif platform._is_win: # pragma: windows _linker_flags += ['/LIBPATH:%s' % plib_d, plib_f] else: _linker_flags += ["-L" + plib_d] _linker_flags += [ "-l" + os.path.splitext(plib_f)[0].split(_prefix)[-1] ] if tools.get_default_comm() == 'IPCComm': _compile_flags += ["-DIPCDEF"] return _compile_flags, _linker_flags