Ejemplo n.º 1
0
    def test_overwrite(self):
        n_slots = 10
        n_head_slot_bytes = 64
        n_raw_data_slot_bytes = 4096
        n_assembled_data_slot_bytes = 5000

        create_rb_files(n_slots, n_head_slot_bytes, n_raw_data_slot_bytes,
                        n_assembled_data_slot_bytes)

        self.assertEqual(os.path.getsize(config.RB_IMAGE_HEAD_FILE),
                         n_slots * n_head_slot_bytes)
        self.assertEqual(os.path.getsize(config.RB_RAW_IMAGE_DATA_FILE),
                         n_slots * n_raw_data_slot_bytes)
        self.assertEqual(os.path.getsize(config.RB_ASSEMBLED_IMAGE_DATA_FILE),
                         n_slots * n_assembled_data_slot_bytes)

        n_slots = 5
        create_rb_files(n_slots, n_head_slot_bytes, n_raw_data_slot_bytes,
                        n_assembled_data_slot_bytes)

        self.assertEqual(os.path.getsize(config.RB_IMAGE_HEAD_FILE),
                         n_slots * n_head_slot_bytes)
        self.assertEqual(os.path.getsize(config.RB_RAW_IMAGE_DATA_FILE),
                         n_slots * n_raw_data_slot_bytes)
        self.assertEqual(os.path.getsize(config.RB_ASSEMBLED_IMAGE_DATA_FILE),
                         n_slots * n_assembled_data_slot_bytes)
Ejemplo n.º 2
0
    def test_create_rb_files(self):
        self.assertFalse(os.path.isfile(config.RB_IMAGE_HEAD_FILE))
        self.assertFalse(os.path.isfile(config.RB_RAW_IMAGE_DATA_FILE))
        self.assertFalse(os.path.isfile(config.RB_ASSEMBLED_IMAGE_DATA_FILE))

        n_slots = 10
        n_head_slot_bytes = 64
        n_raw_data_slot_bytes = 4096
        n_assembled_data_slot_bytes = 5000

        create_rb_files(n_slots, n_head_slot_bytes, n_raw_data_slot_bytes,
                        n_assembled_data_slot_bytes)

        self.assertTrue(os.path.isfile(config.RB_IMAGE_HEAD_FILE))
        self.assertTrue(os.path.isfile(config.RB_RAW_IMAGE_DATA_FILE))
        self.assertTrue(os.path.isfile(config.RB_ASSEMBLED_IMAGE_DATA_FILE))

        head_file_size = os.path.getsize(config.RB_IMAGE_HEAD_FILE)
        self.assertEqual(head_file_size, n_slots * n_head_slot_bytes)

        raw_data_file_size = os.path.getsize(config.RB_RAW_IMAGE_DATA_FILE)
        self.assertEqual(raw_data_file_size, n_slots * n_raw_data_slot_bytes)

        assembled_data_file_size = os.path.getsize(
            config.RB_ASSEMBLED_IMAGE_DATA_FILE)
        self.assertEqual(assembled_data_file_size,
                         n_slots * n_assembled_data_slot_bytes)
Ejemplo n.º 3
0
    def test_exception(self):
        n_slots = -1
        n_head_slot_bytes = 64
        n_raw_data_slot_bytes = 4096
        n_assembled_data_slot_bytes = 4096

        with self.assertRaisesRegex(RuntimeError, "Could not create file"):
            create_rb_files(n_slots, n_head_slot_bytes, n_raw_data_slot_bytes,
                            n_assembled_data_slot_bytes)
def test_prefilled_buffer(n_buffer_slots, rb_folder,
                          detector: DetectorDefinition, n_slots_to_fill):

    create_rb_files(n_buffer_slots,
                    detector.image_header_n_bytes,
                    detector.image_data_n_bytes,
                    rb_folder=rb_folder)

    rb_master = MockRingBufferMaster(rb_folder=rb_folder)
    rb_master.create_buffer()

    rb_client_writer = MockRingBufferClient(process_id=0,
                                            follower_ids=[],
                                            detector_def=detector,
                                            as_reader=False,
                                            rb_folder=rb_folder)

    rb_client_reader = MockRingBufferClient(process_id=1,
                                            follower_ids=[0],
                                            detector_def=detector,
                                            as_reader=True,
                                            rb_folder=rb_folder)

    rb_client_writer.init_buffer()
    rb_client_reader.init_buffer()

    for i_slot in range(n_slots_to_fill):

        rb_current_slot = rb.claim_next_slot(rb_client_writer.rb_consumer_id)
        if rb_current_slot == -1:
            raise RuntimeError(
                "Cannot get next slot from ringbuffer. Are the RB files available?"
            )

        if not rb.commit_slot(rb_client_writer.rb_consumer_id,
                              rb_current_slot):
            raise RuntimeError("Cannot commit rb slot %d." % rb_current_slot)
 def setUpClass(cls):
     create_rb_files(100, 64, 2 * 512 * 256, 2 * 512 * 256)