summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_os.py
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-05-29 19:57:07 (GMT)
committerChristian Heimes <christian@python.org>2019-05-29 19:57:03 (GMT)
commit43fdbd2729cb7cdbb5afb5d16352f6604859e564 (patch)
tree88cddedd14a456ffef515fa70718b1cb5ec33b31 /Lib/test/test_os.py
parent0c2f9305640f7655ba0cd5f478948b2763b376b3 (diff)
downloadcpython-43fdbd2729cb7cdbb5afb5d16352f6604859e564.zip
cpython-43fdbd2729cb7cdbb5afb5d16352f6604859e564.tar.gz
cpython-43fdbd2729cb7cdbb5afb5d16352f6604859e564.tar.bz2
bpo-26836: Add os.memfd_create() (#13567)
* bpo-26836: Add os.memfd_create() * Use the glibc wrapper for memfd_create() Co-Authored-By: Christian Heimes <christian@python.org> * Fix deletions caused by autoreconf. * Use MFD_CLOEXEC as the default value for *flags*. * Add memset_s to configure.ac. * Revert memset_s changes. * Apply the requested changes. * Tweak the docs.
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r--Lib/test/test_os.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 353b9a5..820c99c 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -3122,6 +3122,22 @@ class TermsizeTests(unittest.TestCase):
self.assertEqual(expected, actual)
+@unittest.skipUnless(hasattr(os, 'memfd_create'), 'requires os.memfd_create')
+class MemfdCreateTests(unittest.TestCase):
+ def test_memfd_create(self):
+ fd = os.memfd_create("Hi", os.MFD_CLOEXEC)
+ self.assertNotEqual(fd, -1)
+ self.addCleanup(os.close, fd)
+ self.assertFalse(os.get_inheritable(fd))
+ with open(fd, "wb", closefd=False) as f:
+ f.write(b'memfd_create')
+ self.assertEqual(f.tell(), 12)
+
+ fd2 = os.memfd_create("Hi")
+ self.addCleanup(os.close, fd2)
+ self.assertFalse(os.get_inheritable(fd2))
+
+
class OSErrorTests(unittest.TestCase):
def setUp(self):
class Str(str):