From e3785a882cca35fecce785c21cbc5265e839b2af Mon Sep 17 00:00:00 2001 From: Ben Pastene Date: Fri, 4 May 2018 21:59:11 +0000 Subject: [PATCH] Remove stdout result parsing from cros-vm test runner. Instead, it just pulls the file from the VM directly, which was added in CL:1021531. Bug: 828607 Change-Id: I6c71f557bf91dafc8c5f638d0c07c49bde728ed4 Reviewed-on: https://chromium-review.googlesource.com/1044755 Reviewed-by: Dirk Pranke Reviewed-by: John Budorick Commit-Queue: Ben Pastene Cr-Original-Commit-Position: refs/heads/master@{#556213} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 5a53981ff196802bba5e5436b4cb433a2fccc8c7 --- chromeos/run_vm_test.py | 51 ++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/chromeos/run_vm_test.py b/chromeos/run_vm_test.py index c77e3f0e3..86027bea8 100755 --- a/chromeos/run_vm_test.py +++ b/chromeos/run_vm_test.py @@ -97,6 +97,19 @@ def vm_test(args): for f in read_runtime_files(args.runtime_deps_path, args.path_to_outdir): cros_run_vm_test_cmd.extend(['--files', f]) + if args.test_launcher_summary_output: + result_dir, result_file = os.path.split(args.test_launcher_summary_output) + # If args.test_launcher_summary_output is a file in cwd, result_dir will be + # an empty string, so replace it with '.' when this is the case so + # cros_run_vm_test can correctly handle it. + if not result_dir: + result_dir = '.' + vm_result_file = '/tmp/%s' % result_file + cros_run_vm_test_cmd += [ + '--results-src', vm_result_file, + '--results-dest-dir', result_dir, + ] + cros_run_vm_test_cmd += [ '--cmd', '--', @@ -105,42 +118,16 @@ def vm_test(args): '--test-launcher-total-shards=%d' % args.test_launcher_total_shards, ] - stdout_results_delimiter = '@@@@@results-file-delimiter@@@@@' if args.test_launcher_summary_output: - result_file = 'gtest_results.json' - cros_run_vm_test_cmd.extend([ - '--test-launcher-summary-output=%s' % result_file, - ';', 'export test_code=$?', - ';', 'echo %s' % stdout_results_delimiter, - ';', 'cat %s' % result_file, - ';', 'echo %s' % stdout_results_delimiter, - ';', 'exit $test_code', - ]) + cros_run_vm_test_cmd += [ + '--test-launcher-summary-output=%s' % vm_result_file, + ] logging.info('Running the following command:') logging.info(' '.join(cros_run_vm_test_cmd)) - vm_proc = subprocess.Popen( - cros_run_vm_test_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - - # Stream cros_run_vm_test's stdout to our stdout while capturing it so we can - # strip out the results json file. - # TODO(crbug.com/835061): Remove all this stdout parsing and just pull the - # file directly. - vm_output = '' - while True: - line = vm_proc.stdout.readline() - if not line: - break - print line, # End with a comma so print doesn't auto append a newline. - vm_output += line - - if args.test_launcher_summary_output: - json_contents = vm_output.split(stdout_results_delimiter)[-2] - with open(args.test_launcher_summary_output, 'w') as f: - f.write(json_contents) - - return vm_proc.returncode + return subprocess.call( + cros_run_vm_test_cmd, stdout=sys.stdout, stderr=sys.stderr) def main(): @@ -190,6 +177,8 @@ def main(): help='Total number of external shards.') args = parser.parse_args() + logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARN) + if not os.path.exists('/dev/kvm'): logging.error('/dev/kvm is missing. Is KVM installed on this machine?') return 1