2022-04-19 09:00:36 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-09-06 22:49:51 +02:00
|
|
|
# Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
|
2023-10-05 08:46:07 +02:00
|
|
|
from pathlib import Path
|
|
|
|
|
2016-09-06 22:49:51 +02:00
|
|
|
# Needed because the test runner contains relative imports.
|
2023-10-05 08:46:07 +02:00
|
|
|
TOOLS_PATH = Path(__file__).resolve().parents[2]
|
|
|
|
sys.path.append(str(TOOLS_PATH))
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
from testrunner.local.command import PosixCommand
|
|
|
|
from testrunner.local.context import DefaultOSContext
|
|
|
|
from testrunner.local.testsuite import TestSuite
|
2019-03-12 09:01:49 +01:00
|
|
|
from testrunner.test_config import TestConfig
|
2016-09-06 22:49:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestSuiteTest(unittest.TestCase):
|
2022-04-19 09:00:36 +02:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
def setUp(self):
|
2023-10-05 08:46:07 +02:00
|
|
|
test_dir = Path(__file__).resolve().parent
|
|
|
|
self.test_root = test_dir / "fake_testsuite"
|
2019-03-12 09:01:49 +01:00
|
|
|
self.test_config = TestConfig(
|
|
|
|
command_prefix=[],
|
|
|
|
extra_flags=[],
|
2024-03-30 09:54:35 +01:00
|
|
|
extra_d8_flags=[],
|
2023-03-30 12:11:08 +02:00
|
|
|
framework_name='standard_runner',
|
2019-03-12 09:01:49 +01:00
|
|
|
isolates=False,
|
2024-03-30 09:54:35 +01:00
|
|
|
log_process_stats=False,
|
2019-03-12 09:01:49 +01:00
|
|
|
mode_flags=[],
|
|
|
|
no_harness=False,
|
|
|
|
noi18n=False,
|
|
|
|
random_seed=0,
|
|
|
|
run_skipped=False,
|
2023-03-30 12:11:08 +02:00
|
|
|
shard_count=1,
|
|
|
|
shard_id=0,
|
2023-10-05 08:46:07 +02:00
|
|
|
shell_dir=Path('fake_testsuite/fake_d8'),
|
|
|
|
target_os='macos',
|
2019-03-12 09:01:49 +01:00
|
|
|
timeout=10,
|
|
|
|
verbose=False,
|
2016-09-06 22:49:51 +02:00
|
|
|
)
|
|
|
|
|
2022-09-21 13:28:42 +02:00
|
|
|
self.suite = TestSuite.Load(
|
2023-03-30 12:11:08 +02:00
|
|
|
DefaultOSContext(PosixCommand), self.test_root, self.test_config)
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
def testLoadingTestSuites(self):
|
2022-09-21 13:28:42 +02:00
|
|
|
self.assertEqual(self.suite.name, "fake_testsuite")
|
|
|
|
self.assertEqual(self.suite.test_config, self.test_config)
|
2018-03-07 08:54:53 +01:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
# Verify that the components of the TestSuite aren't loaded yet.
|
|
|
|
self.assertIsNone(self.suite.tests)
|
|
|
|
self.assertIsNone(self.suite.statusfile)
|
2018-03-07 08:54:53 +01:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
def testLoadingTestsFromDisk(self):
|
2022-04-19 09:00:36 +02:00
|
|
|
tests = self.suite.load_tests_from_disk(statusfile_variables={})
|
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
def is_generator(iterator):
|
|
|
|
return iterator == iter(iterator)
|
2016-09-06 22:49:51 +02:00
|
|
|
|
2019-03-15 18:35:06 +05:30
|
|
|
self.assertTrue(is_generator(tests))
|
2024-03-30 09:54:35 +01:00
|
|
|
self.assertEqual(tests.test_count_estimate, 3)
|
|
|
|
|
|
|
|
heavy_tests = list(tests.heavy_tests)
|
|
|
|
slow_tests = list(tests.slow_tests)
|
|
|
|
remaining_tests = list(tests.remaining_tests)
|
2018-01-24 20:16:06 +01:00
|
|
|
|
2019-03-12 09:01:49 +01:00
|
|
|
# Verify that the components of the TestSuite are loaded.
|
2024-03-30 09:54:35 +01:00
|
|
|
self.assertTrue(
|
|
|
|
len(heavy_tests) == len(slow_tests) == len(remaining_tests) == 1)
|
|
|
|
self.assertTrue(all(test.is_heavy for test in heavy_tests))
|
2019-03-12 09:01:49 +01:00
|
|
|
self.assertTrue(all(test.is_slow for test in slow_tests))
|
2024-03-30 09:54:35 +01:00
|
|
|
self.assertFalse(any(test.is_heavy for test in remaining_tests))
|
|
|
|
self.assertFalse(any(test.is_slow for test in remaining_tests))
|
2019-03-12 09:01:49 +01:00
|
|
|
self.assertIsNotNone(self.suite.statusfile)
|
2018-01-24 20:16:06 +01:00
|
|
|
|
2019-03-15 18:35:06 +05:30
|
|
|
def testMergingTestGenerators(self):
|
2022-04-19 09:00:36 +02:00
|
|
|
tests = self.suite.load_tests_from_disk(statusfile_variables={})
|
|
|
|
more_tests = self.suite.load_tests_from_disk(statusfile_variables={})
|
2019-03-15 18:35:06 +05:30
|
|
|
|
|
|
|
# Merge the test generators
|
|
|
|
tests.merge(more_tests)
|
2024-03-30 09:54:35 +01:00
|
|
|
self.assertEqual(tests.test_count_estimate, 6)
|
2019-03-15 18:35:06 +05:30
|
|
|
|
2024-03-30 09:54:35 +01:00
|
|
|
# Check the tests are sorted by memory and speed.
|
|
|
|
tests = list(tests)
|
|
|
|
heavy_tests = [test.is_heavy for test in tests]
|
|
|
|
slow_tests = [test.is_slow for test in tests]
|
2019-03-15 18:35:06 +05:30
|
|
|
|
2024-03-30 09:54:35 +01:00
|
|
|
self.assertEqual(heavy_tests, [True, True, False, False, False, False])
|
|
|
|
self.assertEqual(slow_tests, [False, False, True, True, False, False])
|
2019-03-15 18:35:06 +05:30
|
|
|
|
2016-09-06 22:49:51 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-04-19 09:00:36 +02:00
|
|
|
unittest.main()
|