(self)
| 1185 | @support.requires_linux_version(5, 17, 0) |
| 1186 | @unittest.skipIf(support.linked_to_musl(), "musl libc issue, gh-143632") |
| 1187 | def test_set_name(self): |
| 1188 | # Test setting name on anonymous mmap |
| 1189 | m = mmap.mmap(-1, PAGESIZE) |
| 1190 | self.addCleanup(m.close) |
| 1191 | try: |
| 1192 | result = m.set_name('test_mapping') |
| 1193 | except OSError as exc: |
| 1194 | if exc.errno == errno.EINVAL: |
| 1195 | # gh-142419: On Fedora, prctl(PR_SET_VMA_ANON_NAME) fails with |
| 1196 | # EINVAL because the kernel option CONFIG_ANON_VMA_NAME is |
| 1197 | # disabled. |
| 1198 | # See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 |
| 1199 | self.skipTest("prctl() failed with EINVAL") |
| 1200 | else: |
| 1201 | raise |
| 1202 | self.assertIsNone(result) |
| 1203 | |
| 1204 | # Test name length limit (80 chars including prefix "cpython:mmap:" and '\0') |
| 1205 | # Prefix is 13 chars, so max name is 66 chars |
| 1206 | long_name = 'x' * 66 |
| 1207 | result = m.set_name(long_name) |
| 1208 | self.assertIsNone(result) |
| 1209 | |
| 1210 | # Test name too long |
| 1211 | too_long_name = 'x' * 67 |
| 1212 | with self.assertRaises(ValueError): |
| 1213 | m.set_name(too_long_name) |
| 1214 | |
| 1215 | # Test that file-backed mmap raises error |
| 1216 | with open(TESTFN, 'wb+') as f: |
| 1217 | f.write(b'x' * PAGESIZE) |
| 1218 | f.flush() |
| 1219 | m2 = mmap.mmap(f.fileno(), PAGESIZE) |
| 1220 | self.addCleanup(m2.close) |
| 1221 | |
| 1222 | with self.assertRaises(ValueError): |
| 1223 | m2.set_name('should_fail') |
| 1224 | |
| 1225 | |
| 1226 | class LargeMmapTests(unittest.TestCase): |
nothing calls this directly
no test coverage detected