[Git][ghc/ghc][master] 5 commits: testsuite: Don't fail if we can't unlink __symlink_test
Marge Bot
gitlab at gitlab.haskell.org
Mon Jun 1 10:38:36 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
15857ad8 by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Don't fail if we can't unlink __symlink_test
Afterall, it's possible we were unable to create it due to lack of
symlink permission.
- - - - -
4a7229ef by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Refactor ghostscript detection
Tamar reported that he saw crashes due to unhandled exceptions.
- - - - -
2ab37eaf by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite/perf_notes: Fix ill-typed assignments
- - - - -
e45d5b66 by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite/testutil: Fix bytes/str mismatch
- - - - -
7002d0cb by Ben Gamari at 2020-06-01T06:38:26-04:00
testsuite: Work around spurious mypy failure
- - - - -
5 changed files:
- testsuite/driver/my_typing.py
- testsuite/driver/perf_notes.py
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- testsuite/driver/testutil.py
Changes:
=====================================
testsuite/driver/my_typing.py
=====================================
@@ -26,7 +26,7 @@ except:
# TextIO is missing on some older Pythons.
if 'TextIO' not in globals():
try:
- TextIO = typing.TextIO
+ from typing import TextIO
except ImportError:
TextIO = None # type: ignore
else:
=====================================
testsuite/driver/perf_notes.py
=====================================
@@ -126,10 +126,11 @@ def get_perf_stats(commit: Union[GitRef, GitHash]=GitRef('HEAD'),
except subprocess.CalledProcessError:
return []
- log = log.strip('\n').split('\n')
- log = list(filter(None, log))
- log = [parse_perf_stat(stat_str) for stat_str in log]
- return log
+ return \
+ [ parse_perf_stat(stat_str)
+ for stat_str in log.strip('\n').split('\n')
+ if stat_str != ''
+ ]
# Check if a str is in a 40 character git commit hash.
_commit_hash_re = re.compile('[0-9a-f]' * 40)
=====================================
testsuite/driver/testglobals.py
=====================================
@@ -43,7 +43,7 @@ class TestConfig:
self.summary_file = ''
# Path to Ghostscript
- self.gs = ''
+ self.gs = None # type: Optional[Path]
# Run tests requiring Haddock
self.haddock = False
=====================================
testsuite/driver/testlib.py
=====================================
@@ -22,7 +22,7 @@ from testglobals import config, ghc_env, default_testopts, brokens, t, \
TestRun, TestResult, TestOptions, PerfMetric
from testutil import strip_quotes, lndir, link_or_copy_file, passed, \
failBecause, testing_metrics, \
- PassFail
+ PassFail, memoize
from term_color import Color, colored
import testutil
from cpu_features import have_cpu_feature
@@ -1895,7 +1895,7 @@ def check_hp_ok(name: TestName) -> bool:
if hp2psResult == 0:
if actual_ps_path.exists():
- if gs_working:
+ if does_ghostscript_work():
gsResult = runCmd(genGSCmd(actual_ps_path))
if (gsResult == 0):
return True
@@ -2335,31 +2335,38 @@ def runCmd(cmd: str,
# -----------------------------------------------------------------------------
# checking if ghostscript is available for checking the output of hp2ps
-
def genGSCmd(psfile: Path) -> str:
return '{{gs}} -dNODISPLAY -dBATCH -dQUIET -dNOPAUSE "{0}"'.format(psfile)
-def gsNotWorking() -> None:
- global gs_working
- print("GhostScript not available for hp2ps tests")
-
-global gs_working
-gs_working = False
-if config.have_profiling:
- if config.gs != '':
- resultGood = runCmd(genGSCmd(config.top + '/config/good.ps'));
- if resultGood == 0:
- resultBad = runCmd(genGSCmd(config.top + '/config/bad.ps') +
- ' >/dev/null 2>&1')
- if resultBad != 0:
- print("GhostScript available for hp2ps tests")
- gs_working = True
- else:
- gsNotWorking();
- else:
- gsNotWorking();
- else:
- gsNotWorking();
+ at memoize
+def does_ghostscript_work() -> bool:
+ """
+ Detect whether Ghostscript is functional.
+ """
+ def gsNotWorking(reason: str) -> None:
+ print("GhostScript not available for hp2ps tests:", reason)
+
+ if config.gs is None:
+ return False
+
+ try:
+ if runCmd(genGSCmd(config.top / 'config' / 'good.ps')) != 0:
+ gsNotWorking("gs can't process good input")
+ return False
+ except Exception as e:
+ gsNotWorking('error invoking gs on bad input: %s' % e)
+ return False
+
+ try:
+ cmd = genGSCmd(config.top / 'config' / 'bad.ps') + ' >/dev/null 2>&1'
+ if runCmd(cmd) == 0:
+ gsNotWorking('gs accepts bad input')
+ return False
+ except Exception as e:
+ gsNotWorking('error invoking gs on bad input: %s' % e)
+ return False
+
+ return True
def add_suffix( name: Union[str, Path], suffix: str ) -> Path:
if suffix == '':
=====================================
testsuite/driver/testutil.py
=====================================
@@ -55,7 +55,7 @@ def getStdout(cmd_and_args: List[str]):
if r != 0:
raise Exception("Command failed: " + str(cmd_and_args))
if stderr:
- raise Exception("stderr from command: %s\nOutput:\n%s\n" % (cmd_and_args, stderr))
+ raise Exception("stderr from command: %s\nOutput:\n%s\n" % (cmd_and_args, stderr.decode('utf-8')))
return stdout.decode('utf-8')
def lndir(srcdir: Path, dstdir: Path):
@@ -98,7 +98,10 @@ def symlinks_work() -> bool:
except OSError as e:
print('Saw {} during symlink test; assuming symlinks do not work.'.format(e))
finally:
- os.unlink('__symlink-test')
+ try:
+ os.unlink('__symlink-test')
+ except:
+ pass
return works
else:
@@ -128,3 +131,16 @@ class Watcher(object):
if self.pool <= 0:
self.evt.set()
self.sync_lock.release()
+
+def memoize(f):
+ """
+ A decorator to memoize a nullary function.
+ """
+ def cached():
+ if cached._cache is None:
+ cached._cache = f()
+
+ return cached._cache
+
+ cached._cache = None
+ return cached
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5aaf08f25ef0629432c792880dfc6785ff3ec8a3...7002d0cbbe1581dd157b530e95c62195f37cfe00
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5aaf08f25ef0629432c792880dfc6785ff3ec8a3...7002d0cbbe1581dd157b530e95c62195f37cfe00
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200601/3942f319/attachment-0001.html>
More information about the ghc-commits
mailing list