Skip to content

Commit 5e2c784

Browse files
committed
[GR-40199] Fix trace module coverage reporting, add smoke test
PullRequest: graalpython/2381
2 parents 19e2857 + 769e574 commit 5e2c784

File tree

2 files changed

+75
-7
lines changed

2 files changed

+75
-7
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
41+
def test_trace_module():
42+
import trace
43+
import sys
44+
45+
tracer = trace.Trace(ignoredirs=[], trace=1, count=1, countfuncs=1, countcallers=1)
46+
47+
tracer.runctx("""
48+
def main():
49+
import os
50+
import distutils
51+
import email
52+
import lib2to3
53+
from email.parser import Parser
54+
Parser().parsestr('Hello world')
55+
56+
main()
57+
""")
58+
59+
r = tracer.results()
60+
r.outfile = None
61+
lines = []
62+
trace.print = lambda *a: lines.append(" ".join(a))
63+
try:
64+
r.write_results(summary=True)
65+
except:
66+
assert False, "writing trace results should not fail"
67+
finally:
68+
del trace.print

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TraceModuleBuiltins.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ PTuple start(VirtualFrame frame, PythonModule mod,
229229
continue;
230230
}
231231

232-
String modName;
232+
TruffleString modName;
233233
TruffleFile file = getContext().getEnv().getPublicTruffleFile(filename);
234234
String baseName = file.getName();
235235
if (baseName != null) {
@@ -240,12 +240,12 @@ PTuple start(VirtualFrame frame, PythonModule mod,
240240

241241
RootCoverage[] rootCoverage = getRootCoverage(c);
242242
for (RootCoverage r : rootCoverage) {
243-
String name = getRootName(r);
243+
TruffleString name = toTruffleStringUncached(getRootName(r));
244244
if (name == null) {
245245
continue;
246246
}
247247
if (countFuncs) {
248-
PTuple tp = factory().createTuple(new Object[]{filename, modName, name});
248+
PTuple tp = factory().createTuple(new Object[]{toTruffleStringUncached(filename), modName, name});
249249
setItemNode.execute(frame, calledFuncs, tp, 1);
250250
}
251251
SectionCoverage[] sectionCoverage = getSectionCoverage(r);
@@ -256,7 +256,7 @@ PTuple start(VirtualFrame frame, PythonModule mod,
256256
if (cnt < 0) {
257257
cnt = 1;
258258
}
259-
PTuple ctp = factory().createTuple(new Object[]{filename, startLine});
259+
PTuple ctp = factory().createTuple(new Object[]{toTruffleStringUncached(filename), startLine});
260260
setItemNode.execute(frame, counts, ctp, cnt);
261261
}
262262
}
@@ -296,11 +296,11 @@ private static RootCoverage[] getRootCoverage(SourceCoverage c) {
296296
}
297297

298298
@TruffleBoundary
299-
private static String deriveModuleName(TruffleFile file, String baseName) {
299+
private static TruffleString deriveModuleName(TruffleFile file, String baseName) {
300300
if (baseName.endsWith("__init__.py")) {
301-
return file.getParent().getName();
301+
return toTruffleStringUncached(file.getParent().getName());
302302
} else {
303-
return baseName.replaceFirst("\\.py$", "");
303+
return toTruffleStringUncached(baseName.replaceFirst("\\.py$", ""));
304304
}
305305
}
306306

0 commit comments

Comments
 (0)