Skip to content

Commit

Permalink
Add CI testing for FreeBSD (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 24, 2020
1 parent 2093cd0 commit 634572c
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 45 deletions.
16 changes: 16 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions docs/DEVGUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions psutil/tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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, "")
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions psutil/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import socket
import stat

from psutil import FREEBSD
from psutil import LINUX
from psutil import NETBSD
from psutil import POSIX
Expand All @@ -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
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions psutil/tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 11 additions & 7 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
#
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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, [])
Expand Down
11 changes: 4 additions & 7 deletions psutil/tests/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 634572c

Please sign in to comment.