Ejemplo n.º 1
0
    def test_leak(self):
        """Test map leak."""
        # There was a bug where we were leaking events in the event map.
        self.fd = os.open('test_lio_file', Test.FLAG)

        event_size = len(coro.event_map)

        filesize = 512 * 1024
        orig_data = os.urandom(filesize)
        coro.aio_write(self.fd, orig_data, 0)
        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize - size)
            data = coro.aio_read(self.fd, size, offset)
            self.assertEqual(data, orig_data[offset:offset + size])

        self.assertEqual(event_size, len(coro.event_map))

        # Try error path.
        os.close(self.fd)

        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize - size)
            self.assertRaises(OSError, coro.aio_read, self.fd, size, offset)

        self.assertEqual(event_size, len(coro.event_map))
Ejemplo n.º 2
0
    def test_leak(self):
        """Test map leak."""
        # There was a bug where we were leaking events in the event map.
        self.fd = os.open('test_lio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC)

        event_size = len(coro.event_map)

        filesize = 512 * 1024
        orig_data = os.urandom(filesize)
        coro.aio_write(self.fd, orig_data, 0)
        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize)
            data = coro.aio_read(self.fd, size, offset)
            self.assertEqual(data, orig_data[offset:offset + size])

        self.assertEqual(event_size, len(coro.event_map))

        # Try error path.
        os.close(self.fd)

        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize)
            self.assertRaises(OSError, coro.aio_read, self.fd, size, offset)

        self.assertEqual(event_size, len(coro.event_map))
Ejemplo n.º 3
0
    def _reader(self, reader_num):
        selfish_acts = 1
        self.reader_status[reader_num] = 'Starting.'
        try:
            while 1:
                if coro.get_now() > self._start_time + self.options.duration*coro.ticks_per_sec:
                    self.reader_status[reader_num] = 'Finished.'
                    return
                if not selfish_acts % self.options.greediness:
                    self.reader_status[reader_num] = 'Greediness sleep.'
                    coro.sleep_relative(0)
                if not self._have_blocks_to_read():
                    self.reader_status[reader_num] = 'Sleeping, waiting for writers to catch up.'
                    coro.sleep_relative(0.1)
                    continue
                pos, size, area = self._get_to_read()

                self.log(3, '%i: read(%i, %i)', reader_num, size, pos)
                try:
                    if random.random() < self.options.cancel_percent/100.0:
                        try:
                            self.reader_status[reader_num] = 'Reading with cancel.'
                            data = coro.with_timeout(0, coro.aio_read, self._fd, size, long(pos))
                        except coro.TimeoutError:
                            self._read_cancel_success += 1
                        else:
                            self._read_cancel_fail += 1
                    else:
                        self.reader_status[reader_num] = 'Reading.'
                        data = coro.aio_read(self._fd, size, long(pos))
                        expected_data = t_aio.make_data(pos, size)
                        if data != expected_data:
                            self._assertion_errors += 1
                            self.log(0, 'ERROR: data read=%i expected=%i pos=%i', len(data), size, pos)
                            fname = tempfile.mktemp()
                            f = open(fname, 'w')
                            f.write(data)
                            f.close()
                            self.log(0, 'Wrote temp file %s', fname)
                finally:
                    self._read_locks.delete(area)
                selfish_acts += 1
                self._reads_finished += 1
                self._bytes_read += size
        finally:
            self._worker_semaphore.release()
Ejemplo n.º 4
0
    def test_error(self):
        """Test error return."""
        fd = os.open('test_aio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC)
        data = os.urandom(1024 * 1024)
        r = coro.aio_write(fd, data, 0)
        self.assertEqual(r, len(data))
        self.assertEqual(coro.aio_read(fd, len(data), 0), data)

        # Rip away the file descriptor.
        os.close(fd)
        # Verify it fails.
        self.assertRaises(oserrors.EBADF, coro.aio_read, fd, len(data), 0)

        # Try a test that will fail from aio_return.
        # (NOTE: On FreeBSD before 7, this would actually show up as an
        # error immediately from aio_error, but in FreeBSD 7 it now appears to
        # go through the kqueue code path.)
        soft, hard = resource.getrlimit(resource.RLIMIT_FSIZE)
        fd = os.open('test_aio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC)
        self.assertRaises(oserrors.EFBIG, coro.aio_write, fd, data, soft)
        os.close(fd)
Ejemplo n.º 5
0
    def test_error(self):
        """Test error return."""
        fd = os.open('test_aio_file', os.O_RDWR|os.O_CREAT|os.O_TRUNC)
        data = os.urandom(1024 * 1024)
        r = coro.aio_write(fd, data, 0)
        self.assertEqual(r, len(data))
        self.assertEqual(coro.aio_read(fd, len(data), 0), data)

        # Rip away the file descriptor.
        os.close(fd)
        # Verify it fails.
        self.assertRaises(oserrors.EBADF, coro.aio_read, fd, len(data), 0)

        # Try a test that will fail from aio_return.
        # (NOTE: On FreeBSD before 7, this would actually show up as an
        # error immediately from aio_error, but in FreeBSD 7 it now appears to
        # go through the kqueue code path.)
        soft, hard = resource.getrlimit(resource.RLIMIT_FSIZE)
        fd = os.open('test_aio_file', os.O_RDWR|os.O_CREAT|os.O_TRUNC)
        self.assertRaises(oserrors.EFBIG, coro.aio_write, fd, data, soft)
        os.close(fd)
Ejemplo n.º 6
0
    def test_read_write(self):
        """Test read/write."""
        self.fd = os.open('test_lio_file', os.O_RDWR | os.O_CREAT | os.O_TRUNC)

        # Simple 1-byte test.
        self._read_write('a')

        # Try something really large.
        data = os.urandom(5 * 1024 * 1024)
        self._read_write(data)

        # Test offset read/write.
        filesize = 512 * 1024
        orig_data = os.urandom(filesize)
        coro.aio_write(self.fd, orig_data, 0)
        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize)
            data = coro.aio_read(self.fd, size, offset)
            self.assertEqual(data, orig_data[offset:offset + size])

        os.close(self.fd)
Ejemplo n.º 7
0
    def test_read_write(self):
        """Test read/write."""
        self.fd = os.open('test_lio_file', Test.FLAG)

        # Simple 1-byte test.
        self._read_write('a')

        # Try something really large.
        data = os.urandom(5 * 1024 * 1024)
        self._read_write(data)

        # Test offset read/write.
        orig_data = os.urandom(512 * 1024)
        filesize = len(orig_data)
        coro.aio_write(self.fd, orig_data, 0)
        for x in xrange(100):
            size = random.randint(1, filesize)
            offset = random.randint(0, filesize - size)
            data = coro.aio_read(self.fd, size, offset)
            self.assertEqual(data, orig_data[offset:offset + size])

        os.close(self.fd)
Ejemplo n.º 8
0
 def _read_write(self, data):
     n = coro.aio_write(self.fd, data, 0)
     self.assertEqual(n, len(data))
     a = coro.aio_read(self.fd, len(data), 0)
     self.assertEqual(a, data)
     os.ftruncate(self.fd, 0)
Ejemplo n.º 9
0
 def _read_write(self, data):
     n = coro.aio_write(self.fd, data, 0)
     self.assertEqual(n, len(data))
     a = coro.aio_read(self.fd, len(data), 0)
     self.assertEqual(a, data)
     os.ftruncate(self.fd, 0)
Ejemplo n.º 10
0
 def read (self, size):
     result = aio_read (self.fd, size, self.pos)
     self.pos += len (result)
     return result