Skip to content

Commit 220e247

Browse files
committed
run-test-suite.py: update to handle srcdir != builddir
1 parent 5e1ee56 commit 220e247

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ json-examples: plugin
323323
$(INVOCATION_ENV_VARS) $(srcdir)./gcc-with-cpychecker -I/usr/include/python2.7 -c libcpychecker_html/test/example1/bug.c
324324

325325
test-suite: plugin print-gcc-version testdejagnu testdemo
326-
$(INVOCATION_ENV_VARS) $(PYTHON) $(srcdir)./run-test-suite.py
326+
$(INVOCATION_ENV_VARS) $(PYTHON) $(srcdir)./run-test-suite.py $(if $(srcdir),--srcdir=$(srcdir))
327327

328328
show-ssa: plugin
329329
$(INVOCATION_ENV_VARS) $(srcdir)./gcc-with-python examples/show-ssa.py test.c

gccutils/selftests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
def assertEqual(lhs, rhs):
2525
if lhs != rhs:
2626
raise ValueError('non-equal values: %r != %r' % (lhs, rhs))
27+
28+
def assertEndsWith(s, suffix):
29+
if not s.endswith(suffix):
30+
raise ValueError('%r does not end with %r' % (s, suffix))

run-test-suite.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ def _describe_activity(self):
7171
return 'compiling: %s' % ' '.join(self.args)
7272

7373
class TestStream:
74-
def __init__(self, exppath):
74+
def __init__(self, exppath, srcdir):
7575
self.exppath = exppath
76+
self.srcdir = srcdir
7677
if os.path.exists(exppath):
7778
with open(exppath) as f:
7879
expdata = f.read()
@@ -112,6 +113,10 @@ def _cleanup(self, text):
112113
# Handle stuff like this that changes every time:
113114
# "Preprocessed source stored into /tmp/ccRm9Xgx.out file, please attach this to your bugreport."
114115
continue
116+
117+
# Strip away references to the srcdir
118+
line = re.sub(self.srcdir, '', line)
119+
115120
# Remove exact pointer addresses from repr():
116121
line = re.sub(' object at (0x[0-9a-f]*)>',
117122
' object at 0xdeadbeef>',
@@ -272,14 +277,14 @@ class SkipTest(Exception):
272277
def __init__(self, reason):
273278
self.reason = reason
274279

275-
def run_test(testdir):
280+
def run_test(testdir, srcdir):
276281
# Compile each 'input.c', using 'script.py'
277282
# Assume success and empty stdout; compare against expected stderr, or empty if file not present
278283
inputfiles = get_source_files(testdir)
279284
outfile = os.path.join(testdir, 'output.o')
280285
script_py = os.path.join(testdir, 'script.py')
281-
out = TestStream(os.path.join(testdir, 'stdout.txt'))
282-
err = TestStream(os.path.join(testdir, 'stderr.txt'))
286+
out = TestStream(os.path.join(testdir, 'stdout.txt'), srcdir)
287+
err = TestStream(os.path.join(testdir, 'stderr.txt'), srcdir)
283288

284289
cp = configparser.SafeConfigParser()
285290
metadatapath = os.path.join(testdir, 'metadata.ini')
@@ -423,11 +428,18 @@ def uses_python_headers():
423428
type="string",
424429
dest="excluded_dirs",
425430
help="exclude tests in DIR and below", metavar="DIR")
431+
parser.add_option("--srcdir",
432+
type="string",
433+
dest="srcdir",
434+
help="FIXME", metavar="DIR")
426435
parser.add_option("-s", "--show",
427436
action="store_true", dest="show", default=False,
428437
help="Show stdout, stderr and the command line for each test")
429438
(options, args) = parser.parse_args()
430439

440+
if options.srcdir is None:
441+
options.srcdir = os.getcwd() + os.sep
442+
431443
# print (options, args)
432444

433445
def find_tests_below(path):
@@ -445,13 +457,18 @@ def find_tests_below(path):
445457
testdirs += find_tests_below(path)
446458
else:
447459
# Run all the tests
448-
testdirs = find_tests_below('tests')
460+
path = os.path.join(options.srcdir, 'tests')
461+
testdirs = find_tests_below(path)
449462

450463
def exclude_test(test):
464+
if not test.startswith(options.srcdir):
465+
test = os.path.join(options.srcdir, test)
451466
if test in testdirs:
452467
testdirs.remove(test)
453468

454469
def exclude_tests_below(path):
470+
if not path.startswith(options.srcdir):
471+
path = os.path.join(options.srcdir, path)
455472
for test in find_tests_below(path):
456473
exclude_test(test)
457474

@@ -784,7 +801,7 @@ def exclude_tests_below(path):
784801
def run_one_test(testdir):
785802
try:
786803
sys.stdout.write('%s: ' % testdir)
787-
run_test(testdir)
804+
run_test(testdir, options.srcdir)
788805
print('OK')
789806
return (testdir, 'OK', None)
790807
except SkipTest:

tests/cpychecker/refcounts/json/basic/script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright 2012 David Malcolm <dmalcolm@redhat.com>
2-
# Copyright 2012 Red Hat, Inc.
1+
# Copyright 2012, 2019 David Malcolm <dmalcolm@redhat.com>
2+
# Copyright 2012, 2019 Red Hat, Inc.
33
#
44
# This is free software: you can redistribute it and/or modify it
55
# under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
2020
import gcc
2121
from libcpychecker.refcounts import impl_check_refcounts
2222

23-
from gccutils.selftests import assertEqual
23+
from gccutils.selftests import assertEqual, assertEndsWith
2424

2525
def verify_json(optpass, fun):
2626
# Only run in one pass
@@ -34,7 +34,7 @@ def verify_json(optpass, fun):
3434
print(dumps(js, sort_keys=True, indent=4))
3535

3636
# Verify the top-level JSON that's emitted:
37-
assertEqual(js['filename'], 'tests/cpychecker/refcounts/json/basic/input.c')
37+
assertEndsWith(js['filename'], 'tests/cpychecker/refcounts/json/basic/input.c')
3838
assertEqual(js['function']['name'], 'losing_refcnt_of_none')
3939
assertEqual(js['function']['lines'][0], 22)
4040
assertEqual(js['function']['lines'][1], 28)

0 commit comments

Comments
 (0)