diff --git a/ci/lint.sh b/ci/lint.sh index ed7ced728409b..c1c4ce8e07816 100755 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -74,6 +74,7 @@ pylint-2.7 --rcfile=.pylintrc \ "build/" \ "ci/" \ "impeller/" \ - "tools/gn" + "tools/gn" \ + "testing/run_tests.py" echo "$(date +%T) Linting complete" diff --git a/testing/run_tests.py b/testing/run_tests.py index acbfa9c0cac61..b3213c8867cb1 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -20,29 +20,29 @@ import csv import xvfb -script_dir = os.path.dirname(os.path.realpath(__file__)) -buildroot_dir = os.path.abspath( +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) +BUILDROOT_DIR = os.path.abspath( os.path.join(os.path.realpath(__file__), '..', '..', '..') ) -out_dir = os.path.join(buildroot_dir, 'out') -golden_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'resources') -fonts_dir = os.path.join( - buildroot_dir, 'flutter', 'third_party', 'txt', 'third_party', 'fonts' +OUT_DIR = os.path.join(BUILDROOT_DIR, 'out') +GOLDEN_DIR = os.path.join(BUILDROOT_DIR, 'flutter', 'testing', 'resources') +FONTS_DIR = os.path.join( + BUILDROOT_DIR, 'flutter', 'third_party', 'txt', 'third_party', 'fonts' ) -roboto_font_path = os.path.join(fonts_dir, 'Roboto-Regular.ttf') -font_subset_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'font-subset') +ROBOTO_FONT_PATH = os.path.join(FONTS_DIR, 'Roboto-Regular.ttf') +FONT_SUBSET_DIR = os.path.join(BUILDROOT_DIR, 'flutter', 'tools', 'font-subset') -fml_unittests_filter = '--gtest_filter=-*TimeSensitiveTest*' +FML_UNITTESTS_FILTER = '--gtest_filter=-*TimeSensitiveTest*' -def PrintDivider(char='='): +def print_divider(char='='): print('\n') for _ in range(4): print(''.join([char for _ in range(80)])) print('\n') -def IsAsan(build_dir): +def is_asan(build_dir): with open(os.path.join(build_dir, 'args.gn')) as args: if 'is_asan = true' in args.read(): return True @@ -50,10 +50,15 @@ def IsAsan(build_dir): return False -def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs): +def run_cmd( + cmd, forbidden_output=None, expect_failure=False, env=None, **kwargs +): + if forbidden_output is None: + forbidden_output = [] + command_string = ' '.join(cmd) - PrintDivider('>') + print_divider('>') print('Running command "%s"' % command_string) start_time = time.time() @@ -71,7 +76,7 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs): end_time = time.time() if process.returncode != 0 and not expect_failure: - PrintDivider('!') + print_divider('!') print( 'Failed Command:\n\n%s\n\nExit Code: %d\n' % @@ -84,7 +89,7 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs): if stderr: print('STDERR: \n%s' % stderr) - PrintDivider('!') + print_divider('!') raise Exception( 'Command "%s" exited with code %d.' % @@ -103,34 +108,34 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs): (command_string, forbidden_string) ) - PrintDivider('<') + print_divider('<') print( 'Command run successfully in %.2f seconds: %s' % (end_time - start_time, command_string) ) -def IsMac(): +def is_mac(): return sys.platform == 'darwin' -def IsLinux(): +def is_linux(): return sys.platform.startswith('linux') -def IsWindows(): +def is_windows(): return sys.platform.startswith(('cygwin', 'win')) -def ExecutableSuffix(): - return '.exe' if IsWindows() else '' +def executable_suffix(): + return '.exe' if is_windows() else '' -def FindExecutablePath(path): +def find_executable_path(path): if os.path.exists(path): return path - if IsWindows(): + if is_windows(): exe_path = path + '.exe' if os.path.exists(exe_path): return exe_path @@ -142,20 +147,23 @@ def FindExecutablePath(path): raise Exception('Executable %s does not exist!' % path) -def BuildEngineExecutableCommand( - build_dir, executable_name, flags=[], coverage=False, gtest=False +def build_engine_executable_command( + build_dir, executable_name, flags=None, coverage=False, gtest=False ): + if flags is None: + flags = [] + unstripped_exe = os.path.join(build_dir, 'exe.unstripped', executable_name) # We cannot run the unstripped binaries directly when coverage is enabled. - if IsLinux() and os.path.exists(unstripped_exe) and not coverage: + if is_linux() and os.path.exists(unstripped_exe) and not coverage: # Use unstripped executables in order to get better symbolized crash # stack traces on Linux. executable = unstripped_exe else: - executable = FindExecutablePath(os.path.join(build_dir, executable_name)) + executable = find_executable_path(os.path.join(build_dir, executable_name)) coverage_script = os.path.join( - buildroot_dir, 'flutter', 'build', 'generate_coverage.py' + BUILDROOT_DIR, 'flutter', 'build', 'generate_coverage.py' ) if coverage: @@ -169,32 +177,39 @@ def BuildEngineExecutableCommand( test_command = [executable] + flags if gtest: gtest_parallel = os.path.join( - buildroot_dir, 'third_party', 'gtest-parallel', 'gtest-parallel' + BUILDROOT_DIR, 'third_party', 'gtest-parallel', 'gtest-parallel' ) test_command = ['python3', gtest_parallel] + test_command return test_command -def RunEngineExecutable( +def run_engine_executable( # pylint: disable=too-many-arguments build_dir, executable_name, - filter, - flags=[], - cwd=buildroot_dir, - forbidden_output=[], + executable_filter, + flags=None, + cwd=BUILDROOT_DIR, + forbidden_output=None, expect_failure=False, coverage=False, - extra_env={}, + extra_env=None, gtest=False ): - if filter is not None and executable_name not in filter: + if executable_filter is not None and executable_name not in executable_filter: print('Skipping %s due to filter.' % executable_name) return + if flags is None: + flags = [] + if forbidden_output is None: + forbidden_output = [] + if extra_env is None: + extra_env = {} + unstripped_exe = os.path.join(build_dir, 'exe.unstripped', executable_name) env = os.environ.copy() - if IsLinux(): + if is_linux(): env['LD_LIBRARY_PATH'] = build_dir env['VK_DRIVER_FILES'] = os.path.join(build_dir, 'vk_swiftshader_icd.json') if os.path.exists(unstripped_exe): @@ -203,19 +218,19 @@ def RunEngineExecutable( os.path.join(build_dir, 'lib.unstripped', 'libvulkan.so.1'), os.path.join(build_dir, 'exe.unstripped', 'libvulkan.so.1') ) - except OSError as e: - if e.errno == errno.EEXIST: + except OSError as err: + if err.errno == errno.EEXIST: pass else: raise - elif IsMac(): + elif is_mac(): env['DYLD_LIBRARY_PATH'] = build_dir else: - env['PATH'] = build_dir + ":" + env['PATH'] + env['PATH'] = build_dir + ':' + env['PATH'] print('Running %s in %s' % (executable_name, cwd)) - test_command = BuildEngineExecutableCommand( + test_command = build_engine_executable_command( build_dir, executable_name, flags=flags, @@ -228,7 +243,7 @@ def RunEngineExecutable( env[key] = value try: - RunCmd( + run_cmd( test_command, cwd=cwd, forbidden_output=forbidden_output, @@ -250,9 +265,9 @@ def RunEngineExecutable( print('Writing core dump analysis to %s' % dump_path) subprocess.call([ os.path.join( - buildroot_dir, 'flutter', 'testing', 'analyze_core_dump.sh' + BUILDROOT_DIR, 'flutter', 'testing', 'analyze_core_dump.sh' ), - buildroot_dir, + BUILDROOT_DIR, unstripped_exe, core_path, dump_path, @@ -261,23 +276,23 @@ def RunEngineExecutable( raise -class EngineExecutableTask(object): +class EngineExecutableTask(): # pylint: disable=too-many-instance-attributes - def __init__( + def __init__( # pylint: disable=too-many-arguments self, build_dir, executable_name, - filter, - flags=[], - cwd=buildroot_dir, - forbidden_output=[], + executable_filter, + flags=None, + cwd=BUILDROOT_DIR, + forbidden_output=None, expect_failure=False, coverage=False, - extra_env={} + extra_env=None, ): self.build_dir = build_dir self.executable_name = executable_name - self.filter = filter + self.executable_filter = executable_filter self.flags = flags self.cwd = cwd self.forbidden_output = forbidden_output @@ -286,10 +301,10 @@ def __init__( self.extra_env = extra_env def __call__(self, *args): - RunEngineExecutable( + run_engine_executable( self.build_dir, self.executable_name, - self.filter, + self.executable_filter, flags=self.flags, cwd=self.cwd, forbidden_output=self.forbidden_output, @@ -299,35 +314,39 @@ def __call__(self, *args): ) def __str__(self): - command = BuildEngineExecutableCommand( + command = build_engine_executable_command( self.build_dir, self.executable_name, flags=self.flags, coverage=self.coverage ) - return " ".join(command) + return ' '.join(command) shuffle_flags = [ - "--gtest_repeat=2", - "--gtest_shuffle", + '--gtest_repeat=2', + '--gtest_shuffle', ] -def RunCCTests(build_dir, filter, coverage, capture_core_dump): - print("Running Engine Unit-tests.") +def run_cc_tests(build_dir, executable_filter, coverage, capture_core_dump): + print('Running Engine Unit-tests.') - if capture_core_dump and IsLinux(): - import resource + if capture_core_dump and is_linux(): + import resource # pylint: disable=import-outside-toplevel resource.setrlimit( resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY) ) repeat_flags = [ - "--repeat=2", + '--repeat=2', ] - def make_test(name, flags=repeat_flags, extra_env={}): + def make_test(name, flags=None, extra_env=None): + if flags is None: + flags = repeat_flags + if extra_env is None: + extra_env = {} return (name, flags, extra_env) unittests = [ @@ -341,7 +360,7 @@ def make_test(name, flags=repeat_flags, extra_env={}): make_test('embedder_a11y_unittests'), make_test('embedder_proctable_unittests'), make_test('embedder_unittests'), - make_test('fml_unittests', flags=[fml_unittests_filter] + repeat_flags), + make_test('fml_unittests', flags=[FML_UNITTESTS_FILTER] + repeat_flags), make_test('no_dart_plugin_registrant_unittests'), make_test('runtime_unittests'), make_test('testing_unittests'), @@ -350,7 +369,7 @@ def make_test(name, flags=repeat_flags, extra_env={}): make_test('ui_unittests', flags=repeat_flags + ['--timeout=90']), ] - if not IsWindows(): + if not is_windows(): unittests += [ # /~https://github.com/google/googletest/issues/2490 make_test('android_external_view_embedder_unittests'), @@ -360,7 +379,7 @@ def make_test(name, flags=repeat_flags, extra_env={}): make_test('shell_unittests'), ] - if IsWindows(): + if is_windows(): unittests += [ # The accessibility library only supports Mac and Windows. make_test('accessibility_unittests'), @@ -369,17 +388,17 @@ def make_test(name, flags=repeat_flags, extra_env={}): ] # These unit-tests are Objective-C and can only run on Darwin. - if IsMac(): + if is_mac(): unittests += [ # The accessibility library only supports Mac and Windows. make_test('accessibility_unittests'), make_test('flutter_channels_unittests'), ] - if IsLinux(): + if is_linux(): flow_flags = [ - '--golden-dir=%s' % golden_dir, - '--font-file=%s' % roboto_font_path, + '--golden-dir=%s' % GOLDEN_DIR, + '--font-file=%s' % ROBOTO_FONT_PATH, ] icu_flags = [ '--icu-data-file-path=%s' % os.path.join(build_dir, 'icudtl.dat') @@ -400,35 +419,36 @@ def make_test(name, flags=repeat_flags, extra_env={}): ] for test, flags, extra_env in unittests: - RunEngineExecutable( + run_engine_executable( build_dir, test, - filter, + executable_filter, flags, coverage=coverage, extra_env=extra_env, gtest=True ) - if IsMac(): + if is_mac(): # flutter_desktop_darwin_unittests uses global state that isn't handled # correctly by gtest-parallel. # /~https://github.com/flutter/flutter/issues/104789 - RunEngineExecutable( + run_engine_executable( build_dir, 'flutter_desktop_darwin_unittests', - filter, + executable_filter, shuffle_flags, coverage=coverage ) # Impeller tests are only supported on macOS for now. - RunEngineExecutable( + run_engine_executable( build_dir, 'impeller_unittests', - filter, + executable_filter, shuffle_flags, coverage=coverage, extra_env={ + # pylint: disable=line-too-long # See https://developer.apple.com/documentation/metal/diagnosing_metal_programming_issues_early?language=objc 'MTL_SHADER_VALIDATION': '1', # Enables all shader validation tests. @@ -442,8 +462,8 @@ def make_test(name, flags=repeat_flags, extra_env={}): ) -def ParseImpellerVulkanFilter(): - test_status_path = os.path.join(script_dir, 'impeller_vulkan_test_status.csv') +def parse_impeller_vulkan_filter(): + test_status_path = os.path.join(SCRIPT_DIR, 'impeller_vulkan_test_status.csv') gtest_filter = '--gtest_filter="' with open(test_status_path, 'r') as csvfile: csvreader = csv.reader(csvfile) @@ -455,38 +475,45 @@ def ParseImpellerVulkanFilter(): return gtest_filter -def RunEngineBenchmarks(build_dir, filter): - print("Running Engine Benchmarks.") +def run_engine_benchmarks(build_dir, executable_filter): + print('Running Engine Benchmarks.') icu_flags = [ '--icu-data-file-path=%s' % os.path.join(build_dir, 'icudtl.dat') ] - RunEngineExecutable(build_dir, 'shell_benchmarks', filter, icu_flags) + run_engine_executable( + build_dir, 'shell_benchmarks', executable_filter, icu_flags + ) - RunEngineExecutable(build_dir, 'fml_benchmarks', filter, icu_flags) + run_engine_executable( + build_dir, 'fml_benchmarks', executable_filter, icu_flags + ) - RunEngineExecutable(build_dir, 'ui_benchmarks', filter, icu_flags) + run_engine_executable( + build_dir, 'ui_benchmarks', executable_filter, icu_flags + ) - RunEngineExecutable( - build_dir, 'display_list_builder_benchmarks', filter, icu_flags + run_engine_executable( + build_dir, 'display_list_builder_benchmarks', executable_filter, icu_flags ) - RunEngineExecutable(build_dir, 'geometry_benchmarks', filter, icu_flags) + run_engine_executable( + build_dir, 'geometry_benchmarks', executable_filter, icu_flags + ) - if IsLinux(): - RunEngineExecutable(build_dir, 'txt_benchmarks', filter, icu_flags) + if is_linux(): + run_engine_executable( + build_dir, 'txt_benchmarks', executable_filter, icu_flags + ) -def GatherDartTest( +def gather_dart_test( build_dir, - test_packages, dart_file, - verbose_dart_snapshot, multithreaded, enable_observatory=False, expect_failure=False, - alternative_tester=False ): kernel_file_name = os.path.basename(dart_file) + '.dill' kernel_file_output = os.path.join(build_dir, 'gen', kernel_file_name) @@ -501,7 +528,7 @@ def GatherDartTest( dart_file_contents = open(dart_file, 'r') custom_options = re.findall( - "// FlutterTesterOptions=(.*)", dart_file_contents.read() + '// FlutterTesterOptions=(.*)', dart_file_contents.read() ) dart_file_contents.close() command_args.extend(custom_options) @@ -539,79 +566,78 @@ def GatherDartTest( ) -def EnsureDebugUnoptSkyPackagesAreBuilt(): - variant_out_dir = os.path.join(out_dir, 'host_debug_unopt') +def ensure_debug_unopt_sky_packages(): + variant_out_dir = os.path.join(OUT_DIR, 'host_debug_unopt') message = [] message.append('gn --runtime-mode debug --unopt --no-lto') message.append('ninja -C %s flutter/sky/packages' % variant_out_dir) - final_message = '%s doesn\'t exist. Please run the following commands: \n%s' % ( + final_message = "%s doesn't exist. Please run the following commands: \n%s" % ( variant_out_dir, '\n'.join(message) ) assert os.path.exists(variant_out_dir), final_message -def EnsureIosTestsAreBuilt(ios_out_dir): +def ensure_ios_tests_are_built(ios_out_dir): """Builds the engine variant and the test dylib containing the XCTests""" - tmp_out_dir = os.path.join(out_dir, ios_out_dir) + tmp_out_dir = os.path.join(OUT_DIR, ios_out_dir) ios_test_lib = os.path.join(tmp_out_dir, 'libios_test_flutter.dylib') message = [] message.append( 'gn --ios --unoptimized --runtime-mode=debug --no-lto --simulator' ) message.append('autoninja -C %s ios_test_flutter' % ios_out_dir) - final_message = '%s or %s doesn\'t exist. Please run the following commands: \n%s' % ( + final_message = "%s or %s doesn't exist. Please run the following commands: \n%s" % ( ios_out_dir, ios_test_lib, '\n'.join(message) ) assert os.path.exists(tmp_out_dir ) and os.path.exists(ios_test_lib), final_message -def AssertExpectedXcodeVersion(): +def assert_expected_xcode_version(): """Checks that the user has a version of Xcode installed""" version_output = subprocess.check_output(['xcodebuild', '-version']) - match = re.match(b"Xcode (\d+)", version_output) - message = "Xcode must be installed to run the iOS embedding unit tests" + match = re.match(r'Xcode (\d+)', version_output) + message = 'Xcode must be installed to run the iOS embedding unit tests' assert match, message -def JavaHome(): +def java_home(): script_path = os.path.dirname(os.path.realpath(__file__)) - if IsMac(): + if is_mac(): return os.path.join( script_path, '..', '..', 'third_party', 'java', 'openjdk', 'Contents', 'Home' ) - else: - return os.path.join( - script_path, '..', '..', 'third_party', 'java', 'openjdk' - ) + return os.path.join(script_path, '..', '..', 'third_party', 'java', 'openjdk') -def JavaBin(): - return os.path.join(JavaHome(), 'bin', 'java.exe' if IsWindows() else 'java') +def java_bin(): + return os.path.join( + java_home(), 'bin', 'java.exe' if is_windows() else 'java' + ) -def RunJavaTests(filter, android_variant='android_debug_unopt'): +def run_java_tests(executable_filter, android_variant='android_debug_unopt'): """Runs the Java JUnit unit tests for the Android embedding""" test_runner_dir = os.path.join( - buildroot_dir, 'flutter', 'shell', 'platform', 'android', 'test_runner' + BUILDROOT_DIR, 'flutter', 'shell', 'platform', 'android', 'test_runner' ) gradle_bin = os.path.join( - buildroot_dir, 'third_party', 'gradle', 'bin', - 'gradle.bat' if IsWindows() else 'gradle' + BUILDROOT_DIR, 'third_party', 'gradle', 'bin', + 'gradle.bat' if is_windows() else 'gradle' ) - flutter_jar = os.path.join(out_dir, android_variant, 'flutter.jar') + flutter_jar = os.path.join(OUT_DIR, android_variant, 'flutter.jar') android_home = os.path.join( - buildroot_dir, 'third_party', 'android_tools', 'sdk' + BUILDROOT_DIR, 'third_party', 'android_tools', 'sdk' ) build_dir = os.path.join( - out_dir, android_variant, 'robolectric_tests', 'build' + OUT_DIR, android_variant, 'robolectric_tests', 'build' ) gradle_cache_dir = os.path.join( - out_dir, android_variant, 'robolectric_tests', '.gradle' + OUT_DIR, android_variant, 'robolectric_tests', '.gradle' ) - test_class = filter if filter else '*' + test_class = executable_filter if executable_filter else '*' command = [ gradle_bin, '-Pflutter_jar=%s' % flutter_jar, @@ -624,44 +650,44 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'): '--gradle-user-home=%s' % gradle_cache_dir, ] - env = dict(os.environ, ANDROID_HOME=android_home, JAVA_HOME=JavaHome()) - RunCmd(command, cwd=test_runner_dir, env=env) + env = dict(os.environ, ANDROID_HOME=android_home, JAVA_HOME=java_home()) + run_cmd(command, cwd=test_runner_dir, env=env) -def RunAndroidTests(android_variant='android_debug_unopt', adb_path=None): +def run_android_tests(android_variant='android_debug_unopt', adb_path=None): test_runner_name = 'flutter_shell_native_unittests' - tests_path = os.path.join(out_dir, android_variant, test_runner_name) + tests_path = os.path.join(OUT_DIR, android_variant, test_runner_name) remote_path = '/data/local/tmp' remote_tests_path = os.path.join(remote_path, test_runner_name) - if adb_path == None: + if adb_path is None: adb_path = 'adb' - RunCmd([adb_path, 'push', tests_path, remote_path], cwd=buildroot_dir) - RunCmd([adb_path, 'shell', remote_tests_path]) + run_cmd([adb_path, 'push', tests_path, remote_path], cwd=BUILDROOT_DIR) + run_cmd([adb_path, 'shell', remote_tests_path]) systrace_test = os.path.join( - buildroot_dir, 'flutter', 'testing', 'android_systrace_test.py' + BUILDROOT_DIR, 'flutter', 'testing', 'android_systrace_test.py' ) scenario_apk = os.path.join( - out_dir, android_variant, 'firebase_apks', 'scenario_app.apk' + OUT_DIR, android_variant, 'firebase_apks', 'scenario_app.apk' ) - RunCmd([ + run_cmd([ systrace_test, '--adb-path', adb_path, '--apk-path', scenario_apk, '--package-name', 'dev.flutter.scenarios', '--activity-name', '.PlatformViewsActivity' ]) -def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None): +def run_objc_tests(ios_variant='ios_debug_sim_unopt', test_filter=None): """Runs Objective-C XCTest unit tests for the iOS embedding""" - AssertExpectedXcodeVersion() - ios_out_dir = os.path.join(out_dir, ios_variant) - EnsureIosTestsAreBuilt(ios_out_dir) + assert_expected_xcode_version() + ios_out_dir = os.path.join(OUT_DIR, ios_variant) + ensure_ios_tests_are_built(ios_out_dir) new_simulator_name = 'IosUnitTestsSimulator' # Delete simulators with this name in case any were leaked # from another test run. - DeleteSimulator(new_simulator_name) + delete_simulator(new_simulator_name) create_simulator = [ 'xcrun ' @@ -669,11 +695,11 @@ def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None): 'create ' '%s com.apple.CoreSimulator.SimDeviceType.iPhone-11' % new_simulator_name ] - RunCmd(create_simulator, shell=True) + run_cmd(create_simulator, shell=True) try: ios_unit_test_dir = os.path.join( - buildroot_dir, 'flutter', 'testing', 'ios', 'IosUnitTests' + BUILDROOT_DIR, 'flutter', 'testing', 'ios', 'IosUnitTests' ) # Avoid using xcpretty unless the following can be addressed: # - Make sure all relevant failure output is printed on a failure. @@ -687,28 +713,28 @@ def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None): 'test ' 'FLUTTER_ENGINE=' + ios_variant ] - if test_filter != None: - test_command[0] = test_command[0] + " -only-testing:%s" % test_filter - RunCmd(test_command, cwd=ios_unit_test_dir, shell=True) + if test_filter is not None: + test_command[0] = test_command[0] + ' -only-testing:%s' % test_filter + run_cmd(test_command, cwd=ios_unit_test_dir, shell=True) finally: - DeleteSimulator(new_simulator_name) + delete_simulator(new_simulator_name) -def DeleteSimulator(simulator_name): +def delete_simulator(simulator_name): # Will delete all simulators with this name. - delete_simulator = [ + command = [ 'xcrun', 'simctl', 'delete', simulator_name, ] # Let this fail if the simulator was never created. - RunCmd(delete_simulator, expect_failure=True) + run_cmd(command, expect_failure=True) -def GatherDartTests(build_dir, filter, verbose_dart_snapshot): +def gather_dart_tests(build_dir, test_filter): dart_tests_dir = os.path.join( - buildroot_dir, + BUILDROOT_DIR, 'flutter', 'testing', 'dart', @@ -717,10 +743,10 @@ def GatherDartTests(build_dir, filter, verbose_dart_snapshot): # This one is a bit messy. The pubspec.yaml at flutter/testing/dart/pubspec.yaml # has dependencies that are hardcoded to point to the sky packages at host_debug_unopt/ # Before running Dart tests, make sure to run just that target (NOT the whole engine) - EnsureDebugUnoptSkyPackagesAreBuilt() + ensure_debug_unopt_sky_packages() # Now that we have the Sky packages at the hardcoded location, run `dart pub get`. - RunEngineExecutable( + run_engine_executable( build_dir, os.path.join('dart-sdk', 'bin', 'dart'), None, @@ -732,69 +758,40 @@ def GatherDartTests(build_dir, filter, verbose_dart_snapshot): '%s/observatory/*_test.dart' % dart_tests_dir ) dart_tests = glob.glob('%s/*_test.dart' % dart_tests_dir) - test_packages = os.path.join( - dart_tests_dir, '.dart_tool', 'package_config.json' - ) if 'release' not in build_dir: for dart_test_file in dart_observatory_tests: - if filter is not None and os.path.basename(dart_test_file) not in filter: + if test_filter is not None and os.path.basename(dart_test_file + ) not in test_filter: print("Skipping '%s' due to filter." % dart_test_file) else: print( "Gathering dart test '%s' with observatory enabled" % dart_test_file ) - yield GatherDartTest( - build_dir, test_packages, dart_test_file, verbose_dart_snapshot, - True, True - ) - yield GatherDartTest( - build_dir, test_packages, dart_test_file, verbose_dart_snapshot, - False, True - ) + yield gather_dart_test(build_dir, dart_test_file, True, True) + yield gather_dart_test(build_dir, dart_test_file, False, True) for dart_test_file in dart_tests: - if filter is not None and os.path.basename(dart_test_file) not in filter: + if test_filter is not None and os.path.basename(dart_test_file + ) not in test_filter: print("Skipping '%s' due to filter." % dart_test_file) else: print("Gathering dart test '%s'" % dart_test_file) - yield GatherDartTest( - build_dir, test_packages, dart_test_file, verbose_dart_snapshot, True - ) - yield GatherDartTest( - build_dir, test_packages, dart_test_file, verbose_dart_snapshot, False - ) + yield gather_dart_test(build_dir, dart_test_file, True) + yield gather_dart_test(build_dir, dart_test_file, False) -def GatherDartSmokeTest(build_dir, verbose_dart_snapshot): +def gather_dart_smoke_test(build_dir): smoke_test = os.path.join( - buildroot_dir, "flutter", "testing", "smoke_test_failure", - "fail_test.dart" - ) - test_packages = os.path.join( - buildroot_dir, "flutter", "testing", "smoke_test_failure", ".dart_tool", - "package_config.json" - ) - yield GatherDartTest( - build_dir, - test_packages, - smoke_test, - verbose_dart_snapshot, - True, - expect_failure=True - ) - yield GatherDartTest( - build_dir, - test_packages, - smoke_test, - verbose_dart_snapshot, - False, - expect_failure=True + BUILDROOT_DIR, 'flutter', 'testing', 'smoke_test_failure', + 'fail_test.dart' ) + yield gather_dart_test(build_dir, smoke_test, True, expect_failure=True) + yield gather_dart_test(build_dir, smoke_test, False, expect_failure=True) -def GatherFrontEndServerTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'flutter_frontend_server') +def gather_front_end_server_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'flutter_frontend_server') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = [ @@ -811,13 +808,13 @@ def GatherFrontEndServerTests(build_dir): ) -def GatherPathOpsTests(build_dir): +def gather_path_ops_tests(build_dir): # TODO(dnfield): /~https://github.com/flutter/flutter/issues/107321 - if IsAsan(build_dir): + if is_asan(build_dir): return test_dir = os.path.join( - buildroot_dir, 'flutter', 'tools', 'path_ops', 'dart', 'test' + BUILDROOT_DIR, 'flutter', 'tools', 'path_ops', 'dart', 'test' ) opts = ['--disable-dart-dev', os.path.join(test_dir, 'path_ops_test.dart')] yield EngineExecutableTask( @@ -829,9 +826,9 @@ def GatherPathOpsTests(build_dir): ) -def GatherConstFinderTests(build_dir): +def gather_const_finder_tests(build_dir): test_dir = os.path.join( - buildroot_dir, 'flutter', 'tools', 'const_finder', 'test' + BUILDROOT_DIR, 'flutter', 'tools', 'const_finder', 'test' ) opts = [ '--disable-dart-dev', @@ -849,8 +846,8 @@ def GatherConstFinderTests(build_dir): ) -def GatherLitetestTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'litetest') +def gather_litetest_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'testing', 'litetest') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = ['--disable-dart-dev', dart_test_file] @@ -863,12 +860,12 @@ def GatherLitetestTests(build_dir): ) -def RunBenchmarkTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'testing', 'benchmark') +def run_benchmark_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'testing', 'benchmark') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = ['--disable-dart-dev', dart_test_file] - RunEngineExecutable( + run_engine_executable( build_dir, os.path.join('dart-sdk', 'bin', 'dart'), None, @@ -877,8 +874,8 @@ def RunBenchmarkTests(build_dir): ) -def GatherGithooksTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'githooks') +def gather_githooks_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'tools', 'githooks') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = ['--disable-dart-dev', dart_test_file] @@ -891,14 +888,14 @@ def GatherGithooksTests(build_dir): ) -def GatherClangTidyTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'clang_tidy') +def gather_clang_tidy_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'tools', 'clang_tidy') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = [ '--disable-dart-dev', dart_test_file, os.path.join(build_dir, 'compile_commands.json'), - os.path.join(buildroot_dir, 'flutter') + os.path.join(BUILDROOT_DIR, 'flutter') ] yield EngineExecutableTask( build_dir, @@ -909,13 +906,13 @@ def GatherClangTidyTests(build_dir): ) -def GatherApiConsistencyTests(build_dir): - test_dir = os.path.join(buildroot_dir, 'flutter', 'tools', 'api_check') +def gather_api_consistency_tests(build_dir): + test_dir = os.path.join(BUILDROOT_DIR, 'flutter', 'tools', 'api_check') dart_tests = glob.glob('%s/test/*_test.dart' % test_dir) for dart_test_file in dart_tests: opts = [ '--disable-dart-dev', dart_test_file, - os.path.join(buildroot_dir, 'flutter') + os.path.join(BUILDROOT_DIR, 'flutter') ] yield EngineExecutableTask( build_dir, @@ -926,7 +923,7 @@ def GatherApiConsistencyTests(build_dir): ) -def RunEngineTasksInParallel(tasks): +def run_engine_tasks_in_parallel(tasks): # Work around a bug in Python. # # The multiprocessing package relies on the win32 WaitForMultipleObjects() @@ -946,13 +943,13 @@ def RunEngineTasksInParallel(tasks): for task, async_result in async_results: try: async_result.get() - except Exception as exn: + except Exception as exn: # pylint: disable=broad-except failures += [(task, exn)] if len(failures) > 0: - print("The following commands failed:") + print('The following commands failed:') for task, exn in failures: - print("%s\n%s\n" % (str(task), str(exn))) + print('%s\n%s\n' % (str(task), str(exn))) raise Exception() @@ -1019,7 +1016,10 @@ def main(): '--objc-filter', type=str, default=None, - help='Filter parameter for which objc tests to run (example: "IosUnitTestsTests/SemanticsObjectTest/testShouldTriggerAnnouncement")' + help=( + 'Filter parameter for which objc tests to run ' + '(example: "IosUnitTestsTests/SemanticsObjectTest/testShouldTriggerAnnouncement")' + ) ) parser.add_argument( '--coverage', @@ -1056,30 +1056,30 @@ def main(): else: types = args.type.split(',') - build_dir = os.path.join(out_dir, args.variant) + build_dir = os.path.join(OUT_DIR, args.variant) if args.type != 'java' and args.type != 'android': assert os.path.exists( build_dir ), 'Build variant directory %s does not exist!' % build_dir if args.sanitizer_suppressions: - assert IsLinux() or IsMac( - ), "The sanitizer suppressions flag is only supported on Linux and Mac." + assert is_linux() or is_mac( + ), 'The sanitizer suppressions flag is only supported on Linux and Mac.' file_dir = os.path.dirname(os.path.abspath(__file__)) command = [ - "env", "-i", "bash", "-c", - "source {}/sanitizer_suppressions.sh >/dev/null && env" + 'env', '-i', 'bash', '-c', + 'source {}/sanitizer_suppressions.sh >/dev/null && env' .format(file_dir) ] process = subprocess.Popen(command, stdout=subprocess.PIPE) for line in process.stdout: - key, _, value = line.decode('utf8').strip().partition("=") + key, _, value = line.decode('utf8').strip().partition('=') os.environ[key] = value process.communicate() # Avoid pipe deadlock while waiting for termination. engine_filter = args.engine_filter.split(',') if args.engine_filter else None if 'engine' in types: - RunCCTests( + run_cc_tests( build_dir, engine_filter, args.coverage, args.engine_capture_core_dump ) @@ -1090,10 +1090,10 @@ def main(): build_name = args.variant try: xvfb.StartVirtualX(build_name, build_dir) - vulkan_gtest_filter = ParseImpellerVulkanFilter() + vulkan_gtest_filter = parse_impeller_vulkan_filter() gtest_flags = shuffle_flags gtest_flags.append(vulkan_gtest_filter) - RunEngineExecutable( + run_engine_executable( build_dir, 'impeller_unittests', engine_filter, @@ -1105,47 +1105,47 @@ def main(): if 'dart' in types: dart_filter = args.dart_filter.split(',') if args.dart_filter else None - tasks = list(GatherDartSmokeTest(build_dir, args.verbose_dart_snapshot)) - tasks += list(GatherLitetestTests(build_dir)) - tasks += list(GatherGithooksTests(build_dir)) - tasks += list(GatherClangTidyTests(build_dir)) - tasks += list(GatherApiConsistencyTests(build_dir)) - tasks += list(GatherPathOpsTests(build_dir)) - tasks += list(GatherConstFinderTests(build_dir)) - tasks += list(GatherFrontEndServerTests(build_dir)) - tasks += list( - GatherDartTests(build_dir, dart_filter, args.verbose_dart_snapshot) - ) - RunEngineTasksInParallel(tasks) + tasks = list(gather_dart_smoke_test(build_dir)) + tasks += list(gather_litetest_tests(build_dir)) + tasks += list(gather_githooks_tests(build_dir)) + tasks += list(gather_clang_tidy_tests(build_dir)) + tasks += list(gather_api_consistency_tests(build_dir)) + tasks += list(gather_path_ops_tests(build_dir)) + tasks += list(gather_const_finder_tests(build_dir)) + tasks += list(gather_front_end_server_tests(build_dir)) + tasks += list(gather_dart_tests(build_dir, dart_filter)) + run_engine_tasks_in_parallel(tasks) if 'java' in types: - assert not IsWindows(), "Android engine files can't be compiled on Windows." + assert not is_windows( + ), "Android engine files can't be compiled on Windows." java_filter = args.java_filter if ',' in java_filter or '*' in java_filter: print( - 'Can only filter JUnit4 tests by single entire class name, eg "io.flutter.SmokeTest". Ignoring filter=' - + java_filter + 'Can only filter JUnit4 tests by single entire class name, ' + 'eg "io.flutter.SmokeTest". Ignoring filter=' + java_filter ) java_filter = None - RunJavaTests(java_filter, args.android_variant) + run_java_tests(java_filter, args.android_variant) if 'android' in types: - assert not IsWindows(), "Android engine files can't be compiled on Windows." - RunAndroidTests(args.android_variant, args.adb_path) + assert not is_windows( + ), "Android engine files can't be compiled on Windows." + run_android_tests(args.android_variant, args.adb_path) if 'objc' in types: - assert IsMac(), "iOS embedding tests can only be run on macOS." - RunObjcTests(args.ios_variant, args.objc_filter) + assert is_mac(), 'iOS embedding tests can only be run on macOS.' + run_objc_tests(args.ios_variant, args.objc_filter) # /~https://github.com/flutter/flutter/issues/36300 - if 'benchmarks' in types and not IsWindows(): - RunBenchmarkTests(build_dir) - RunEngineBenchmarks(build_dir, engine_filter) + if 'benchmarks' in types and not is_windows(): + run_benchmark_tests(build_dir) + run_engine_benchmarks(build_dir, engine_filter) variants_to_skip = ['host_release', 'host_profile'] if ('engine' in types or 'font-subset' in types) and args.variant not in variants_to_skip: - RunCmd(['python3', 'test.py'], cwd=font_subset_dir) + run_cmd(['python3', 'test.py'], cwd=FONT_SUBSET_DIR) if __name__ == '__main__':