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

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