Skip to content

Commit

Permalink
fix some win tests + upgrade BSD* vmactions
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 18, 2023
1 parent 7dd31ac commit 8e574ff
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/bsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ concurrency:
cancel-in-progress: true
jobs:
freebsd:
runs-on: macos-12
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: vmactions/freebsd-vm@v0
uses: vmactions/freebsd-vm@v1
with:
usesh: true
prepare: |
Expand All @@ -28,11 +28,11 @@ jobs:
make test
make test-memleaks
openbsd:
runs-on: macos-12
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: vmactions/openbsd-vm@v0
uses: vmactions/openbsd-vm@v1
with:
usesh: true
prepare: |
Expand All @@ -46,16 +46,16 @@ jobs:
make test
make test-memleaks
netbsd:
runs-on: macos-12
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run tests
uses: vmactions/netbsd-vm@v0
uses: vmactions/netbsd-vm@v1
with:
usesh: true
prepare: |
set -e
pkg_add -v pkgin
/usr/sbin/pkg_add -v pkgin
pkgin update
pkgin -y install python311-* py311-setuptools-* gcc12-*
run: |
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
archs: "AMD64"
- os: windows-2019
archs: "x86"

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand Down
26 changes: 26 additions & 0 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
'unittest', 'skip_on_access_denied', 'skip_on_not_implemented',
'retry_on_failure', 'TestMemoryLeak', 'PsutilTestCase',
'process_namespace', 'system_namespace', 'print_sysinfo',
'is_win_secure_system_proc',
# fs utils
'chdir', 'safe_rmpath', 'create_exe', 'get_testfn',
# os
Expand Down Expand Up @@ -1295,6 +1296,31 @@ def print_sysinfo():
print("=" * 70, file=sys.stderr) # NOQA
sys.stdout.flush()

if WINDOWS:
os.system("tasklist")
elif which("ps"):
os.system("ps aux")
print("=" * 70, file=sys.stderr) # NOQA
sys.stdout.flush()


def is_win_secure_system_proc(pid):
# see: https://github.com/giampaolo/psutil/issues/2338
@memoize
def get_procs():
ret = {}
out = sh("tasklist.exe /NH /FO csv")
for line in out.splitlines()[1:]:
bits = [x.replace('"', "") for x in line.split(",")]
name, pid = bits[0], int(bits[1])
ret[pid] = name
return ret

try:
return get_procs()[pid] == "Secure System"
except KeyError:
return False


def _get_eligible_cpu():
p = psutil.Process()
Expand Down
14 changes: 8 additions & 6 deletions psutil/tests/test_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from psutil._compat import long
from psutil._compat import range
from psutil._compat import unicode
from psutil.tests import APPVEYOR
from psutil.tests import CI_TESTING
from psutil.tests import GITHUB_ACTIONS
from psutil.tests import HAS_CPU_FREQ
Expand All @@ -51,6 +50,7 @@
from psutil.tests import create_sockets
from psutil.tests import enum
from psutil.tests import is_namedtuple
from psutil.tests import is_win_secure_system_proc
from psutil.tests import kernel_version
from psutil.tests import process_namespace
from psutil.tests import serialrun
Expand Down Expand Up @@ -442,8 +442,8 @@ def test_all(self):
meth(value, info)
except Exception:
s = '\n' + '=' * 70 + '\n'
s += "FAIL: name=test_%s, pid=%s, ret=%s\n" % (
name, info['pid'], repr(value))
s += "FAIL: name=test_%s, pid=%s, ret=%s\ninfo=%s\n" % (
name, info['pid'], repr(value), info)
s += '-' * 70
s += "\n%s" % traceback.format_exc()
s = "\n".join((" " * 4) + i for i in s.splitlines()) + "\n"
Expand Down Expand Up @@ -489,11 +489,12 @@ def ppid(self, ret, info):

def name(self, ret, info):
self.assertIsInstance(ret, (str, unicode))
if APPVEYOR and not ret and info['status'] == 'stopped':
if WINDOWS and not ret and is_win_secure_system_proc(info['pid']):
# https://github.com/giampaolo/psutil/issues/2338
return
# on AIX, "<exiting>" processes don't have names
if not AIX:
assert ret
assert ret, repr(ret)

def create_time(self, ret, info):
self.assertIsInstance(ret, float)
Expand Down Expand Up @@ -562,7 +563,8 @@ def ionice(self, ret, info):

def num_threads(self, ret, info):
self.assertIsInstance(ret, int)
if APPVEYOR and not ret and info['status'] == 'stopped':
if WINDOWS and ret == 0 and is_win_secure_system_proc(info['pid']):
# https://github.com/giampaolo/psutil/issues/2338
return
self.assertGreaterEqual(ret, 1)

Expand Down
13 changes: 8 additions & 5 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,6 @@ def test_nice(self):
init = p.nice()
try:
if WINDOWS:
# A CI runner may limit our maximum priority, which will break
# this test. Instead, we test in order of increasing priority,
# and match either the expected value or the highest so far.
highest_prio = None
for prio in [psutil.IDLE_PRIORITY_CLASS,
psutil.BELOW_NORMAL_PRIORITY_CLASS,
Expand All @@ -842,10 +839,16 @@ def test_nice(self):
pass
else:
new_prio = p.nice()
if CI_TESTING:
# The OS may limit our maximum priority,
# even if the function succeeds. For higher
# priorities, we match either the expected
# value or the highest so far.
if prio in (psutil.ABOVE_NORMAL_PRIORITY_CLASS,
psutil.HIGH_PRIORITY_CLASS,
psutil.REALTIME_PRIORITY_CLASS):
if new_prio == prio or highest_prio is None:
highest_prio = prio
self.assertEqual(new_prio, highest_prio)
self.assertEqual(new_prio, highest_prio)
else:
self.assertEqual(new_prio, prio)
else:
Expand Down
5 changes: 3 additions & 2 deletions scripts/internal/winmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def test_by_name(name):
sh("%s -m unittest -v %s" % (PYTHON, name))


def test_failed():
def test_last_failed():
"""Re-run tests which failed on last run."""
build()
sh("%s %s --last-failed" % (PYTHON, RUNNER_PY))
Expand Down Expand Up @@ -559,7 +559,8 @@ def parse_args():
test_by_name = sp.add_parser('test-by-name', help="<ARG> run test by name")
sp.add_parser('test-connections', help="run connections tests")
sp.add_parser('test-contracts', help="run contracts tests")
sp.add_parser('test-failed', help="re-run tests which failed on last run")
sp.add_parser('test-last-failed',
help="re-run tests which failed on last run")
sp.add_parser('test-memleaks', help="run memory leaks tests")
sp.add_parser('test-misc', help="run misc tests")
sp.add_parser('test-platform', help="run windows only tests")
Expand Down

0 comments on commit 8e574ff

Please sign in to comment.