Best Python code snippet using fMBT_python
c_lib.py
Source:c_lib.py
...3import os4import ctypes5import platform6import multiprocessing7def _load_lib():8 """ Load library in build/lib. """9 cur_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))10 lib_path = os.path.join(cur_path, "../../build/")11 if platform.system() == 'Darwin':12 path_to_so_file = os.path.join(lib_path, "libmagent.dylib")13 elif platform.system() == 'Linux':14 path_to_so_file = os.path.join(lib_path, "libmagent.so")15 else:16 raise BaseException("unsupported system: " + platform.system())17 lib = ctypes.CDLL(path_to_so_file, ctypes.RTLD_GLOBAL)18 return lib19def as_float_c_array(buf):20 """numpy to ctypes array"""21 return buf.ctypes.data_as(ctypes.POINTER(ctypes.c_float))22def as_int32_c_array(buf):23 """numpy to ctypes array"""24 return buf.ctypes.data_as(ctypes.POINTER(ctypes.c_int32))25def as_bool_c_array(buf):26 """numpy to ctypes array"""27 return buf.ctypes.data_as(ctypes.POINTER(ctypes.c_bool))28if 'OMP_NUM_THREADS' not in os.environ:29 os.environ['OMP_NUM_THREADS'] = str(multiprocessing.cpu_count() // 2)...
linux.py
Source:linux.py
...3class NotAvail:4 pass5class LibC:6 _libc = None7 def _load_lib(self):8 if self._libc:9 return10 self._libc = ctypes.cdll.LoadLibrary("libc.so.6")11 def syscall(self, id):12 self._load_lib()13 return self._libc.syscall(id)14class LibCap:15 _libcap = None16 pr_set_name = 1517 def _load_lib(self):18 if self._libcap:19 return20 try:21 self._libcap = ctypes.cdll.LoadLibrary("libcap.so.2")22 except OSError:23 self._libcap = NotAvail24 def tname(self, name):25 self._load_lib()26 if self._libcap is NotAvail:27 return28 self._libcap.prctl(self.pr_set_name, name.encode())29libc = LibC()30libcap = LibCap()31def get_tid():32 return libc.syscall(SYS_gettid)33def set_tname(name):...
vic.py
Source:vic.py
2 @section DESCRIPTION3 cffi wrapper for vic_run4"""5from ._vic import ffi6def _load_lib(lib):7 import os8 import sysconfig9 suffix = sysconfig.get_config_var('SO')10 path = os.path.join(os.path.dirname(__file__), os.pardir,11 '{0}{1}'.format(lib, suffix))12 return ffi.dlopen(path)13lib = _load_lib('vic_core')14# Initialize global structures15lib.initialize_log()16lib.initialize_global()17lib.initialize_options()18lib.initialize_parameters()19# TODO: wrappers for individual vic functions. For now, access to lib functions...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!