From 634572caf7f65f2e0c749c52f7cdec2e5303a704 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 24 Jan 2020 21:56:15 +0100 Subject: [PATCH] Add CI testing for FreeBSD (#1671) --- .cirrus.yml | 16 ++++++++++++++++ HISTORY.rst | 1 + MANIFEST.in | 2 -- README.rst | 6 +++++- docs/DEVGUIDE.rst | 4 ++++ psutil/_psbsd.py | 2 ++ psutil/tests/__init__.py | 9 +++++---- psutil/tests/test_connections.py | 16 ++++++++-------- psutil/tests/test_contracts.py | 9 ++------- psutil/tests/test_misc.py | 9 +++++---- psutil/tests/test_posix.py | 8 ++++---- psutil/tests/test_process.py | 2 +- psutil/tests/test_system.py | 18 +++++++++++------- psutil/tests/test_unicode.py | 11 ++++------- 14 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 .cirrus.yml diff --git a/.cirrus.yml b/.cirrus.yml new file mode 100644 index 000000000..d86f7e4c3 --- /dev/null +++ b/.cirrus.yml @@ -0,0 +1,16 @@ +freebsd_12_1_task: + freebsd_instance: + image: freebsd-12-1-release-amd64 + env: + CIRRUS: 1 + install_script: + - pkg install -y python3 gcc py37-pip + script: + - python3 -m pip install --user setuptools flake8 ipaddress mock + - make clean + - make build + - make install + - make test + - make test-memleaks + - PSUTIL_TESTING=1 python3 -Wa scripts/internal/print_access_denied.py + - PSUTIL_TESTING=1 python3 -Wa scripts/internal/print_api_speed.py diff --git a/HISTORY.rst b/HISTORY.rst index 28a5ce134..754c15a0b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -13,6 +13,7 @@ XXXX-XX-XX - 1652_: [Windows] dropped support for Windows XP and Windows Server 2003. Minimum supported Windows version now is Windows Vista. - 1667_: added process_iter(new_only=True) parameter. +- 1671_: [FreeBSD] add CI testing/service for FreeBSD (Cirrus CI). **Bug fixes** diff --git a/MANIFEST.in b/MANIFEST.in index 75ad5f15d..038d4baab 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -68,8 +68,6 @@ include psutil/arch/windows/cpu.c include psutil/arch/windows/cpu.h include psutil/arch/windows/disk.c include psutil/arch/windows/disk.h -include psutil/arch/windows/globals.c -include psutil/arch/windows/globals.h include psutil/arch/windows/net.c include psutil/arch/windows/net.h include psutil/arch/windows/ntextapi.h diff --git a/README.rst b/README.rst index ce859bd97..b38e736ac 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,6 @@ | |downloads| |stars| |forks| |contributors| |coverage| |quality| | |version| |py-versions| |packages| |license| -| |travis| |appveyor| |doc| |twitter| |tidelift| +| |travis| |appveyor| |cirrus| |doc| |twitter| |tidelift| .. |downloads| image:: https://img.shields.io/pypi/dm/psutil.svg :target: https://pepy.tech/project/psutil @@ -30,6 +30,10 @@ :target: https://ci.appveyor.com/project/giampaolo/psutil :alt: Windows tests (Appveyor) +.. |cirrus| image:: https://img.shields.io/cirrus/github/giampaolo/psutil?label=FreeBSD + :target: https://cirrus-ci.com/github/giampaolo/psutil-cirrus-ci + :alt: FreeBSD tests (Cirrus-Ci) + .. |coverage| image:: https://img.shields.io/coveralls/github/giampaolo/psutil.svg?label=test%20coverage :target: https://coveralls.io/github/giampaolo/psutil?branch=master :alt: Test coverage (coverall.io) diff --git a/docs/DEVGUIDE.rst b/docs/DEVGUIDE.rst index d9eb6d7ab..5ef1c4e42 100644 --- a/docs/DEVGUIDE.rst +++ b/docs/DEVGUIDE.rst @@ -149,6 +149,10 @@ Two icons in the home page (README) always show the build status: :target: https://ci.appveyor.com/project/giampaolo/psutil :alt: Windows tests (Appveyor) +.. image:: https://img.shields.io/cirrus/github/giampaolo/psutil?label=FreeBSD + :target: https://cirrus-ci.com/github/giampaolo/psutil-cirrus-ci + :alt: FreeBSD tests (Cirrus-CI) + BSD, AIX and Solaris are currently tested manually. Test coverage diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index 78e436f7e..11a2e59c1 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -622,6 +622,8 @@ def name(self): @wrap_exceptions def exe(self): if FREEBSD: + if self.pid == 0: + return '' # else NSP return cext.proc_exe(self.pid) elif NETBSD: if self.pid == 0: diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 2844360d7..0c297b9b0 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -71,7 +71,8 @@ # constants 'APPVEYOR', 'DEVNULL', 'GLOBAL_TIMEOUT', 'MEMORY_TOLERANCE', 'NO_RETRIES', 'PYPY', 'PYTHON_EXE', 'ROOT_DIR', 'SCRIPTS_DIR', 'TESTFILE_PREFIX', - 'TESTFN', 'TESTFN_UNICODE', 'TOX', 'TRAVIS', 'VALID_PROC_STATUSES', + 'TESTFN', 'TESTFN_UNICODE', 'TOX', 'TRAVIS', 'CIRRUS', 'CI_TESTING', + 'VALID_PROC_STATUSES', "HAS_CPU_AFFINITY", "HAS_CPU_FREQ", "HAS_ENVIRON", "HAS_PROC_IO_COUNTERS", "HAS_IONICE", "HAS_MEMORY_MAPS", "HAS_PROC_CPU_NUM", "HAS_RLIMIT", "HAS_SENSORS_BATTERY", "HAS_BATTERY", "HAS_SENSORS_FANS", @@ -113,11 +114,11 @@ TOX = os.getenv('TOX') or '' in ('1', 'true') PYPY = '__pypy__' in sys.builtin_module_names WIN_VISTA = (6, 0, 0) if WINDOWS else None -# whether we're running this test suite on Travis (https://travis-ci.org/) +# whether we're running this test suite on a Continuous Integration service TRAVIS = bool(os.environ.get('TRAVIS')) -# whether we're running this test suite on Appveyor for Windows -# (http://www.appveyor.com/) APPVEYOR = bool(os.environ.get('APPVEYOR')) +CIRRUS = bool(os.environ.get('CIRRUS')) +CI_TESTING = TRAVIS or APPVEYOR or CIRRUS PYPY = '__pypy__' in sys.builtin_module_names # --- configurable defaults diff --git a/psutil/tests/test_connections.py b/psutil/tests/test_connections.py index 5fda78cbf..b70e6d14d 100755 --- a/psutil/tests/test_connections.py +++ b/psutil/tests/test_connections.py @@ -58,15 +58,15 @@ class Base(object): def setUp(self): safe_rmpath(TESTFN) - if not NETBSD: - # NetBSD opens a UNIX socket to /var/log/run. + if not (NETBSD or FREEBSD): + # process opens a UNIX socket to /var/log/run. cons = thisproc.connections(kind='all') assert not cons, cons def tearDown(self): safe_rmpath(TESTFN) reap_children() - if not NETBSD: + if not (FREEBSD or NETBSD): # Make sure we closed all resources. # NetBSD opens a UNIX socket to /var/log/run. cons = thisproc.connections(kind='all') @@ -318,11 +318,11 @@ def test_unix(self): cons = thisproc.connections(kind='unix') assert not (cons[0].laddr and cons[0].raddr) assert not (cons[1].laddr and cons[1].raddr) - if NETBSD: + if NETBSD or FREEBSD: # On NetBSD creating a UNIX socket will cause # a UNIX connection to /var/run/log. cons = [c for c in cons if c.raddr != '/var/run/log'] - self.assertEqual(len(cons), 2) + self.assertEqual(len(cons), 2, msg=cons) if LINUX or FREEBSD or SUNOS: # remote path is never set self.assertEqual(cons[0].raddr, "") @@ -533,9 +533,9 @@ def test_count(self): for conn in cons: self.assertEqual(conn.family, AF_INET6) self.assertIn(conn.type, (SOCK_STREAM, SOCK_DGRAM)) - # unix (skipped on NetBSD because by default the Python process - # creates a connection to '/var/run/log' UNIX socket) - if HAS_CONNECTIONS_UNIX and not NETBSD: + # Skipped on BSD becayse by default the Python process + # creates a UNIX socket to '/var/run/log'. + if HAS_CONNECTIONS_UNIX and not (FREEBSD or NETBSD): cons = thisproc.connections(kind='unix') self.assertEqual(len(cons), 3) for conn in cons: diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py index 509ffc0cb..13a5bb492 100755 --- a/psutil/tests/test_contracts.py +++ b/psutil/tests/test_contracts.py @@ -238,6 +238,7 @@ def test_cpu_count(self): @unittest.skipIf(not HAS_CPU_FREQ, "not supported") def test_cpu_freq(self): + print(repr(psutil.cpu_freq())) self.assert_ntuple_of_nums(psutil.cpu_freq(), type_=(float, int, long)) def test_disk_io_counters(self): @@ -555,13 +556,7 @@ def memory_info(self, ret, proc): for value in ret: self.assertIsInstance(value, (int, long)) self.assertGreaterEqual(value, 0) - if POSIX and not AIX and ret.vms != 0: - # VMS is always supposed to be the highest - for name in ret._fields: - if name != 'vms': - value = getattr(ret, name) - self.assertGreater(ret.vms, value, msg=ret) - elif WINDOWS: + if WINDOWS: self.assertGreaterEqual(ret.peak_wset, ret.wset) self.assertGreaterEqual(ret.peak_paged_pool, ret.paged_pool) self.assertGreaterEqual(ret.peak_nonpaged_pool, ret.nonpaged_pool) diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py index 4e476871d..616a36545 100755 --- a/psutil/tests/test_misc.py +++ b/psutil/tests/test_misc.py @@ -19,6 +19,7 @@ import socket import stat +from psutil import FREEBSD from psutil import LINUX from psutil import NETBSD from psutil import POSIX @@ -35,6 +36,7 @@ from psutil.tests import bind_unix_socket from psutil.tests import call_until from psutil.tests import chdir +from psutil.tests import CI_TESTING from psutil.tests import create_proc_children_pair from psutil.tests import create_sockets from psutil.tests import create_zombie_proc @@ -712,9 +714,7 @@ def test_meminfo(self): def test_procinfo(self): self.assert_stdout('procinfo.py', str(os.getpid())) - # can't find users on APPVEYOR or TRAVIS - @unittest.skipIf(APPVEYOR or TRAVIS and not psutil.users(), - "unreliable on APPVEYOR or TRAVIS") + @unittest.skipIf(CI_TESTING and not psutil.users(), "no users") def test_who(self): self.assert_stdout('who.py') @@ -1017,7 +1017,8 @@ def tcp_tcp_socketpair(self): self.assertNotEqual(client.getsockname(), addr) @unittest.skipIf(not POSIX, "POSIX only") - @unittest.skipIf(NETBSD, "/var/run/log UNIX socket opened by default") + @unittest.skipIf(NETBSD or FREEBSD, + "/var/run/log UNIX socket opened by default") def test_unix_socketpair(self): p = psutil.Process() num_fds = p.num_fds() diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index 348366ad7..e405393b7 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -22,7 +22,7 @@ from psutil import OPENBSD from psutil import POSIX from psutil import SUNOS -from psutil.tests import APPVEYOR +from psutil.tests import CI_TESTING from psutil.tests import get_kernel_version from psutil.tests import get_test_subprocess from psutil.tests import HAS_NET_IO_COUNTERS @@ -365,13 +365,13 @@ def test_nic_names(self): "couldn't find %s nic in 'ifconfig -a' output\n%s" % ( nic, output)) - # can't find users on APPVEYOR or TRAVIS - @unittest.skipIf(APPVEYOR or TRAVIS and not psutil.users(), - "unreliable on APPVEYOR or TRAVIS") + @unittest.skipIf(CI_TESTING and not psutil.users(), "unreliable on CI") @retry_on_failure() def test_users(self): out = sh("who") lines = out.split('\n') + if not lines: + raise self.skipTest("no users on this system") users = [x.split()[0] for x in lines] terminals = [x.split()[1] for x in lines] self.assertEqual(len(users), len(psutil.users())) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 37eaecf28..2035305fc 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -301,7 +301,7 @@ def test_create_time(self): @unittest.skipIf(TRAVIS, 'not reliable on TRAVIS') def test_terminal(self): terminal = psutil.Process().terminal() - if sys.stdin.isatty() or sys.stdout.isatty(): + if sys.stdin.isatty() or sys.stdout.isatty() or sys.stderr.isatty(): tty = os.path.realpath(sh('tty')) self.assertEqual(terminal, tty) else: diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index f2d072824..c6f8a17a3 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -31,7 +31,7 @@ from psutil import WINDOWS from psutil._compat import FileNotFoundError from psutil._compat import long -from psutil.tests import APPVEYOR +from psutil.tests import CI_TESTING from psutil.tests import ASCII_FS from psutil.tests import check_net_address from psutil.tests import DEVNULL @@ -275,8 +275,9 @@ def test_test(self): finally: sys.stdout = stdout - def test_cpu_count(self): + def test_cpu_count_logical(self): logical = psutil.cpu_count() + self.assertIsNotNone(logical) self.assertEqual(logical, len(psutil.cpu_times(percpu=True))) self.assertGreaterEqual(logical, 1) # @@ -285,7 +286,12 @@ def test_cpu_count(self): cpuinfo_data = fd.read() if "physical id" not in cpuinfo_data: raise unittest.SkipTest("cpuinfo doesn't include physical id") + + def test_cpu_count_physical(self): + logical = psutil.cpu_count() physical = psutil.cpu_count(logical=False) + if physical is None: + raise self.skipTest("physical cpu_count() is None") if WINDOWS and sys.getwindowsversion()[:2] <= (6, 1): # <= Vista self.assertIsNone(physical) else: @@ -695,8 +701,8 @@ def test_net_if_stats_enodev(self): @unittest.skipIf(LINUX and not os.path.exists('/proc/diskstats'), '/proc/diskstats not available on this linux version') - @unittest.skipIf(APPVEYOR and psutil.disk_io_counters() is None, - "unreliable on APPVEYOR") # no visible disks + @unittest.skipIf(CI_TESTING and not psutil.disk_io_counters(), + "unreliable on CI") # no visible disks def test_disk_io_counters(self): def check_ntuple(nt): self.assertEqual(nt[0], nt.read_count) @@ -734,9 +740,7 @@ def test_disk_io_counters_no_disks(self): self.assertEqual(psutil.disk_io_counters(perdisk=True), {}) assert m.called - # can't find users on APPVEYOR or TRAVIS - @unittest.skipIf(APPVEYOR or TRAVIS and not psutil.users(), - "unreliable on APPVEYOR or TRAVIS") + @unittest.skipIf(CI_TESTING and not psutil.users(), "unreliable on CI") def test_users(self): users = psutil.users() self.assertNotEqual(users, []) diff --git a/psutil/tests/test_unicode.py b/psutil/tests/test_unicode.py index 05c94613a..6308de097 100755 --- a/psutil/tests/test_unicode.py +++ b/psutil/tests/test_unicode.py @@ -300,13 +300,10 @@ class TestFSAPIs(_BaseFSAPIsTests, unittest.TestCase): def expect_exact_path_match(cls): # Do not expect psutil to correctly handle unicode paths on # Python 2 if os.listdir() is not able either. - if PY3: - return True - else: - here = '.' if isinstance(cls.funky_name, str) else u('.') - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - return cls.funky_name in os.listdir(here) + here = '.' if isinstance(cls.funky_name, str) else u('.') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + return cls.funky_name in os.listdir(here) @unittest.skipIf(PYPY and TRAVIS, "unreliable on PYPY + TRAVIS")