Skip to content

Commit

Permalink
pythongh-124213: Skip tests failing with --suppress-sync=true whe…
Browse files Browse the repository at this point in the history
…n inside systemd-nspawn container

Add a helper functon that checks whether the test suite is running
inside a systemd-nspawn container, and skip the few tests failing
with `--suppress-sync=true` in that case.  The tests are failing because
`--suppress-sync=true` stubs out `fsync()`, `fdatasync()` and `msync()`
calls, and therefore they always return success without checking for
invalid arguments.

Technically, this means that the tests are also skipped when running
inside systemd-nspawn container without `--suppress-sync=true`.
However, to the best of my knowledge the only way to detect this option
is to actually reproduce one of the unexpectedly-succeeding syscalls,
and since this is precisely what we're testing for, the skip-test
and the actual test would be doing the same thing.

Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed Sep 19, 2024
1 parent a9ffcd6 commit c5c6238
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
12 changes: 11 additions & 1 deletion Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import unittest
import urllib.error
import warnings
from pathlib import Path

from .testresult import get_test_runner

Expand Down Expand Up @@ -119,7 +120,8 @@
"run_with_locale", "swap_item",
"swap_attr", "Matcher", "set_memlimit", "SuppressCrashReport", "sortdict",
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
"ALWAYS_EQ", "LARGEST", "SMALLEST"
"ALWAYS_EQ", "LARGEST", "SMALLEST",
"in_systemd_nspawn",
]

class Error(Exception):
Expand Down Expand Up @@ -3411,3 +3413,11 @@ def adjust_int_max_str_digits(max_digits):
yield
finally:
sys.set_int_max_str_digits(current)


def in_systemd_nspawn() -> bool:
try:
return (Path("/run/systemd/container").read_bytes().rstrip() ==
b"systemd-nspawn")
except FileNotFoundError:
return False
5 changes: 3 additions & 2 deletions Lib/test/test_mmap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from test.support import (TESTFN, import_module, unlink,
requires, _2G, _4G, gc_collect, cpython_only)
requires, _2G, _4G, gc_collect, cpython_only,
in_systemd_nspawn,)
import unittest
import os
import re
Expand Down Expand Up @@ -740,7 +741,7 @@ def test_flush_return_value(self):
mm.write(b'python')
result = mm.flush()
self.assertIsNone(result)
if sys.platform.startswith('linux'):
if sys.platform.startswith('linux') and not in_systemd_nspawn():
# 'offset' must be a multiple of mmap.PAGESIZE on Linux.
# See bpo-34754 for details.
self.assertRaises(OSError, mm.flush, 1, len(b'python'))
Expand Down
8 changes: 6 additions & 2 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,12 @@ def test_chmod(self):


class TestInvalidFD(unittest.TestCase):
singles = ["fchdir", "dup", "fdopen", "fdatasync", "fstat",
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
singles = ["fchdir", "dup", "fdopen", "fstat",
"fstatvfs", "tcgetpgrp", "ttyname"]
# systemd-nspawn --suppress-sync=true does not verify fd passed
# fdatasync() and fsync(), and always returns success
if not support.in_systemd_nspawn():
singles += ["fdatasync", "fsync"]
#singles.append("close")
#We omit close because it doesn't raise an exception on some platforms
def get_single(f):
Expand Down

0 comments on commit c5c6238

Please sign in to comment.