Skip to content

Commit e98c305

Browse files
joyeecheungmarco-ippolito
authored andcommittedJun 17, 2024
tools: support max_virtual_memory test configuration
PR-URL: #52766 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent dce0300 commit e98c305

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed
 

‎tools/test.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import copy
4747
import io
4848

49-
5049
if sys.version_info >= (3, 5):
5150
from importlib import machinery, util
5251
def get_module(name, path):
@@ -572,6 +571,7 @@ def __init__(self, context, path, arch, mode):
572571
self.mode = mode
573572
self.parallel = False
574573
self.disable_core_files = False
574+
self.max_virtual_memory = None
575575
self.serial_id = 0
576576
self.thread_id = 0
577577

@@ -595,7 +595,8 @@ def RunCommand(self, command, env):
595595
self.context,
596596
self.context.GetTimeout(self.mode, self.config.section),
597597
env,
598-
disable_core_files = self.disable_core_files)
598+
disable_core_files = self.disable_core_files,
599+
max_virtual_memory = self.max_virtual_memory)
599600
return TestOutput(self,
600601
full_command,
601602
output,
@@ -759,7 +760,8 @@ def CheckedUnlink(name):
759760
PrintError("os.unlink() " + str(e))
760761
break
761762

762-
def Execute(args, context, timeout=None, env=None, disable_core_files=False, stdin=None):
763+
def Execute(args, context, timeout=None, env=None, disable_core_files=False,
764+
stdin=None, max_virtual_memory=None):
763765
(fd_out, outname) = tempfile.mkstemp()
764766
(fd_err, errname) = tempfile.mkstemp()
765767

@@ -781,11 +783,27 @@ def Execute(args, context, timeout=None, env=None, disable_core_files=False, std
781783

782784
preexec_fn = None
783785

786+
def disableCoreFiles():
787+
import resource
788+
resource.setrlimit(resource.RLIMIT_CORE, (0,0))
789+
784790
if disable_core_files and not utils.IsWindows():
785-
def disableCoreFiles():
791+
preexec_fn = disableCoreFiles
792+
793+
if max_virtual_memory is not None and utils.GuessOS() == 'linux':
794+
def setMaxVirtualMemory():
786795
import resource
787796
resource.setrlimit(resource.RLIMIT_CORE, (0,0))
788-
preexec_fn = disableCoreFiles
797+
resource.setrlimit(resource.RLIMIT_AS, (max_virtual_memory,max_virtual_memory + 1))
798+
799+
if preexec_fn is not None:
800+
prev_preexec_fn = preexec_fn
801+
def setResourceLimits():
802+
setMaxVirtualMemory()
803+
prev_preexec_fn()
804+
preexec_fn = setResourceLimits
805+
else:
806+
preexec_fn = setMaxVirtualMemory
789807

790808
(process, exit_code, timed_out) = RunProcess(
791809
context,

0 commit comments

Comments
 (0)
Please sign in to comment.