@@ -531,6 +531,14 @@ class Base(unittest.TestCase):
531531 # Keep track of the old current working directory.
532532 oldcwd = None
533533
534+ # Maximum allowed attempts when launching the inferior process.
535+ # Can be overridden by the LLDB_MAX_LAUNCH_COUNT environment variable.
536+ maxLaunchCount = 1
537+
538+ # Time to wait before the next launching attempt in second(s).
539+ # Can be overridden by the LLDB_TIME_WAIT_NEXT_LAUNCH environment variable.
540+ timeWaitNextLaunch = 1.0
541+
534542 @staticmethod
535543 def compute_mydir (test_file ):
536544 """Subclasses should call this function to correctly calculate the
@@ -796,6 +804,12 @@ def setUp(self):
796804 # import traceback
797805 # traceback.print_stack()
798806
807+ if "LLDB_MAX_LAUNCH_COUNT" in os .environ :
808+ self .maxLaunchCount = int (os .environ ["LLDB_MAX_LAUNCH_COUNT" ])
809+
810+ if "LLDB_TIME_WAIT_NEXT_LAUNCH" in os .environ :
811+ self .timeWaitNextLaunch = float (os .environ ["LLDB_TIME_WAIT_NEXT_LAUNCH" ])
812+
799813 if "LIBCXX_PATH" in os .environ :
800814 self .libcxxPath = os .environ ["LIBCXX_PATH" ]
801815 else :
@@ -937,6 +951,57 @@ def spawnSubprocess(self, executable, args=[], extra_env=None, install_remote=Tr
937951 self .subprocesses .append (proc )
938952 return proc
939953
954+ def runCmd (self , cmd , msg = None , check = True , trace = False , inHistory = False ):
955+ """
956+ Ask the command interpreter to handle the command and then check its
957+ return status.
958+ """
959+ # Fail fast if 'cmd' is not meaningful.
960+ if cmd is None :
961+ raise Exception ("Bad 'cmd' parameter encountered" )
962+
963+ trace = True if traceAlways else trace
964+
965+ if cmd .startswith ("target create " ):
966+ cmd = cmd .replace ("target create " , "file " )
967+
968+ running = cmd .startswith ("run" ) or cmd .startswith ("process launch" )
969+
970+ for i in range (self .maxLaunchCount if running else 1 ):
971+ with recording (self , trace ) as sbuf :
972+ print ("runCmd:" , cmd , file = sbuf )
973+ if not check :
974+ print ("check of return status not required" , file = sbuf )
975+
976+ self .ci .HandleCommand (cmd , self .res , inHistory )
977+
978+ with recording (self , trace ) as sbuf :
979+ if self .res .Succeeded ():
980+ print ("output:" , self .res .GetOutput (), file = sbuf )
981+ else :
982+ print ("runCmd failed!" , file = sbuf )
983+ print (self .res .GetError (), file = sbuf )
984+
985+ if self .res .Succeeded ():
986+ break
987+ elif running :
988+ # For process launch, wait some time before possible next try.
989+ time .sleep (self .timeWaitNextLaunch )
990+ with recording (self , trace ) as sbuf :
991+ print ("Command '" + cmd + "' failed!" , file = sbuf )
992+
993+ if check :
994+ output = ""
995+ if self .res .GetOutput ():
996+ output += "\n Command output:\n " + self .res .GetOutput ()
997+ if self .res .GetError ():
998+ output += "\n Error output:\n " + self .res .GetError ()
999+ if msg :
1000+ msg += output
1001+ if cmd :
1002+ cmd += output
1003+ self .assertTrue (self .res .Succeeded (), msg if (msg ) else CMD_MSG (cmd ))
1004+
9401005 def HideStdout (self ):
9411006 """Hide output to stdout from the user.
9421007
@@ -1764,14 +1829,6 @@ class TestBase(Base, metaclass=LLDBTestCaseFactory):
17641829 # test multiple times with various debug info types.
17651830 NO_DEBUG_INFO_TESTCASE = False
17661831
1767- # Maximum allowed attempts when launching the inferior process.
1768- # Can be overridden by the LLDB_MAX_LAUNCH_COUNT environment variable.
1769- maxLaunchCount = 1
1770-
1771- # Time to wait before the next launching attempt in second(s).
1772- # Can be overridden by the LLDB_TIME_WAIT_NEXT_LAUNCH environment variable.
1773- timeWaitNextLaunch = 1.0
1774-
17751832 def generateSource (self , source ):
17761833 template = source + ".template"
17771834 temp = os .path .join (self .getSourceDir (), template )
@@ -1812,12 +1869,6 @@ def setUp(self):
18121869 for s in self .setUpCommands ():
18131870 self .runCmd (s )
18141871
1815- if "LLDB_MAX_LAUNCH_COUNT" in os .environ :
1816- self .maxLaunchCount = int (os .environ ["LLDB_MAX_LAUNCH_COUNT" ])
1817-
1818- if "LLDB_TIME_WAIT_NEXT_LAUNCH" in os .environ :
1819- self .timeWaitNextLaunch = float (os .environ ["LLDB_TIME_WAIT_NEXT_LAUNCH" ])
1820-
18211872 # We want our debugger to be synchronous.
18221873 self .dbg .SetAsync (False )
18231874
@@ -1983,57 +2034,6 @@ def switch_to_thread_with_stop_reason(self, stop_reason):
19832034 if matched :
19842035 self .runCmd ("thread select %s" % matched .group (1 ))
19852036
1986- def runCmd (self , cmd , msg = None , check = True , trace = False , inHistory = False ):
1987- """
1988- Ask the command interpreter to handle the command and then check its
1989- return status.
1990- """
1991- # Fail fast if 'cmd' is not meaningful.
1992- if cmd is None :
1993- raise Exception ("Bad 'cmd' parameter encountered" )
1994-
1995- trace = True if traceAlways else trace
1996-
1997- if cmd .startswith ("target create " ):
1998- cmd = cmd .replace ("target create " , "file " )
1999-
2000- running = cmd .startswith ("run" ) or cmd .startswith ("process launch" )
2001-
2002- for i in range (self .maxLaunchCount if running else 1 ):
2003- with recording (self , trace ) as sbuf :
2004- print ("runCmd:" , cmd , file = sbuf )
2005- if not check :
2006- print ("check of return status not required" , file = sbuf )
2007-
2008- self .ci .HandleCommand (cmd , self .res , inHistory )
2009-
2010- with recording (self , trace ) as sbuf :
2011- if self .res .Succeeded ():
2012- print ("output:" , self .res .GetOutput (), file = sbuf )
2013- else :
2014- print ("runCmd failed!" , file = sbuf )
2015- print (self .res .GetError (), file = sbuf )
2016-
2017- if self .res .Succeeded ():
2018- break
2019- elif running :
2020- # For process launch, wait some time before possible next try.
2021- time .sleep (self .timeWaitNextLaunch )
2022- with recording (self , trace ) as sbuf :
2023- print ("Command '" + cmd + "' failed!" , file = sbuf )
2024-
2025- if check :
2026- output = ""
2027- if self .res .GetOutput ():
2028- output += "\n Command output:\n " + self .res .GetOutput ()
2029- if self .res .GetError ():
2030- output += "\n Error output:\n " + self .res .GetError ()
2031- if msg :
2032- msg += output
2033- if cmd :
2034- cmd += output
2035- self .assertTrue (self .res .Succeeded (), msg if (msg ) else CMD_MSG (cmd ))
2036-
20372037 def match (
20382038 self , str , patterns , msg = None , trace = False , error = False , matching = True , exe = True
20392039 ):
0 commit comments