Commit 6390aec4 authored by Jason Madden's avatar Jason Madden

Debugging the test__core.py memory corruption bug seen on travis.

parent cbae4c9b
......@@ -11,16 +11,16 @@ env:
# These are ordered to get as much diversity in the
# first group of parallel runs (4) as posible
- TASK=test-py27-libuv
- TASK=test-py27-noembed
- TASK=test-pypy
- TASK=test-py36
#- TASK=test-py27-noembed
#- TASK=test-pypy
#- TASK=test-py36
- TASK=lint-py27
- TASK=test-pypy3
- TASK=test-py35
- TASK=test-py278
- TASK=test-py27
- TASK=test-py34
- TASK=test-py27-cffi
#- TASK=test-pypy3
#- TASK=test-py35
#- TASK=test-py278
#- TASK=test-py27
#- TASK=test-py34
#- TASK=test-py27-cffi
matrix:
fast_finish: true
......
"""
libuv loop implementation
"""
# pylint: disable=no-member
from __future__ import absolute_import, print_function
import os
......@@ -15,8 +15,8 @@ from gevent._ffi.loop import AbstractLoop
from gevent.libuv import _corecffi # pylint:disable=no-name-in-module,import-error
from gevent._ffi.loop import assign_standard_callbacks
ffi = _corecffi.ffi # pylint:disable=no-member
libuv = _corecffi.lib # pylint:disable=no-member
ffi = _corecffi.ffi
libuv = _corecffi.lib
__all__ = [
]
......
# pylint: disable=too-many-lines, protected-access, redefined-outer-name, not-callable
# pylint: disable=no-member
from __future__ import absolute_import, print_function
import functools
......@@ -6,8 +7,8 @@ import weakref
import gevent.libuv._corecffi as _corecffi # pylint:disable=no-name-in-module,import-error
ffi = _corecffi.ffi # pylint:disable=no-member
libuv = _corecffi.lib # pylint:disable=no-member
ffi = _corecffi.ffi
libuv = _corecffi.lib
from gevent._ffi import watcher as _base
......
......@@ -42,6 +42,7 @@ import _six as six
PYPY = hasattr(sys, 'pypy_version_info')
VERBOSE = sys.argv.count('-v') > 1
LIBUV = os.getenv('GEVENT_CORE_CFFI_ONLY') == 'libuv' # XXX: Formalize this better
if '--debug-greentest' in sys.argv:
sys.argv.remove('--debug-greentest')
......@@ -138,6 +139,11 @@ skipIf = unittest.skipIf
EXPECT_POOR_TIMER_RESOLUTION = PYPY3 or RUNNING_ON_APPVEYOR
if LIBUV:
skipOnLibuv = unittest.skip
else:
skipOnLibuv = _do_not_skip
class ExpectedException(Exception):
"""An exception whose traceback should be ignored"""
......
# pylint:disable=no-member
import sys
from greentest import TestCase, main
from gevent import core
import unittest
from greentest import main, skipOnLibuv
from gevent import core
class Test(TestCase):
switch_expected = False
__timeout__ = None
@unittest.skip("Debugging")
class TestCore(unittest.TestCase):
def test_get_version(self):
version = core.get_version()
assert isinstance(version, str), repr(version)
assert version, repr(version)
self.assertIsInstance(version, str)
self.assertTrue(version)
header_version = core.get_header_version()
assert isinstance(header_version, str), repr(header_version)
assert header_version, repr(header_version)
self.assertIsInstance(header_version, str)
self.assertTrue(header_version)
self.assertEqual(version, header_version)
@unittest.skipIf(hasattr(core, 'libuv'),
"flags are libev-only")
def test_flags_conversion(self):
if sys.platform != 'win32':
self.assertEqual(core.loop(2, default=False).backend_int, 2)
self.assertEqual(core.loop('select', default=False).backend, 'select')
self.assertEqual(core._flags_to_int(None), 0)
self.assertEqual(core._flags_to_int(['kqueue', 'SELECT']), core.BACKEND_KQUEUE | core.BACKEND_SELECT)
self.assertEqual(core._flags_to_list(core.BACKEND_PORT | core.BACKEND_POLL), ['port', 'poll'])
self.assertRaises(ValueError, core.loop, ['port', 'blabla'])
self.assertRaises(TypeError, core.loop, object())
def test_events_conversion(self):
self.assertEqual(core._events_to_str(core.READ | core.WRITE), 'READ|WRITE')
def test_EVENTS(self):
self.assertEqual(str(core.EVENTS), 'gevent.core.EVENTS')
self.assertEqual(repr(core.EVENTS), 'gevent.core.EVENTS')
class TestWatchers(unittest.TestCase):
def test_io(self):
if sys.platform == 'win32':
......@@ -43,10 +25,13 @@ class Test(TestCase):
else:
Error = ValueError
win32 = False
self.assertRaises(Error, core.loop().io, -1, 1)
with self.assertRaises(Error):
core.loop().io(-1, 1)
if hasattr(core, 'TIMER'):
# libev
self.assertRaises(ValueError, core.loop().io, 1, core.TIMER)
with self.assertRaises(ValueError):
core.loop().io(1, core.TIMER)
# Test we can set events and io before it's started
if not win32:
# We can't do this with arbitrary FDs on windows;
......@@ -61,12 +46,36 @@ class Test(TestCase):
else:
self.assertEqual(core._events_to_str(io.events), 'WRITE')
def test_timer(self):
self.assertRaises(ValueError, core.loop().timer, 1, -1)
def test_timer_constructor(self):
with self.assertRaises(ValueError):
core.loop().timer(1, -1)
def test_signal(self):
self.assertRaises(ValueError, core.loop().signal, 1000)
def test_signal_constructor(self):
with self.assertRaises(ValueError):
core.loop().signal(1000)
@skipOnLibuv("Tests for libev-only functions")
class TestLibev(unittest.TestCase):
def test_flags_conversion(self):
if sys.platform != 'win32':
self.assertEqual(core.loop(2, default=False).backend_int, 2)
self.assertEqual(core.loop('select', default=False).backend, 'select')
self.assertEqual(core._flags_to_int(None), 0)
self.assertEqual(core._flags_to_int(['kqueue', 'SELECT']), core.BACKEND_KQUEUE | core.BACKEND_SELECT)
self.assertEqual(core._flags_to_list(core.BACKEND_PORT | core.BACKEND_POLL), ['port', 'poll'])
self.assertRaises(ValueError, core.loop, ['port', 'blabla'])
self.assertRaises(TypeError, core.loop, object())
class TestEvents(unittest.TestCase):
def test_events_conversion(self):
self.assertEqual(core._events_to_str(core.READ | core.WRITE), 'READ|WRITE')
def test_EVENTS(self):
self.assertEqual(str(core.EVENTS), 'gevent.core.EVENTS')
self.assertEqual(repr(core.EVENTS), 'gevent.core.EVENTS')
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment