aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2021-07-17 16:26:20 +0100
committerGravatar Joe Banks <[email protected]>2021-07-17 16:26:20 +0100
commit096a8d25b7d99032a99f85e07eec1c57b4cabde5 (patch)
tree7f8b886e52396ae79638755be639480a94b8ccd8
parenttest: update pid limit tests to account for new increased limit (diff)
test: add test_multiprocess_resource_limits to test memory limit sharing
This test ensures that spawned child processes inherit the same resource group as the parent by spawning 2 child processes which each allocate a 40MB object, it then verifies that one of the child processes was killed with SIGKILL for violating the resource quota.
-rw-r--r--tests/test_nsjail.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_nsjail.py b/tests/test_nsjail.py
index ec5c56f..c0ed96b 100644
--- a/tests/test_nsjail.py
+++ b/tests/test_nsjail.py
@@ -67,6 +67,34 @@ class NsJailTests(unittest.TestCase):
self.assertIn("Resource temporarily unavailable", result.stdout)
self.assertEqual(result.stderr, None)
+ def test_multiprocess_resource_limits(self):
+ code = dedent("""
+ import time
+ from multiprocessing import Process
+
+ def f():
+ object = "A" * 40_000_000
+ time.sleep(0.5)
+
+
+ proc_1 = Process(target=f)
+ proc_2 = Process(target=f)
+
+ proc_1.start()
+ proc_2.start()
+
+ proc_1.join()
+ proc_2.join()
+
+ print(proc_1.exitcode, proc_2.exitcode)
+ """)
+
+ result = self.nsjail.python3(code)
+
+ exit_codes = result.stdout.strip().split()
+ self.assertIn("-9", exit_codes)
+ self.assertEqual(result.stderr, None)
+
def test_read_only_file_system(self):
for path in ("/", "/etc", "/lib", "/lib64", "/snekbox", "/usr"):
with self.subTest(path=path):