Skip to content

Commit 11faa21

Browse files
committed
Merge from 3.5 for issue python#25188.
2 parents 5f9d3ac + be7c163 commit 11faa21

File tree

7 files changed

+47
-21
lines changed

7 files changed

+47
-21
lines changed

Lib/test/libregrtest/cmdline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ def _create_parser():
236236
group.add_argument('--list-tests', action='store_true',
237237
help="only write the name of tests that will be run, "
238238
"don't execute them")
239+
group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
240+
help='enable Profile Guided Optimization training')
239241

240242
parser.add_argument('args', nargs=argparse.REMAINDER,
241243
help=argparse.SUPPRESS)
@@ -279,7 +281,7 @@ def _parse_args(args, **kwargs):
279281
findleaks=False, use_resources=None, trace=False, coverdir='coverage',
280282
runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,
281283
random_seed=None, use_mp=None, verbose3=False, forever=False,
282-
header=False, failfast=False, match_tests=None)
284+
header=False, failfast=False, match_tests=None, pgo=False)
283285
for k, v in kwargs.items():
284286
if not hasattr(ns, k):
285287
raise TypeError('%r is an invalid keyword argument '
@@ -299,6 +301,8 @@ def _parse_args(args, **kwargs):
299301
parser.error("-l and -j don't go together!")
300302
if ns.failfast and not (ns.verbose or ns.verbose3):
301303
parser.error("-G/--failfast needs either -v or -W")
304+
if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
305+
parser.error("--pgo/-v don't go together!")
302306

303307
if ns.quiet:
304308
ns.verbose = 0

Lib/test/libregrtest/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ def accumulate_result(self, test, result):
103103
def display_progress(self, test_index, test):
104104
if self.ns.quiet:
105105
return
106-
fmt = "[{1:{0}}{2}/{3}] {4}" if self.bad else "[{1:{0}}{2}] {4}"
106+
if self.bad and not self.ns.pgo:
107+
fmt = "[{1:{0}}{2}/{3}] {4}"
108+
else:
109+
fmt = "[{1:{0}}{2}] {4}"
107110
print(fmt.format(self.test_count_width, test_index,
108111
self.test_count, len(self.bad), test),
109112
flush=True)
@@ -238,6 +241,11 @@ def display_result(self):
238241
print(count(len(omitted), "test"), "omitted:")
239242
printlist(omitted)
240243

244+
# If running the test suite for PGO then no one cares about
245+
# results.
246+
if self.ns.pgo:
247+
return
248+
241249
if self.good and not self.ns.quiet:
242250
if (not self.bad
243251
and not self.skipped
@@ -314,7 +322,7 @@ def run_tests(self):
314322
# For a partial run, we do not need to clutter the output.
315323
if (self.ns.verbose
316324
or self.ns.header
317-
or not (self.ns.quiet or self.ns.single
325+
or not (self.ns.pgo or self.ns.quiet or self.ns.single
318326
or self.tests or self.ns.args)):
319327
# Print basic platform information
320328
print("==", platform.python_implementation(), *sys.version.split())

Lib/test/libregrtest/runtest.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def runtest(ns, test):
6565
timeout -- dump the traceback and exit if a test takes more than
6666
timeout seconds
6767
failfast, match_tests -- See regrtest command-line flags for these.
68+
pgo -- if true, suppress any info irrelevant to a generating a PGO build
6869
6970
Returns the tuple result, test_time, where result is one of the constants:
7071
INTERRUPTED KeyboardInterrupt when run under -j
@@ -82,6 +83,7 @@ def runtest(ns, test):
8283
failfast = ns.failfast
8384
match_tests = ns.match_tests
8485
timeout = ns.timeout
86+
pgo = ns.pgo
8587

8688
use_timeout = (timeout is not None)
8789
if use_timeout:
@@ -110,7 +112,7 @@ def runtest(ns, test):
110112
sys.stdout = stream
111113
sys.stderr = stream
112114
result = runtest_inner(test, verbose, quiet, huntrleaks,
113-
display_failure=False)
115+
display_failure=False, pgo=pgo)
114116
if result[0] == FAILED:
115117
output = stream.getvalue()
116118
orig_stderr.write(output)
@@ -121,7 +123,7 @@ def runtest(ns, test):
121123
else:
122124
support.verbose = verbose # Tell tests to be moderately quiet
123125
result = runtest_inner(test, verbose, quiet, huntrleaks,
124-
display_failure=not verbose)
126+
display_failure=not verbose, pgo=pgo)
125127
return result
126128
finally:
127129
if use_timeout:
@@ -131,7 +133,7 @@ def runtest(ns, test):
131133

132134

133135
def runtest_inner(test, verbose, quiet,
134-
huntrleaks=False, display_failure=True):
136+
huntrleaks=False, display_failure=True, *, pgo=False):
135137
support.unload(test)
136138

137139
test_time = 0.0
@@ -142,7 +144,7 @@ def runtest_inner(test, verbose, quiet,
142144
else:
143145
# Always import it from the test package
144146
abstest = 'test.' + test
145-
with saved_test_environment(test, verbose, quiet) as environment:
147+
with saved_test_environment(test, verbose, quiet, pgo=pgo) as environment:
146148
start_time = time.time()
147149
the_module = importlib.import_module(abstest)
148150
# If the test has a test_main, that will run the appropriate
@@ -162,24 +164,28 @@ def test_runner():
162164
refleak = dash_R(the_module, test, test_runner, huntrleaks)
163165
test_time = time.time() - start_time
164166
except support.ResourceDenied as msg:
165-
if not quiet:
167+
if not quiet and not pgo:
166168
print(test, "skipped --", msg, flush=True)
167169
return RESOURCE_DENIED, test_time
168170
except unittest.SkipTest as msg:
169-
if not quiet:
171+
if not quiet and not pgo:
170172
print(test, "skipped --", msg, flush=True)
171173
return SKIPPED, test_time
172174
except KeyboardInterrupt:
173175
raise
174176
except support.TestFailed as msg:
175-
if display_failure:
176-
print("test", test, "failed --", msg, file=sys.stderr, flush=True)
177-
else:
178-
print("test", test, "failed", file=sys.stderr, flush=True)
177+
if not pgo:
178+
if display_failure:
179+
print("test", test, "failed --", msg, file=sys.stderr,
180+
flush=True)
181+
else:
182+
print("test", test, "failed", file=sys.stderr, flush=True)
179183
return FAILED, test_time
180184
except:
181185
msg = traceback.format_exc()
182-
print("test", test, "crashed --", msg, file=sys.stderr, flush=True)
186+
if not pgo:
187+
print("test", test, "crashed --", msg, file=sys.stderr,
188+
flush=True)
183189
return FAILED, test_time
184190
else:
185191
if refleak:

Lib/test/libregrtest/runtest_mp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def run_test_in_subprocess(testname, ns):
4242
'-X', 'faulthandler',
4343
'-m', 'test.regrtest',
4444
'--slaveargs', slaveargs]
45+
if ns.pgo:
46+
cmd += ['--pgo']
4547

4648
# Running the child from the same working directory as regrtest's original
4749
# invocation ensures that TEMPDIR for the child is the same when
@@ -175,7 +177,7 @@ def get_running(workers):
175177
item = output.get(timeout=timeout)
176178
except queue.Empty:
177179
running = get_running(workers)
178-
if running:
180+
if running and not regrtest.ns.pgo:
179181
print('running: %s' % ', '.join(running))
180182
continue
181183

@@ -189,17 +191,18 @@ def get_running(workers):
189191
text = test
190192
ok, test_time = result
191193
if (ok not in (CHILD_ERROR, INTERRUPTED)
192-
and test_time >= PROGRESS_MIN_TIME):
194+
and test_time >= PROGRESS_MIN_TIME
195+
and not regrtest.ns.pgo):
193196
text += ' (%.0f sec)' % test_time
194197
running = get_running(workers)
195-
if running:
198+
if running and not regrtest.ns.pgo:
196199
text += ' -- running: %s' % ', '.join(running)
197200
regrtest.display_progress(test_index, text)
198201

199202
# Copy stdout and stderr from the child process
200203
if stdout:
201204
print(stdout, flush=True)
202-
if stderr:
205+
if stderr and not regrtest.ns.pgo:
203206
print(stderr, file=sys.stderr, flush=True)
204207

205208
if result[0] == INTERRUPTED:

Lib/test/libregrtest/save_env.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class saved_test_environment:
4141

4242
changed = False
4343

44-
def __init__(self, testname, verbose=0, quiet=False):
44+
def __init__(self, testname, verbose=0, quiet=False, *, pgo=False):
4545
self.testname = testname
4646
self.verbose = verbose
4747
self.quiet = quiet
48+
self.pgo = pgo
4849

4950
# To add things to save and restore, add a name XXX to the resources list
5051
# and add corresponding get_XXX/restore_XXX functions. get_XXX should
@@ -273,7 +274,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
273274
if current != original:
274275
self.changed = True
275276
restore(original)
276-
if not self.quiet:
277+
if not self.quiet and not self.pgo:
277278
print("Warning -- {} was modified by {}".format(
278279
name, self.testname),
279280
file=sys.stderr)

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ TCLTK_INCLUDES= @TCLTK_INCLUDES@
231231
TCLTK_LIBS= @TCLTK_LIBS@
232232

233233
# The task to run while instrument when building the profile-opt target
234-
PROFILE_TASK=-m test.regrtest >/dev/null 2>&1
234+
PROFILE_TASK=-m test.regrtest --pgo
235235

236236
# report files for gcov / lcov coverage report
237237
COVERAGE_INFO= $(abs_builddir)/coverage.info

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ Documentation
170170
Tests
171171
-----
172172

173+
- Issue #25188: Add -P/--pgo to test.regrtest to suppress error output when
174+
running the test suite for the purposes of a PGO build. Initial patch by
175+
Alecsandru Patrascu.
176+
173177
- Issue #22806: Add ``python -m test --list-tests`` command to list tests.
174178

175179
- Issue #18174: ``python -m test --huntrleaks ...`` now also checks for leak of

0 commit comments

Comments
 (0)