From dedbc0f61b5feec0857e7abbdc4979f68abbb33d Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Fri, 25 Mar 2022 10:36:27 -0400 Subject: [PATCH] Update Crashpad bot scripts to python3. Change-Id: Ie3848c2f2bbbe34ca3a5e7da5e7d05e3cfba5b72 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3549021 Reviewed-by: Mark Mentovai Commit-Queue: Justin Cohen --- .vpython3 | 32 ++++++++++++++++++++++++++++++++ build/run_tests.py | 31 ++++++++++++++++--------------- snapshot/win/end_to_end_test.py | 18 +++++++++++++----- 3 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 .vpython3 diff --git a/.vpython3 b/.vpython3 new file mode 100644 index 00000000..0d7baf9e --- /dev/null +++ b/.vpython3 @@ -0,0 +1,32 @@ +# Copyright 2022 The Crashpad Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This is a vpython "spec" file. +# +# It describes patterns for python wheel dependencies of the python scripts. +# +# Read more about `vpython` and how to modify this file here: +# https://chromium.googlesource.com/infra/infra/+/master/doc/users/vpython.md + +# This is needed for snapshot/win/end_to_end_test.py. +wheel: < + name: "infra/python/wheels/pywin32/${vpython_platform}" + version: "version:300" + match_tag: < + platform: "win32" + > + match_tag: < + platform: "win_amd64" + > +> diff --git a/build/run_tests.py b/build/run_tests.py index f48652ff..71d1d9c3 100755 --- a/build/run_tests.py +++ b/build/run_tests.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# coding: utf-8 +#!/usr/bin/env python3 # Copyright 2014 The Crashpad Authors. All rights reserved. # @@ -15,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import argparse import os import pipes @@ -40,7 +37,7 @@ def _FindGNFromBinaryDir(binary_dir): build_ninja = os.path.join(binary_dir, 'build.ninja') if os.path.isfile(build_ninja): - with open(build_ninja, 'rb') as f: + with open(build_ninja, 'r') as f: # Look for the always-generated regeneration rule of the form: # # rule gn @@ -78,10 +75,11 @@ def _BinaryDirTargetOS(binary_dir): ], shell=IS_WINDOWS_HOST, stdout=subprocess.PIPE, - stderr=open(os.devnull)) + stderr=open(os.devnull), + text=True) value = popen.communicate()[0] if popen.returncode == 0: - match = re.match('target_os = "(.*)"$', value.decode('utf-8')) + match = re.match('target_os = "(.*)"$', value) if match: return match.group(1) @@ -196,13 +194,14 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line): child = subprocess.Popen(adb_command, shell=IS_WINDOWS_HOST, stdin=open(os.devnull), - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + text=True) FINAL_LINE_RE = re.compile('status=(\d+)$') final_line = None while True: # Use readline so that the test output appears “live” when running. - data = child.stdout.readline().decode('utf-8') + data = child.stdout.readline() if data == '': break if final_line is not None: @@ -369,10 +368,11 @@ def _RunOnIOSTarget(binary_dir, test, is_xcuitest=False): xctestrun_path = f.name print(xctestrun_path) - if is_xcuitest: - plistlib.writePlist(xcuitest(binary_dir, test), xctestrun_path) - else: - plistlib.writePlist(xctest(binary_dir, test), xctestrun_path) + with open(xctestrun_path, 'wb') as fp: + if is_xcuitest: + plistlib.dump(xcuitest(binary_dir, test), fp) + else: + plistlib.dump(xctest(binary_dir, test), fp) subprocess.check_call([ 'xcodebuild', 'test-without-building', '-xctestrun', xctestrun_path, @@ -421,10 +421,11 @@ def main(args): android_device = os.environ.get('ANDROID_DEVICE') if not android_device: adb_devices = subprocess.check_output(['adb', 'devices'], - shell=IS_WINDOWS_HOST) + shell=IS_WINDOWS_HOST, + text=True) devices = [] for line in adb_devices.splitlines(): - line = line.decode('utf-8') + line = line if (line == 'List of devices attached' or re.match('^\* daemon .+ \*$', line) or line == ''): continue diff --git a/snapshot/win/end_to_end_test.py b/snapshot/win/end_to_end_test.py index aa606f98..9d319078 100755 --- a/snapshot/win/end_to_end_test.py +++ b/snapshot/win/end_to_end_test.py @@ -14,13 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import os import platform import pywintypes import random import re +import struct import subprocess import sys import tempfile @@ -104,7 +103,7 @@ def NamedPipeExistsAndReady(pipe_name): try: win32pipe.WaitNamedPipe(pipe_name, win32pipe.NMPWAIT_WAIT_FOREVER) except pywintypes.error as e: - if e[0] == winerror.ERROR_FILE_NOT_FOUND: + if e.winerror == winerror.ERROR_FILE_NOT_FOUND: return False raise return True @@ -152,6 +151,14 @@ def GetDumpFromProgram(out_dir, pipe_name, executable_name, expect_exit_code, ] + list(args)) print('Running %s' % os.path.basename(command[0])) exit_code = subprocess.call(command) + + # Some win32con codes are negative signed integers, whereas all exit + # codes are unsigned integers. Convert from signed to unsigned. + if expect_exit_code < 0: + expect_exit_code = struct.unpack('I', + struct.pack('i', + expect_exit_code))[0] + if exit_code != expect_exit_code: raise subprocess.CalledProcessError(exit_code, executable_name) @@ -160,7 +167,8 @@ def GetDumpFromProgram(out_dir, pipe_name, executable_name, expect_exit_code, '--database=' + test_database, '--show-pending-reports', '--show-all-report-info', - ]) + ], + text=True) for line in out.splitlines(): if line.strip().startswith('Path:'): return line.partition(':')[2].strip() @@ -205,7 +213,7 @@ class CdbRun(object): # Run a command line that loads the dump, runs the specified cdb # command, and then quits, and capturing stdout. self.out = subprocess.check_output( - [cdb_path, '-z', dump_path, '-c', command + ';q']) + [cdb_path, '-z', dump_path, '-c', command + ';q'], text=True) def Check(self, pattern, message, re_flags=0): match_obj = re.search(pattern, self.out, re_flags)