Irit Goihman has uploaded a new change for review. Change subject: infra tests: moved infra tests to tests directory ......................................................................
infra tests: moved infra tests to tests directory infra tests were located with infra source code and were moved to tests directory in order to keep persistency with the rest of the project. some changes were made in the tests so they can be run with run_test_local.sh. Change-Id: Ib85f904e790812fe629e19836591e8e50a0c4541 Signed-off-by: Irit Goihman <igoih...@redhat.com> --- M lib/vdsm/infra/eventfd/Makefile.am D lib/vdsm/infra/eventfd/tests.py M lib/vdsm/infra/filecontrol/Makefile.am D lib/vdsm/infra/filecontrol/tests.py M lib/vdsm/infra/sigutils/Makefile.am D lib/vdsm/infra/sigutils/tests.py M lib/vdsm/infra/zombiereaper/Makefile.am M tests/Makefile.am A tests/eventfd_test.py A tests/filecontrol_test.py A tests/sigutils_test.py R tests/tests_child.py R tests/zombiereaper_test.py 13 files changed, 242 insertions(+), 279 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/62/57562/1 diff --git a/lib/vdsm/infra/eventfd/Makefile.am b/lib/vdsm/infra/eventfd/Makefile.am index f5b2c87..c267144 100644 --- a/lib/vdsm/infra/eventfd/Makefile.am +++ b/lib/vdsm/infra/eventfd/Makefile.am @@ -25,13 +25,3 @@ dist_eventfd_PYTHON = \ __init__.py \ $(NULL) - -dist_noinst_PYTHON = \ - tests.py \ - $(NULL) - -check-local: - if [ -x "$(PYTHON3_NOSE)" ]; then \ - "$(PYTHON3_NOSE)" tests.py; \ - fi - nosetests tests.py diff --git a/lib/vdsm/infra/eventfd/tests.py b/lib/vdsm/infra/eventfd/tests.py deleted file mode 100644 index e126026..0000000 --- a/lib/vdsm/infra/eventfd/tests.py +++ /dev/null @@ -1,75 +0,0 @@ -# -# Copyright 2015 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# Refer to the README and COPYING files for full details of the license -# -from __future__ import absolute_import -import fcntl -from .. import eventfd -from nose import tools - - -def test_create(): - efd = eventfd.EventFD() - tools.assert_not_equals(efd, None) - - -def test_close(): - efd = eventfd.EventFD() - efd.close() - tools.assert_equals(efd.fileno(), -1) - - -def test_read(): - value = 10 - efd = eventfd.EventFD(value) - tools.assert_equals(efd.read(), value) - - -def test_write(): - value = 10 - efd = eventfd.EventFD() - efd.write(value) - tools.assert_equals(efd.read(), value) - - -def test_write_with_coe_flag(): - value = 10 - efd = _set_flag(eventfd.EFD_CLOEXEC) - efd.write(value) - tools.assert_equals(efd.read(), value) - - -def test_write_with_nbio_flag(): - value = 10 - efd = _set_flag(eventfd.EFD_NONBLOCK) - efd.write(value) - tools.assert_equals(efd.read(), value) - - -def test_write_with_sem_flag(): - value = 10 - efd = _set_flag(eventfd.EFD_SEMAPHORE) - efd.write(value) - tools.assert_equals(efd.read(), 1) - - -def _set_flag(flag): - efd = eventfd.EventFD(flags=flag) - tools.assert_equals(0, eventfd.EFD_CLOEXEC & fcntl.fcntl(efd, - fcntl.F_GETFD)) - return efd diff --git a/lib/vdsm/infra/filecontrol/Makefile.am b/lib/vdsm/infra/filecontrol/Makefile.am index 0c7628d..2b6c952 100644 --- a/lib/vdsm/infra/filecontrol/Makefile.am +++ b/lib/vdsm/infra/filecontrol/Makefile.am @@ -25,13 +25,3 @@ dist_filecontrol_PYTHON = \ __init__.py \ $(NULL) - -dist_noinst_PYTHON = \ - tests.py \ - $(NULL) - -check-local: - if [ -x "$(PYTHON3_NOSE)" ]; then \ - "$(PYTHON3_NOSE)" tests.py; \ - fi - nosetests tests.py diff --git a/lib/vdsm/infra/filecontrol/tests.py b/lib/vdsm/infra/filecontrol/tests.py deleted file mode 100644 index 3025983..0000000 --- a/lib/vdsm/infra/filecontrol/tests.py +++ /dev/null @@ -1,44 +0,0 @@ -from __future__ import absolute_import -import fcntl -import functools -import os - -import nose.tools as nt - -from .. import filecontrol - - -def with_fd(func): - @functools.wraps(func) - def wrapper(*args, **kwargs): - r, w = os.pipe() - try: - return func(r, *args, **kwargs) - finally: - os.close(r) - os.close(w) - return wrapper - - -@with_fd -def test_non_blocking(fd): - nt.assert_equals(0, filecontrol.set_non_blocking(fd)) - nt.assert_true(os.O_NONBLOCK & fcntl.fcntl(fd, fcntl.F_GETFL)) - - -@with_fd -def test_blocking(fd): - nt.assert_equals(0, filecontrol.set_non_blocking(fd, False)) - nt.assert_false(os.O_NONBLOCK & fcntl.fcntl(fd, fcntl.F_GETFL)) - - -@with_fd -def test_close_on_exec(fd): - nt.assert_equals(0, filecontrol.set_close_on_exec(fd)) - nt.assert_true(fcntl.FD_CLOEXEC & fcntl.fcntl(fd, fcntl.F_GETFD)) - - -@with_fd -def test_no_close_on_exec(fd): - nt.assert_equals(0, filecontrol.set_close_on_exec(fd, False)) - nt.assert_false(fcntl.FD_CLOEXEC & fcntl.fcntl(fd, fcntl.F_GETFD)) diff --git a/lib/vdsm/infra/sigutils/Makefile.am b/lib/vdsm/infra/sigutils/Makefile.am index 1d2f9e8..be51de3 100644 --- a/lib/vdsm/infra/sigutils/Makefile.am +++ b/lib/vdsm/infra/sigutils/Makefile.am @@ -25,14 +25,3 @@ dist_sigutils_PYTHON = \ __init__.py \ $(NULL) - -dist_noinst_PYTHON = \ - tests.py \ - tests_child.py \ - $(NULL) - -check-local: - if [ -x "$(PYTHON3_NOSE)" ]; then \ - "$(PYTHON3_NOSE)" tests.py; \ - fi - nosetests tests.py diff --git a/lib/vdsm/infra/sigutils/tests.py b/lib/vdsm/infra/sigutils/tests.py deleted file mode 100644 index 6225b89..0000000 --- a/lib/vdsm/infra/sigutils/tests.py +++ /dev/null @@ -1,114 +0,0 @@ -# -# Copyright 2014 Red Hat, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# -# Refer to the README and COPYING files for full details of the license -# - -from __future__ import absolute_import -import contextlib -import errno -import os -import signal -import subprocess -import time - -from nose import tools - -CHILD_SCRIPT = 'tests_child.py' - - -def assert_read(stream, expected): - while True: - try: - tools.assert_equals(stream.read(len(expected)), expected) - except IOError as e: - if e.errno != errno.EINTR: - raise - else: - break - - -@contextlib.contextmanager -def child_test(*args): - proc = subprocess.Popen( - [os.path.abspath(CHILD_SCRIPT)] + list(args), - stdout=subprocess.PIPE, - cwd=os.path.dirname(__file__) - ) - try: - yield proc - finally: - proc.wait() - - -def test_signal_received(): - with child_test('check_signal_received') as child: - assert_read(child.stdout, b'ready\n') - child.send_signal(signal.SIGUSR1) - assert_read(child.stdout, b'signal sigusr1\n') - assert_read(child.stdout, b'done\n') - - -def test_signal_timeout(): - TIMEOUT = 0.2 - with child_test('check_signal_timeout', str(TIMEOUT)) as child: - now = time.time() - assert_read(child.stdout, b'ready\n') - assert_read(child.stdout, b'done\n') - later = time.time() - - # 3 is a safety factor - tools.assert_true(TIMEOUT < (later - now) < TIMEOUT * 3) - - -def test_signal_3_times(): - ''' - A sanity test to make sure wait_for_signal fires more than once. - ''' - with child_test('check_signal_times') as child: - assert_read(child.stdout, b'ready\n') - child.send_signal(signal.SIGUSR1) - assert_read(child.stdout, b'signal sigusr1\n') - assert_read(child.stdout, b'woke up\n') - child.send_signal(signal.SIGUSR1) - assert_read(child.stdout, b'signal sigusr1\n') - assert_read(child.stdout, b'woke up\n') - child.send_signal(signal.SIGUSR1) - assert_read(child.stdout, b'signal sigusr1\n') - assert_read(child.stdout, b'woke up\n') - assert_read(child.stdout, b'done\n') - - -def test_signal_to_thread(): - with child_test('check_child_signal_to_thread') as child: - assert_read(child.stdout, b'ready\n') - assert_read(child.stdout, b'signal sigchld\n') - assert_read(child.stdout, b'done\n') - - -def test_uninitialized(): - with child_test('check_uninitialized') as child: - assert_read(child.stdout, b'ready\n') - assert_read(child.stdout, b'exception\n') - assert_read(child.stdout, b'done\n') - - -def test_register_twice(): - with child_test('check_register_twice') as child: - assert_read(child.stdout, b'ready\n') - assert_read(child.stdout, b'exception\n') - assert_read(child.stdout, b'done\n') diff --git a/lib/vdsm/infra/zombiereaper/Makefile.am b/lib/vdsm/infra/zombiereaper/Makefile.am index 1671da9..5d2cdbe 100644 --- a/lib/vdsm/infra/zombiereaper/Makefile.am +++ b/lib/vdsm/infra/zombiereaper/Makefile.am @@ -25,13 +25,3 @@ dist_zombiereaper_PYTHON = \ __init__.py \ $(NULL) - -dist_noinst_PYTHON = \ - tests.py \ - $(NULL) - -check-local: - if [ -x "$(PYTHON3_NOSE)" ]; then \ - "$(PYTHON3_NOSE)" tests.py; \ - fi - nosetests tests.py diff --git a/tests/Makefile.am b/tests/Makefile.am index c4d1ca5..c82adf7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -58,6 +58,8 @@ encodingTests.py \ exception_test.py \ executorTests.py \ + eventfd_test.py \ + filecontrol_test.py \ fileSDTests.py \ fileVolumeTests.py \ fileUtilTests.py \ @@ -100,6 +102,7 @@ schemaValidationTest.py \ sdm_indirection_tests.py \ securableTests.py \ + sigutils_test.py \ sparsifyTests.py \ sslTests.py \ stompAdapterTests.py \ @@ -141,6 +144,7 @@ vmUtilsTests.py \ vmXmlTests.py \ v2vTests.py \ + zombiereaper_test.py \ $(NULL) blacklist_modules_python3 = \ diff --git a/tests/eventfd_test.py b/tests/eventfd_test.py new file mode 100644 index 0000000..688ec56 --- /dev/null +++ b/tests/eventfd_test.py @@ -0,0 +1,70 @@ +# +# Copyright 2015 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# +from __future__ import absolute_import +import fcntl +from vdsm.infra import eventfd +from nose import tools +from testlib import VdsmTestCase + + +class TestEventFD(VdsmTestCase): + def test_create(self): + efd = eventfd.EventFD() + tools.assert_not_equals(efd, None) + + def test_close(self): + efd = eventfd.EventFD() + efd.close() + tools.assert_equals(efd.fileno(), -1) + + def test_read(self): + value = 10 + efd = eventfd.EventFD(value) + tools.assert_equals(efd.read(), value) + + def test_write(self): + value = 10 + efd = eventfd.EventFD() + efd.write(value) + tools.assert_equals(efd.read(), value) + + def test_write_with_coe_flag(self): + value = 10 + efd = self._set_flag(eventfd.EFD_CLOEXEC) + efd.write(value) + tools.assert_equals(efd.read(), value) + + def test_write_with_nbio_flag(self): + value = 10 + efd = self._set_flag(eventfd.EFD_NONBLOCK) + efd.write(value) + tools.assert_equals(efd.read(), value) + + def test_write_with_sem_flag(self): + value = 10 + efd = self._set_flag(eventfd.EFD_SEMAPHORE) + efd.write(value) + tools.assert_equals(efd.read(), 1) + + def _set_flag(self, flag): + efd = eventfd.EventFD(flags=flag) + tools.assert_equals(0, eventfd.EFD_CLOEXEC & fcntl.fcntl( + efd, fcntl.F_GETFD)) + return efd diff --git a/tests/filecontrol_test.py b/tests/filecontrol_test.py new file mode 100644 index 0000000..3eff815 --- /dev/null +++ b/tests/filecontrol_test.py @@ -0,0 +1,41 @@ +from __future__ import absolute_import +import fcntl +import functools +import os + +import nose.tools as nt +from testlib import VdsmTestCase +from vdsm.infra import filecontrol + + +class TestFileControl(VdsmTestCase): + def with_fd(func): + @functools.wraps(func) + def wrapper(self, *args, **kwargs): + r, w = os.pipe() + try: + return func(self, r, *args, **kwargs) + finally: + os.close(r) + os.close(w) + return wrapper + + @with_fd + def test_non_blocking(self, fd): + nt.assert_equals(0, filecontrol.set_non_blocking(fd)) + nt.assert_true(os.O_NONBLOCK & fcntl.fcntl(fd, fcntl.F_GETFL)) + + @with_fd + def test_blocking(self, fd): + nt.assert_equals(0, filecontrol.set_non_blocking(fd, False)) + nt.assert_false(os.O_NONBLOCK & fcntl.fcntl(fd, fcntl.F_GETFL)) + + @with_fd + def test_close_on_exec(self, fd): + nt.assert_equals(0, filecontrol.set_close_on_exec(fd)) + nt.assert_true(fcntl.FD_CLOEXEC & fcntl.fcntl(fd, fcntl.F_GETFD)) + + @with_fd + def test_no_close_on_exec(self, fd): + nt.assert_equals(0, filecontrol.set_close_on_exec(fd, False)) + nt.assert_false(fcntl.FD_CLOEXEC & fcntl.fcntl(fd, fcntl.F_GETFD)) diff --git a/tests/sigutils_test.py b/tests/sigutils_test.py new file mode 100644 index 0000000..8584fee --- /dev/null +++ b/tests/sigutils_test.py @@ -0,0 +1,109 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from __future__ import absolute_import +import contextlib +import errno +import os +import signal +import subprocess +import time + +from nose import tools +from testlib import VdsmTestCase + +CHILD_SCRIPT = 'tests_child.py' + + +class TestSigutils(VdsmTestCase): + def assert_read(self, stream, expected): + while True: + try: + tools.assert_equals(stream.read(len(expected)), expected) + except IOError as e: + if e.errno != errno.EINTR: + raise + else: + break + + @contextlib.contextmanager + def child_test(self, *args): + proc = subprocess.Popen( + [os.path.abspath(CHILD_SCRIPT)] + list(args), + stdout=subprocess.PIPE, + cwd=os.path.dirname(__file__) + ) + try: + yield proc + finally: + proc.wait() + + def test_signal_received(self): + with self.child_test('check_signal_received') as child: + self.assert_read(child.stdout, b'ready\n') + child.send_signal(signal.SIGUSR1) + self.assert_read(child.stdout, b'signal sigusr1\n') + self.assert_read(child.stdout, b'done\n') + + def test_signal_timeout(self): + TIMEOUT = 0.2 + with self.child_test('check_signal_timeout', str(TIMEOUT)) as child: + now = time.time() + self.assert_read(child.stdout, b'ready\n') + self.assert_read(child.stdout, b'done\n') + later = time.time() + + # 3 is a safety factor + tools.assert_true(TIMEOUT < (later - now) < TIMEOUT * 3) + + def test_signal_3_times(self): + ''' + A sanity test to make sure wait_for_signal fires more than once. + ''' + with self.child_test('check_signal_times') as child: + self.assert_read(child.stdout, b'ready\n') + child.send_signal(signal.SIGUSR1) + self.assert_read(child.stdout, b'signal sigusr1\n') + self.assert_read(child.stdout, b'woke up\n') + child.send_signal(signal.SIGUSR1) + self.assert_read(child.stdout, b'signal sigusr1\n') + self.assert_read(child.stdout, b'woke up\n') + child.send_signal(signal.SIGUSR1) + self.assert_read(child.stdout, b'signal sigusr1\n') + self.assert_read(child.stdout, b'woke up\n') + self.assert_read(child.stdout, b'done\n') + + def test_signal_to_thread(self): + with self.child_test('check_child_signal_to_thread') as child: + self.assert_read(child.stdout, b'ready\n') + self.assert_read(child.stdout, b'signal sigchld\n') + self.assert_read(child.stdout, b'done\n') + + def test_uninitialized(self): + with self.child_test('check_uninitialized') as child: + self.assert_read(child.stdout, b'ready\n') + self.assert_read(child.stdout, b'exception\n') + self.assert_read(child.stdout, b'done\n') + + def test_register_twice(self): + with self.child_test('check_register_twice') as child: + self.assert_read(child.stdout, b'ready\n') + self.assert_read(child.stdout, b'exception\n') + self.assert_read(child.stdout, b'done\n') diff --git a/lib/vdsm/infra/sigutils/tests_child.py b/tests/tests_child.py similarity index 100% rename from lib/vdsm/infra/sigutils/tests_child.py rename to tests/tests_child.py diff --git a/lib/vdsm/infra/zombiereaper/tests.py b/tests/zombiereaper_test.py similarity index 75% rename from lib/vdsm/infra/zombiereaper/tests.py rename to tests/zombiereaper_test.py index fb25cc5..df8e00a 100644 --- a/lib/vdsm/infra/zombiereaper/tests.py +++ b/tests/zombiereaper_test.py @@ -21,13 +21,13 @@ from time import sleep import os -from .. import zombiereaper +from testlib import VdsmTestCase + +from vdsm.infra import zombiereaper from subprocess import Popen -from unittest import TestCase - -class zombieReaperTests(TestCase): +class zombieReaperTests(VdsmTestCase): def setUp(self): zombiereaper.registerSignalHandler() @@ -55,6 +55,19 @@ self.assertRaises(OSError, os.waitpid, p.pid, os.WNOHANG) -class RegisterTests(TestCase): +class RegisterTests(VdsmTestCase): + + # testrunner calls zombiereaper.registerSignalHandler so for testing + # purposes unregisterSignalHandler is called. + def setUp(self): + self.unregistered = True + if zombiereaper._registered: + self.unregistered = True + zombiereaper.unregisterSignalHandler() + + def tearDown(self): + if self.unregistered: + zombiereaper.registerSignalHandler() + def testUnregistered(self): self.assertRaises(RuntimeError, zombiereaper.autoReapPID, 12345) -- To view, visit https://gerrit.ovirt.org/57562 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib85f904e790812fe629e19836591e8e50a0c4541 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Irit Goihman <igoih...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches