Blame SOURCES/00333-reduce-pgo-tests.patch

b7e076
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py
b7e076
index 538ff05..e7f2013 100644
b7e076
--- a/Lib/test/libregrtest/cmdline.py
b7e076
+++ b/Lib/test/libregrtest/cmdline.py
b7e076
@@ -263,7 +263,9 @@ def _create_parser():
b7e076
                        help='only write the name of test cases that will be run'
b7e076
                             ' , don\'t execute them')
b7e076
     group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
b7e076
-                       help='enable Profile Guided Optimization training')
b7e076
+                       help='enable Profile Guided Optimization (PGO) training')
b7e076
+    group.add_argument('--pgo-extended', action='store_true',
b7e076
+                       help='enable extended PGO training (slower training)')
b7e076
     group.add_argument('--fail-env-changed', action='store_true',
b7e076
                        help='if a test file alters the environment, mark '
b7e076
                             'the test as failed')
b7e076
@@ -339,6 +341,8 @@ def _parse_args(args, **kwargs):
b7e076
         parser.error("-G/--failfast needs either -v or -W")
b7e076
     if ns.pgo and (ns.verbose or ns.verbose2 or ns.verbose3):
b7e076
         parser.error("--pgo/-v don't go together!")
b7e076
+    if ns.pgo_extended:
b7e076
+        ns.pgo = True  # pgo_extended implies pgo
b7e076
 
b7e076
     if ns.nowindows:
b7e076
         print("Warning: the --nowindows (-n) option is deprecated. "
b7e076
diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py
b7e076
index b6d05f6..524dbfa 100644
b7e076
--- a/Lib/test/libregrtest/main.py
b7e076
+++ b/Lib/test/libregrtest/main.py
b7e076
@@ -17,6 +17,7 @@ from test.libregrtest.runtest import (
b7e076
     INTERRUPTED, CHILD_ERROR, TEST_DID_NOT_RUN,
b7e076
     PROGRESS_MIN_TIME, format_test_result)
b7e076
 from test.libregrtest.setup import setup_tests
b7e076
+from test.libregrtest.pgo import setup_pgo_tests
b7e076
 from test.libregrtest.utils import removepy, count, format_duration, printlist
b7e076
 from test import support
b7e076
 try:
b7e076
@@ -214,6 +215,10 @@ class Regrtest:
b7e076
 
b7e076
         removepy(self.tests)
b7e076
 
b7e076
+        if self.ns.pgo:
b7e076
+            # add default PGO tests if no tests are specified
b7e076
+            setup_pgo_tests(self.ns)
b7e076
+
b7e076
         stdtests = STDTESTS[:]
b7e076
         nottests = NOTTESTS.copy()
b7e076
         if self.ns.exclude:
b7e076
@@ -601,6 +606,7 @@ class Regrtest:
b7e076
             input("Press any key to continue...")
b7e076
 
b7e076
         support.PGO = self.ns.pgo
b7e076
+        support.PGO_EXTENDED = self.ns.pgo_extended
b7e076
 
b7e076
         setup_tests(self.ns)
b7e076
 
b7e076
diff --git a/Lib/test/libregrtest/pgo.py b/Lib/test/libregrtest/pgo.py
b7e076
new file mode 100644
b7e076
index 0000000..379ff05
b7e076
--- /dev/null
b7e076
+++ b/Lib/test/libregrtest/pgo.py
b7e076
@@ -0,0 +1,55 @@
b7e076
+# Set of tests run by default if --pgo is specified.  The tests below were
b7e076
+# chosen based on the following criteria: either they exercise a commonly used
b7e076
+# C extension module or type, or they run some relatively typical Python code.
b7e076
+# Long running tests should be avoided because the PGO instrumented executable
b7e076
+# runs slowly.
b7e076
+PGO_TESTS = [
b7e076
+    'test_array',
b7e076
+    'test_base64',
b7e076
+    'test_binascii',
b7e076
+    'test_binop',
b7e076
+    'test_bisect',
b7e076
+    'test_bytes',
b7e076
+    'test_bz2',
b7e076
+    'test_cmath',
b7e076
+    'test_codecs',
b7e076
+    'test_collections',
b7e076
+    'test_complex',
b7e076
+    'test_dataclasses',
b7e076
+    'test_datetime',
b7e076
+    'test_decimal',
b7e076
+    'test_difflib',
b7e076
+    'test_embed',
b7e076
+    'test_float',
b7e076
+    'test_fstring',
b7e076
+    'test_functools',
b7e076
+    'test_generators',
b7e076
+    'test_hashlib',
b7e076
+    'test_heapq',
b7e076
+    'test_int',
b7e076
+    'test_itertools',
b7e076
+    'test_json',
b7e076
+    'test_long',
b7e076
+    'test_lzma',
b7e076
+    'test_math',
b7e076
+    'test_memoryview',
b7e076
+    'test_operator',
b7e076
+    'test_ordered_dict',
b7e076
+    'test_pickle',
b7e076
+    'test_pprint',
b7e076
+    'test_re',
b7e076
+    'test_set',
b7e076
+    'test_sqlite',
b7e076
+    'test_statistics',
b7e076
+    'test_struct',
b7e076
+    'test_tabnanny',
b7e076
+    'test_time',
b7e076
+    'test_unicode',
b7e076
+    'test_xml_etree',
b7e076
+    'test_xml_etree_c',
b7e076
+]
b7e076
+
b7e076
+def setup_pgo_tests(ns):
b7e076
+    if not ns.args and not ns.pgo_extended:
b7e076
+        # run default set of tests for PGO training
b7e076
+        ns.args = PGO_TESTS[:]
b7e076
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
b7e076
index 764057a..468ee46 100644
b7e076
--- a/Lib/test/pickletester.py
b7e076
+++ b/Lib/test/pickletester.py
b7e076
@@ -2039,6 +2039,7 @@ class AbstractPickleTests(unittest.TestCase):
b7e076
 
b7e076
     FRAME_SIZE_TARGET = 64 * 1024
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     def check_frame_opcodes(self, pickled):
b7e076
         """
b7e076
         Check the arguments of FRAME opcodes in a protocol 4+ pickle.
b7e076
@@ -2059,6 +2060,7 @@ class AbstractPickleTests(unittest.TestCase):
b7e076
         frame_size = len(pickled) - last_pos - frame_opcode_size
b7e076
         self.assertEqual(frame_size, last_arg)
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     def test_framing_many_objects(self):
b7e076
         obj = list(range(10**5))
b7e076
         for proto in range(4, pickle.HIGHEST_PROTOCOL + 1):
b7e076
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
b7e076
index 66c0fed..e80a819 100644
b7e076
--- a/Lib/test/support/__init__.py
b7e076
+++ b/Lib/test/support/__init__.py
b7e076
@@ -953,6 +953,10 @@ SAVEDCWD = os.getcwd()
b7e076
 # useful for PGO
b7e076
 PGO = False
b7e076
 
b7e076
+# Set by libregrtest/main.py if we are running the extended (time consuming)
b7e076
+# PGO task.  If this is True, PGO is also True.
b7e076
+PGO_EXTENDED = False
b7e076
+
b7e076
 @contextlib.contextmanager
b7e076
 def temp_dir(path=None, quiet=False):
b7e076
     """Return a context manager that creates a temporary directory.
b7e076
@@ -2442,6 +2446,11 @@ def skip_unless_xattr(test):
b7e076
     msg = "no non-broken extended attribute support"
b7e076
     return test if ok else unittest.skip(msg)(test)
b7e076
 
b7e076
+def skip_if_pgo_task(test):
b7e076
+    """Skip decorator for tests not run in (non-extended) PGO task"""
b7e076
+    ok = not PGO or PGO_EXTENDED
b7e076
+    msg = "Not run for (non-extended) PGO task"
b7e076
+    return test if ok else unittest.skip(msg)(test)
b7e076
 
b7e076
 def fs_is_case_insensitive(directory):
b7e076
     """Detects if the file system for the specified directory is case-insensitive."""
b7e076
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
b7e076
index f340f23..ebb151c 100644
b7e076
--- a/Lib/test/test_bz2.py
b7e076
+++ b/Lib/test/test_bz2.py
b7e076
@@ -654,6 +654,7 @@ class BZ2CompressorTest(BaseTest):
b7e076
         data += bz2c.flush()
b7e076
         self.assertEqual(ext_decompress(data), self.TEXT)
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     @bigmemtest(size=_4G + 100, memuse=2)
b7e076
     def testCompress4G(self, size):
b7e076
         # "Test BZ2Compressor.compress()/flush() with >4GiB input"
b7e076
@@ -712,6 +713,7 @@ class BZ2DecompressorTest(BaseTest):
b7e076
         self.assertRaises(EOFError, bz2d.decompress, b"anything")
b7e076
         self.assertRaises(EOFError, bz2d.decompress, b"")
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     @bigmemtest(size=_4G + 100, memuse=3.3)
b7e076
     def testDecompress4G(self, size):
b7e076
         # "Test BZ2Decompressor.decompress() with >4GiB input"
b7e076
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
b7e076
index 9317951..8c1d016 100644
b7e076
--- a/Lib/test/test_itertools.py
b7e076
+++ b/Lib/test/test_itertools.py
b7e076
@@ -2023,6 +2023,7 @@ class RegressionTests(unittest.TestCase):
b7e076
         self.assertRaises(AssertionError, list, cycle(gen1()))
b7e076
         self.assertEqual(hist, [0,1])
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     def test_long_chain_of_empty_iterables(self):
b7e076
         # Make sure itertools.chain doesn't run into recursion limits when
b7e076
         # dealing with long chains of empty iterables. Even with a high
b7e076
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
b7e076
index 3dc2c1e..117de0a 100644
b7e076
--- a/Lib/test/test_lzma.py
b7e076
+++ b/Lib/test/test_lzma.py
b7e076
@@ -333,6 +333,7 @@ class CompressorDecompressorTestCase(unittest.TestCase):
b7e076
 
b7e076
     # Test with inputs larger than 4GiB.
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     @bigmemtest(size=_4G + 100, memuse=2)
b7e076
     def test_compressor_bigmem(self, size):
b7e076
         lzc = LZMACompressor()
b7e076
@@ -344,6 +345,7 @@ class CompressorDecompressorTestCase(unittest.TestCase):
b7e076
         finally:
b7e076
             ddata = None
b7e076
 
b7e076
+    @support.skip_if_pgo_task
b7e076
     @bigmemtest(size=_4G + 100, memuse=3)
b7e076
     def test_decompressor_bigmem(self, size):
b7e076
         lzd = LZMADecompressor()
b7e076
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
b7e076
index 5347bb1..9d83217 100644
b7e076
--- a/Lib/test/test_regrtest.py
b7e076
+++ b/Lib/test/test_regrtest.py
b7e076
@@ -6,6 +6,7 @@ Note: test_regrtest cannot be run twice in parallel.
b7e076
 
b7e076
 import contextlib
b7e076
 import faulthandler
b7e076
+import glob
b7e076
 import io
b7e076
 import os.path
b7e076
 import platform
b7e076
@@ -532,6 +533,31 @@ class BaseTestCase(unittest.TestCase):
b7e076
         return proc.stdout
b7e076
 
b7e076
 
b7e076
+class CheckActualTests(BaseTestCase):
b7e076
+    """
b7e076
+    Check that regrtest appears to find the expected set of tests.
b7e076
+    """
b7e076
+
b7e076
+    def test_finds_expected_number_of_tests(self):
b7e076
+        args = ['-Wd', '-E', '-bb', '-m', 'test.regrtest', '--list-tests']
b7e076
+        output = self.run_python(args)
b7e076
+        rough_number_of_tests_found = len(output.splitlines())
b7e076
+        actual_testsuite_glob = os.path.join(os.path.dirname(__file__),
b7e076
+                                             'test*.py')
b7e076
+        rough_counted_test_py_files = len(glob.glob(actual_testsuite_glob))
b7e076
+        # We're not trying to duplicate test finding logic in here,
b7e076
+        # just give a rough estimate of how many there should be and
b7e076
+        # be near that.  This is a regression test to prevent mishaps
b7e076
+        # such as https://bugs.python.org/issue37667 in the future.
b7e076
+        # If you need to change the values in here during some
b7e076
+        # mythical future test suite reorganization, don't go
b7e076
+        # overboard with logic and keep that goal in mind.
b7e076
+        self.assertGreater(rough_number_of_tests_found,
b7e076
+                           rough_counted_test_py_files*9//10,
b7e076
+                           msg='Unexpectedly low number of tests found in:\n'
b7e076
+                           f'{", ".join(output.splitlines())}')
b7e076
+
b7e076
+
b7e076
 class ProgramsTestCase(BaseTestCase):
b7e076
     """
b7e076
     Test various ways to run the Python test suite. Use options close
b7e076
diff --git a/Makefile.pre.in b/Makefile.pre.in
b7e076
index b452289..cc428ac 100644
b7e076
--- a/Makefile.pre.in
b7e076
+++ b/Makefile.pre.in
b7e076
@@ -247,9 +247,10 @@ TCLTK_INCLUDES=	@TCLTK_INCLUDES@
b7e076
 TCLTK_LIBS=	@TCLTK_LIBS@
b7e076
 
b7e076
 # The task to run while instrumented when building the profile-opt target.
b7e076
-# We exclude unittests with -x that take a rediculious amount of time to
b7e076
-# run in the instrumented training build or do not provide much value.
b7e076
-PROFILE_TASK=-m test.regrtest --pgo
b7e076
+# To speed up profile generation, we don't run the full unit test suite
b7e076
+# by default. The default is "-m test --pgo". To run more tests, use
b7e076
+# PROFILE_TASK="-m test --pgo-extended"
b7e076
+PROFILE_TASK=	@PROFILE_TASK@
b7e076
 
b7e076
 # report files for gcov / lcov coverage report
b7e076
 COVERAGE_INFO=	$(abs_builddir)/coverage.info
b7e076
diff --git a/configure.ac b/configure.ac
b7e076
index c071ec3..816fc5a 100644
b7e076
--- a/configure.ac
b7e076
+++ b/configure.ac
b7e076
@@ -1308,6 +1308,14 @@ else
b7e076
   DEF_MAKE_RULE="all"
b7e076
 fi
b7e076
 
b7e076
+AC_ARG_VAR(PROFILE_TASK, Python args for PGO generation task)
b7e076
+AC_MSG_CHECKING(PROFILE_TASK)
b7e076
+if test -z "$PROFILE_TASK"
b7e076
+then
b7e076
+	PROFILE_TASK='-m test --pgo'
b7e076
+fi
b7e076
+AC_MSG_RESULT($PROFILE_TASK)
b7e076
+
b7e076
 # Make llvm-relatec checks work on systems where llvm tools are not installed with their
b7e076
 # normal names in the default $PATH (ie: Ubuntu).  They exist under the
b7e076
 # non-suffixed name in their versioned llvm directory.