Browse Source

test.include.pexpect: add `timeout` param

The MMGen Project 2 years ago
parent
commit
06f914e2a8
2 changed files with 5 additions and 3 deletions
  1. 3 3
      test/include/pexpect.py
  2. 2 0
      test/test.py

+ 3 - 3
test/include/pexpect.py

@@ -40,7 +40,7 @@ NL = '\n'
 
 
 class MMGenPexpect:
 class MMGenPexpect:
 
 
-	def __init__(self,args,no_output=False,env=None,pexpect_spawn=False,send_delay=None):
+	def __init__(self,args,no_output=False,env=None,pexpect_spawn=False,send_delay=None,timeout=None):
 
 
 		self.pexpect_spawn = pexpect_spawn
 		self.pexpect_spawn = pexpect_spawn
 		self.send_delay = send_delay
 		self.send_delay = send_delay
@@ -53,7 +53,7 @@ class MMGenPexpect:
 			from subprocess import run,DEVNULL
 			from subprocess import run,DEVNULL
 			run([args[0]] + args[1:],check=True,stdout=DEVNULL if no_output else None)
 			run([args[0]] + args[1:],check=True,stdout=DEVNULL if no_output else None)
 		else:
 		else:
-			timeout = int(opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)]
+			timeout = int(timeout or opt.pexpect_timeout or 0) or (60,5)[bool(opt.debug_pexpect)]
 			if pexpect_spawn:
 			if pexpect_spawn:
 				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=env)
 				self.p = pexpect.spawn(args[0],args[1:],encoding='utf8',timeout=timeout,env=env)
 			else:
 			else:
@@ -198,7 +198,7 @@ class MMGenPexpect:
 			m1 = f'\nERROR.  Expect {s!r} timed out.  Exiting\n'
 			m1 = f'\nERROR.  Expect {s!r} timed out.  Exiting\n'
 			m2 = f'before: [{self.p.before}]\n'
 			m2 = f'before: [{self.p.before}]\n'
 			m3 = f'sent value: [{self.sent_value}]' if self.sent_value != None else ''
 			m3 = f'sent value: [{self.sent_value}]' if self.sent_value != None else ''
-			die(2,m1+m2+m3)
+			raise pexpect.TIMEOUT(m1+m2+m3)
 
 
 		if opt.debug_pexpect:
 		if opt.debug_pexpect:
 			debug_pexpect_msg(self.p)
 			debug_pexpect_msg(self.p)

+ 2 - 0
test/test.py

@@ -569,6 +569,7 @@ class TestSuiteRunner(object):
 			no_msg       = False,
 			no_msg       = False,
 			cmd_dir      = 'cmds',
 			cmd_dir      = 'cmds',
 			no_exec_wrapper = False,
 			no_exec_wrapper = False,
+			timeout       = None,
 			pexpect_spawn = None ):
 			pexpect_spawn = None ):
 
 
 		desc = self.ts.test_name if opt.names else self.gm.dpy_data[self.ts.test_name][1]
 		desc = self.ts.test_name if opt.names else self.gm.dpy_data[self.ts.test_name][1]
@@ -641,6 +642,7 @@ class TestSuiteRunner(object):
 			no_output     = no_output,
 			no_output     = no_output,
 			env           = env,
 			env           = env,
 			pexpect_spawn = pexpect_spawn,
 			pexpect_spawn = pexpect_spawn,
+			timeout       = timeout,
 			send_delay    = send_delay )
 			send_delay    = send_delay )
 
 
 	def end_msg(self):
 	def end_msg(self):