def test_existing_manager_already_exists(self): # Attempt to create a shared buffer manager that already exists with assert_raises(SharedBufferManagerException) as cm: clobbered_shared_buffer = SharedBufferManager(shared_mem_name, 100, 100, True, boost_mmap_mode=boost_mmap_mode) ex = cm.exception assert_regexp_matches(ex.msg, "Shared memory with the specified name already exists")
def test_existing_manager_absent(self): # Attempt to map a shared buffer manager that doesn't already exist absent_manager_name = "AbsentBufferManager" with assert_raises(SharedBufferManagerException) as cm: existing_shared_buffer = SharedBufferManager(absent_manager_name, boost_mmap_mode=boost_mmap_mode) ex = cm.exception assert_regexp_matches(ex.msg, "No shared memory exists with the specified name")
def test_existing_manager(self): # Map the existing manager existing_shared_buffer = SharedBufferManager(shared_mem_name, boost_mmap_mode=boost_mmap_mode) # Test that the configuration matches the original assert_equal(self.shared_buffer_manager.get_manager_id(), existing_shared_buffer.get_manager_id()) assert_equal(self.shared_buffer_manager.get_num_buffers(), existing_shared_buffer.get_num_buffers()) assert_equal(self.shared_buffer_manager.get_buffer_size(), existing_shared_buffer.get_buffer_size())
def setup_buffer(self, filename, buffer_size, frames): self._filename = filename self._frames = frames # Create the shared buffer self._shared_buffer_manager = SharedBufferManager(self._buffer, buffer_size*num_buffers, buffer_size, remove_when_deleted=True, boost_mmap_mode=boost_mmap_mode) # Now load in the file with open(self._filepath + "/" + self._filename, mode='rb') as file: fileContent = file.read() print("Writing file content to ", shared_mem_name) self._shared_buffer_manager.write_buffer(0, fileContent)
def __init__(self): # Initialise the logging module with log messages directed to stdout #logging.basicConfig(format='%(asctime)s %(levelname)s FrameProcessor - %(message)s', level=logging.DEBUG) #ch = logging.StreamHandler(sys.stdout) #logging.addHandler(ch) # create logger self.logger = logging.getLogger('frame_processor') self.logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) # create formatter formatter = logging.Formatter('%(asctime)s %(levelname)s %(name)s - %(message)s') # add formatter to ch ch.setFormatter(formatter) # add ch to logger self.logger.addHandler(ch) # Instantiate a configuration container object, which will be populated # with sensible default values self.config = FrameProcessorConfig("FrameProcessor", "FrameProcessor - test harness to simulate operation of FrameProcessor application") # Create the appropriate IPC channels self.ctrl_channel = IpcChannel(IpcChannel.CHANNEL_TYPE_REQ) self.ready_channel = IpcChannel(IpcChannel.CHANNEL_TYPE_SUB) self.release_channel = IpcChannel(IpcChannel.CHANNEL_TYPE_PUB) # Map the shared buffer manager try: self.shared_buffer_manager = SharedBufferManager(self.config.sharedbuf, boost_mmap_mode=self.config.boost_mmap_mode) except SharedBufferManagerException as e: self.logger.error("Failed to create shared buffer manager: %s" % str(e)) self.frame_decoder = PercivalEmulatorFrameDecoder(self.shared_buffer_manager) # Zero frames recevied counter self.frames_received = 0 # Create the thread to handle frame processing self.frame_processor = threading.Thread(target=self.process_frames) self.frame_processor.daemon = True self._run = True
def setup_class(cls): # Create a shared buffer manager for use in all tests cls.shared_buffer_manager = SharedBufferManager( shared_mem_name, shared_mem_size, buffer_size, remove_when_deleted=True, boost_mmap_mode=boost_mmap_mode)