11cb0ef41Sopenharmony_ci#!/usr/bin/env python3
21cb0ef41Sopenharmony_ci# Copyright 2016 the V8 project authors. All rights reserved.
31cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be
41cb0ef41Sopenharmony_ci# found in the LICENSE file.
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciimport itertools
71cb0ef41Sopenharmony_ciimport os
81cb0ef41Sopenharmony_ciimport sys
91cb0ef41Sopenharmony_ciimport tempfile
101cb0ef41Sopenharmony_ciimport unittest
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci# Needed because the test runner contains relative imports.
131cb0ef41Sopenharmony_ciTOOLS_PATH = os.path.dirname(
141cb0ef41Sopenharmony_ci    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
151cb0ef41Sopenharmony_cisys.path.append(TOOLS_PATH)
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifrom testrunner.local.testsuite import TestSuite, TestGenerator
181cb0ef41Sopenharmony_cifrom testrunner.objects.testcase import TestCase
191cb0ef41Sopenharmony_cifrom testrunner.test_config import TestConfig
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ciclass TestSuiteTest(unittest.TestCase):
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  def setUp(self):
251cb0ef41Sopenharmony_ci    test_dir = os.path.dirname(__file__)
261cb0ef41Sopenharmony_ci    self.test_root = os.path.join(test_dir, "fake_testsuite")
271cb0ef41Sopenharmony_ci    self.test_config = TestConfig(
281cb0ef41Sopenharmony_ci        command_prefix=[],
291cb0ef41Sopenharmony_ci        extra_flags=[],
301cb0ef41Sopenharmony_ci        isolates=False,
311cb0ef41Sopenharmony_ci        mode_flags=[],
321cb0ef41Sopenharmony_ci        no_harness=False,
331cb0ef41Sopenharmony_ci        noi18n=False,
341cb0ef41Sopenharmony_ci        random_seed=0,
351cb0ef41Sopenharmony_ci        run_skipped=False,
361cb0ef41Sopenharmony_ci        shell_dir='fake_testsuite/fake_d8',
371cb0ef41Sopenharmony_ci        timeout=10,
381cb0ef41Sopenharmony_ci        verbose=False,
391cb0ef41Sopenharmony_ci    )
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci    self.suite = TestSuite.Load(self.test_root, self.test_config,
421cb0ef41Sopenharmony_ci                                "standard_runner")
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  def testLoadingTestSuites(self):
451cb0ef41Sopenharmony_ci    self.assertEquals(self.suite.name, "fake_testsuite")
461cb0ef41Sopenharmony_ci    self.assertEquals(self.suite.test_config, self.test_config)
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci    # Verify that the components of the TestSuite aren't loaded yet.
491cb0ef41Sopenharmony_ci    self.assertIsNone(self.suite.tests)
501cb0ef41Sopenharmony_ci    self.assertIsNone(self.suite.statusfile)
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci  def testLoadingTestsFromDisk(self):
531cb0ef41Sopenharmony_ci    tests = self.suite.load_tests_from_disk(statusfile_variables={})
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci    def is_generator(iterator):
561cb0ef41Sopenharmony_ci      return iterator == iter(iterator)
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ci    self.assertTrue(is_generator(tests))
591cb0ef41Sopenharmony_ci    self.assertEquals(tests.test_count_estimate, 2)
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci    slow_tests, fast_tests = list(tests.slow_tests), list(tests.fast_tests)
621cb0ef41Sopenharmony_ci    # Verify that the components of the TestSuite are loaded.
631cb0ef41Sopenharmony_ci    self.assertTrue(len(slow_tests) == len(fast_tests) == 1)
641cb0ef41Sopenharmony_ci    self.assertTrue(all(test.is_slow for test in slow_tests))
651cb0ef41Sopenharmony_ci    self.assertFalse(any(test.is_slow for test in fast_tests))
661cb0ef41Sopenharmony_ci    self.assertIsNotNone(self.suite.statusfile)
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci  def testMergingTestGenerators(self):
691cb0ef41Sopenharmony_ci    tests = self.suite.load_tests_from_disk(statusfile_variables={})
701cb0ef41Sopenharmony_ci    more_tests = self.suite.load_tests_from_disk(statusfile_variables={})
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci    # Merge the test generators
731cb0ef41Sopenharmony_ci    tests.merge(more_tests)
741cb0ef41Sopenharmony_ci    self.assertEquals(tests.test_count_estimate, 4)
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci    # Check the tests are sorted by speed
771cb0ef41Sopenharmony_ci    test_speeds = []
781cb0ef41Sopenharmony_ci    for test in tests:
791cb0ef41Sopenharmony_ci      test_speeds.append(test.is_slow)
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci    self.assertEquals(test_speeds, [True, True, False, False])
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ciif __name__ == '__main__':
851cb0ef41Sopenharmony_ci  unittest.main()
86