[tests] Remove py2 workaround for lack of timeout in subprocess
This commit is contained in:
parent
b5526a09ff
commit
761695264b
|
@ -1,40 +1,24 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys, os, subprocess, tempfile, threading, shutil
|
import sys, os, subprocess, tempfile, shutil
|
||||||
|
|
||||||
|
|
||||||
def cmd (command):
|
def cmd (command):
|
||||||
# https://stackoverflow.com/a/4408409
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
||||||
# https://stackoverflow.com/a/10012262
|
|
||||||
with tempfile.TemporaryFile () as tempf:
|
with tempfile.TemporaryFile () as tempf:
|
||||||
p = subprocess.Popen (command, stderr=tempf)
|
p = subprocess.Popen (command, stderr=tempf)
|
||||||
is_killed = {'value': False}
|
|
||||||
|
|
||||||
def timeout (p, is_killed):
|
|
||||||
is_killed['value'] = True
|
|
||||||
p.kill ()
|
|
||||||
timeout_seconds = int (os.environ.get ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2"))
|
|
||||||
timer = threading.Timer (timeout_seconds, timeout, [p, is_killed])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timer.start()
|
p.wait (timeout=int (os.environ.get ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2")))
|
||||||
p.wait ()
|
|
||||||
tempf.seek (0)
|
tempf.seek (0)
|
||||||
text = tempf.read ()
|
text = tempf.read ()
|
||||||
|
|
||||||
#TODO: Detect debug mode with a better way
|
#TODO: Detect debug mode with a better way
|
||||||
is_debug_mode = b"SANITIZE" in text
|
is_debug_mode = b"SANITIZE" in text
|
||||||
|
|
||||||
text = "" if is_debug_mode else text.decode ("utf-8").strip ()
|
return ("" if is_debug_mode else text.decode ("utf-8").strip ()), p.returncode
|
||||||
returncode = p.returncode
|
except subprocess.TimeoutExpired:
|
||||||
finally:
|
return 'error: timeout, ' + ' '.join (command), 1
|
||||||
timer.cancel()
|
|
||||||
|
|
||||||
if is_killed['value']:
|
|
||||||
text = 'error: timeout, ' + text
|
|
||||||
returncode = 1
|
|
||||||
|
|
||||||
return text, returncode
|
|
||||||
|
|
||||||
|
|
||||||
srcdir = os.environ.get ("srcdir", ".")
|
srcdir = os.environ.get ("srcdir", ".")
|
||||||
|
|
|
@ -1,40 +1,24 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys, os, subprocess, tempfile, threading, shutil
|
import sys, os, subprocess, tempfile, shutil
|
||||||
|
|
||||||
|
|
||||||
def cmd (command):
|
def cmd (command):
|
||||||
# https://stackoverflow.com/a/4408409
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
||||||
# https://stackoverflow.com/a/10012262
|
|
||||||
with tempfile.TemporaryFile () as tempf:
|
with tempfile.TemporaryFile () as tempf:
|
||||||
p = subprocess.Popen (command, stderr=tempf)
|
p = subprocess.Popen (command, stderr=tempf)
|
||||||
is_killed = {'value': False}
|
|
||||||
|
|
||||||
def timeout (p, is_killed):
|
|
||||||
is_killed['value'] = True
|
|
||||||
p.kill ()
|
|
||||||
timeout_seconds = int (os.environ.get ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2"))
|
|
||||||
timer = threading.Timer (timeout_seconds, timeout, [p, is_killed])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timer.start()
|
p.wait (timeout=int (os.environ.get ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2")))
|
||||||
p.wait ()
|
|
||||||
tempf.seek (0)
|
tempf.seek (0)
|
||||||
text = tempf.read ()
|
text = tempf.read ()
|
||||||
|
|
||||||
#TODO: Detect debug mode with a better way
|
#TODO: Detect debug mode with a better way
|
||||||
is_debug_mode = b"SANITIZE" in text
|
is_debug_mode = b"SANITIZE" in text
|
||||||
|
|
||||||
text = "" if is_debug_mode else text.decode ("utf-8").strip ()
|
return ("" if is_debug_mode else text.decode ("utf-8").strip ()), p.returncode
|
||||||
returncode = p.returncode
|
except subprocess.TimeoutExpired:
|
||||||
finally:
|
return 'error: timeout, ' + ' '.join (command), 1
|
||||||
timer.cancel()
|
|
||||||
|
|
||||||
if is_killed['value']:
|
|
||||||
text = 'error: timeout, ' + text
|
|
||||||
returncode = 1
|
|
||||||
|
|
||||||
return text, returncode
|
|
||||||
|
|
||||||
|
|
||||||
srcdir = os.environ.get ("srcdir", ".")
|
srcdir = os.environ.get ("srcdir", ".")
|
||||||
|
|
|
@ -1,40 +1,24 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys, os, subprocess, tempfile, threading, shutil
|
import sys, os, subprocess, tempfile, shutil
|
||||||
|
|
||||||
|
|
||||||
def cmd(command):
|
def cmd (command):
|
||||||
# https://stackoverflow.com/a/4408409
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
||||||
# https://stackoverflow.com/a/10012262
|
with tempfile.TemporaryFile () as tempf:
|
||||||
with tempfile.TemporaryFile() as tempf:
|
|
||||||
p = subprocess.Popen (command, stderr=tempf)
|
p = subprocess.Popen (command, stderr=tempf)
|
||||||
is_killed = {'value': False}
|
|
||||||
|
|
||||||
def timeout(p, is_killed):
|
|
||||||
is_killed['value'] = True
|
|
||||||
p.kill()
|
|
||||||
timeout_seconds = int (os.environ.get ("HB_TEST_SUBSET_FUZZER_TIMEOUT", "12"))
|
|
||||||
timer = threading.Timer (timeout_seconds, timeout, [p, is_killed])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
timer.start()
|
p.wait (timeout=int (os.environ.get ("HB_TEST_SUBSET_FUZZER_TIMEOUT", "12")))
|
||||||
p.wait ()
|
|
||||||
tempf.seek (0)
|
tempf.seek (0)
|
||||||
text = tempf.read ()
|
text = tempf.read ()
|
||||||
|
|
||||||
#TODO: Detect debug mode with a better way
|
#TODO: Detect debug mode with a better way
|
||||||
is_debug_mode = b"SANITIZE" in text
|
is_debug_mode = b"SANITIZE" in text
|
||||||
|
|
||||||
text = "" if is_debug_mode else text.decode ("utf-8").strip ()
|
return ("" if is_debug_mode else text.decode ("utf-8").strip ()), p.returncode
|
||||||
returncode = p.returncode
|
except subprocess.TimeoutExpired:
|
||||||
finally:
|
return 'error: timeout, ' + ' '.join (command), 1
|
||||||
timer.cancel()
|
|
||||||
|
|
||||||
if is_killed['value']:
|
|
||||||
text = 'error: timeout, ' + text
|
|
||||||
returncode = 1
|
|
||||||
|
|
||||||
return text, returncode
|
|
||||||
|
|
||||||
|
|
||||||
srcdir = os.environ.get ("srcdir", ".")
|
srcdir = os.environ.get ("srcdir", ".")
|
||||||
|
|
Loading…
Reference in New Issue