Skip to content

gh-107888: Fix test_mmap.test_access_parameter() on macOS 14 #109928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Lib/test/test_mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,15 @@ def test_access_parameter(self):
# Try writing with PROT_EXEC and without PROT_WRITE
prot = mmap.PROT_READ | getattr(mmap, 'PROT_EXEC', 0)
with open(TESTFN, "r+b") as f:
m = mmap.mmap(f.fileno(), mapsize, prot=prot)
self.assertRaises(TypeError, m.write, b"abcdef")
self.assertRaises(TypeError, m.write_byte, 0)
m.close()
try:
m = mmap.mmap(f.fileno(), mapsize, prot=prot)
except PermissionError:
# on macOS 14, PROT_READ | PROT_WRITE is not allowed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps make this a self.skipTest message?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps make this a self.skipTest message?

That's probably a good idea although there are plenty of other places in test_mmap that simply do a pass for similar types of failures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_access_parameter() is a long function: 124 lines, it contains many tests. If someone wants to use skipTest() as some places, the function should be splitted into sub-functions. Otherwise, there is a risk that newly added code below will be skipped by mistake.

Today I lost 10 min trying to understand why the flush() call that I added at the end doesn't work as expected...

def display_header(use_resources: tuple[str, ...]):
    ...  # <=== a lot more code obviously

    # This makes it easier to remember what to set in your local
    # environment when trying to reproduce a sanitizer failure.
    asan = support.check_sanitizer(address=True)
    msan = support.check_sanitizer(memory=True)
    ubsan = support.check_sanitizer(ub=True)
    sanitizers = []
    if asan:
        sanitizers.append("address")
    if msan:
        sanitizers.append("memory")
    if ubsan:
        sanitizers.append("undefined behavior")
    if not sanitizers:
        return

    print(f"== sanitizers: {', '.join(sanitizers)}")
    for sanitizer, env_var in (
        (asan, "ASAN_OPTIONS"),
        (msan, "MSAN_OPTIONS"),
        (ubsan, "UBSAN_OPTIONS"),
    ):
        options= os.environ.get(env_var)
        if sanitizer and options is not None:
            print(f"== {env_var}={options!r}")

    sys.stdout.flush()  # <====== ADDED CODE ======

pass
else:
self.assertRaises(TypeError, m.write, b"abcdef")
self.assertRaises(TypeError, m.write_byte, 0)
m.close()

def test_bad_file_desc(self):
# Try opening a bad file descriptor...
Expand Down