Commit 73383ad5 authored by zhaoyangli's avatar zhaoyangli Committed by Commit Bot

Modify bot scripts to run Autofill Automation(WPR) eg2tests.

Major changes at WprProxySimulatorTestRunner:
- Added a new class variable |host_app_path| for eg2test.
- Changed command running test from iossim binary file to Xcodebuild.
  Created command with |Eg2testsApp| and |LaunchCommand| classes from
  xcodebuilder_runner.py.
- Moved it to a new file wpr_runner.py for clearer structure.
- Changed runner tests correspondingly and moved them to new file
  wpr_runner_test.py.

Other changes:
- In run.py, added |host_app_path| parameter when initializing
  |WprProxySimulatorTestRunner|.
- In test_runner.py, deleted trusted certificate if exist as it can't
  be overwritten per permission settings. Moved trusted cert related
  logic to wpr_runner.py.

TEST=src/ios/build/bots/scripts/run.py     --app
src/out/Debug-iphonesimulator/
  ios_chrome_autofill_automation_eg2tests_module-Runner.app
--host-app     src/out/Debug-iphonesimulator/ios_chrome_eg2tests.app
--args-json     "{\"test_args\": [],         \"xctest\": true,
  \"test_cases\": [],         \"restart\": false,
  \"xcode_parallelization\": false,
  \"xcodebuild_device_runner\": false}"
--out-dir     ${ISOLATED_OUTDIR}     --retries     3
--shards     1     --xcode-build-version     11a420a
--mac-toolchain-cmd     mac_toolchain     --xcode-path
/Applications/Xcode.app     --wpr-tools-path     ${WPRPATH}
--replay-path
/Users/zhaoyangli/Desktop/projects/auto-auto/recipeReplayDataSubset
--iossim     src/out/Debug-iphonesimulator/iossim
--platform     "iPhone X"     --version     13.0



Bug: 1003605
Change-Id: Id336fa2e0a73cd0331dc2b97333e7e8a562180da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876757
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715538}
parent 3d330531
...@@ -25,6 +25,7 @@ import sys ...@@ -25,6 +25,7 @@ import sys
import traceback import traceback
import test_runner import test_runner
import wpr_runner
import xcodebuild_runner import xcodebuild_runner
...@@ -61,8 +62,9 @@ def main(): ...@@ -61,8 +62,9 @@ def main():
env_vars=args.env_var env_vars=args.env_var
) )
elif args.replay_path != 'NO_PATH': elif args.replay_path != 'NO_PATH':
tr = test_runner.WprProxySimulatorTestRunner( tr = wpr_runner.WprProxySimulatorTestRunner(
args.app, args.app,
args.host_app,
args.iossim, args.iossim,
args.replay_path, args.replay_path,
args.platform, args.platform,
...@@ -93,7 +95,6 @@ def main(): ...@@ -93,7 +95,6 @@ def main():
shards=args.shards, shards=args.shards,
test_args=test_args, test_args=test_args,
test_cases=args.test_cases, test_cases=args.test_cases,
use_trusted_cert=args.use_trusted_cert,
wpr_tools_path=args.wpr_tools_path, wpr_tools_path=args.wpr_tools_path,
xcode_path=args.xcode_path, xcode_path=args.xcode_path,
xctest=args.xctest, xctest=args.xctest,
......
This diff is collapsed.
...@@ -354,175 +354,6 @@ class SimulatorTestRunnerTest(TestCase): ...@@ -354,175 +354,6 @@ class SimulatorTestRunnerTest(TestCase):
self.assertTrue(tr.logs) self.assertTrue(tr.logs)
class WprProxySimulatorTestRunnerTest(TestCase):
"""Tests for test_runner.WprProxySimulatorTestRunner."""
def setUp(self):
super(WprProxySimulatorTestRunnerTest, self).setUp()
def install_xcode(build, mac_toolchain_cmd, xcode_app_path):
return True
self.mock(test_runner, 'get_current_xcode_info', lambda: {
'version': 'test version', 'build': 'test build', 'path': 'test/path'})
self.mock(test_runner, 'install_xcode', install_xcode)
self.mock(test_runner.subprocess, 'check_output',
lambda _: 'fake-bundle-id')
self.mock(os.path, 'abspath', lambda path: '/abs/path/to/%s' % path)
self.mock(os.path, 'exists', lambda _: True)
self.mock(test_runner.TestRunner, 'set_sigterm_handler',
lambda self, handler: 0)
self.mock(test_runner.SimulatorTestRunner, 'getSimulator',
lambda _: 'fake-id')
self.mock(test_runner.SimulatorTestRunner, 'deleteSimulator',
lambda a, b: True)
self.mock(test_runner.WprProxySimulatorTestRunner,
'copy_trusted_certificate', lambda a, b: True)
def test_replay_path_not_found(self):
"""Ensures ReplayPathNotFoundError is raised."""
self.mock(os.path, 'exists', lambda p: not p.endswith('bad-replay-path'))
with self.assertRaises(test_runner.ReplayPathNotFoundError):
test_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-iossim',
'bad-replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
def test_wpr_tools_not_found(self):
"""Ensures WprToolsNotFoundError is raised."""
self.mock(os.path, 'exists', lambda p: not p.endswith('bad-tools-path'))
with self.assertRaises(test_runner.WprToolsNotFoundError):
test_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'bad-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
def test_init(self):
"""Ensures instance is created."""
tr = test_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
self.assertTrue(tr)
def run_wpr_test(self, test_filter=[], invert=False):
"""Wrapper that mocks the _run method and returns its result."""
class FakeStdout:
def __init__(self):
self.line_index = 0
self.lines = [
'Test Case \'-[a 1]\' started.',
'Test Case \'-[a 1]\' has uninteresting logs.',
'Test Case \'-[a 1]\' passed (0.1 seconds)',
'Test Case \'-[b 2]\' started.',
'Test Case \'-[b 2]\' passed (0.1 seconds)',
'Test Case \'-[c 3]\' started.',
'Test Case \'-[c 3]\' has interesting failure info.',
'Test Case \'-[c 3]\' failed (0.1 seconds)',
]
def readline(self):
if self.line_index < len(self.lines):
return_line = self.lines[self.line_index]
self.line_index += 1
return return_line
else:
return None
class FakeProcess:
def __init__(self):
self.stdout = FakeStdout()
self.returncode = 0
def stdout(self):
return self.stdout
def wait(self):
return
def popen(recipe_cmd, env, stdout, stderr):
return FakeProcess()
tr = test_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
self.mock(test_runner.WprProxySimulatorTestRunner, 'wprgo_start',
lambda a,b: None)
self.mock(test_runner.WprProxySimulatorTestRunner, 'wprgo_stop',
lambda _: None)
self.mock(os.path, 'isfile', lambda _: True)
self.mock(glob, 'glob', lambda _: ["file1", "file2"])
self.mock(subprocess, 'Popen', popen)
tr.xctest_path = 'fake.xctest'
cmd = tr.get_launch_command(test_filter=test_filter, invert=invert)
return tr._run(cmd=cmd, shards=1)
def test_run_no_filter(self):
"""Ensures the _run method can handle passed and failed tests."""
result = self.run_wpr_test()
self.assertIn('file1.a/1', result.passed_tests)
self.assertIn('file1.b/2', result.passed_tests)
self.assertIn('file1.c/3', result.failed_tests)
self.assertIn('file2.a/1', result.passed_tests)
self.assertIn('file2.b/2', result.passed_tests)
self.assertIn('file2.c/3', result.failed_tests)
def test_run_with_filter(self):
"""Ensures the _run method works with a filter."""
result = self.run_wpr_test(test_filter=["file1"], invert=False)
self.assertIn('file1.a/1', result.passed_tests)
self.assertIn('file1.b/2', result.passed_tests)
self.assertIn('file1.c/3', result.failed_tests)
self.assertNotIn('file2.a/1', result.passed_tests)
self.assertNotIn('file2.b/2', result.passed_tests)
self.assertNotIn('file2.c/3', result.failed_tests)
def test_run_with_inverted_filter(self):
"""Ensures the _run method works with an inverted filter."""
result = self.run_wpr_test(test_filter=["file1"], invert=True)
self.assertNotIn('file1.a/1', result.passed_tests)
self.assertNotIn('file1.b/2', result.passed_tests)
self.assertNotIn('file1.c/3', result.failed_tests)
self.assertIn('file2.a/1', result.passed_tests)
self.assertIn('file2.b/2', result.passed_tests)
self.assertIn('file2.c/3', result.failed_tests)
class DeviceTestRunnerTest(TestCase): class DeviceTestRunnerTest(TestCase):
def setUp(self): def setUp(self):
super(DeviceTestRunnerTest, self).setUp() super(DeviceTestRunnerTest, self).setUp()
......
This diff is collapsed.
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for wpr_runner.py."""
import glob
import logging
import os
import subprocess
import unittest
import test_runner
import test_runner_test
import wpr_runner
class WprProxySimulatorTestRunnerTest(test_runner_test.TestCase):
"""Tests for test_runner.WprProxySimulatorTestRunner."""
def setUp(self):
super(WprProxySimulatorTestRunnerTest, self).setUp()
def install_xcode(build, mac_toolchain_cmd, xcode_app_path):
return True
self.mock(test_runner, 'get_current_xcode_info', lambda: {
'version': 'test version', 'build': 'test build', 'path': 'test/path'})
self.mock(test_runner, 'install_xcode', install_xcode)
self.mock(test_runner.subprocess, 'check_output',
lambda _: 'fake-bundle-id')
self.mock(os.path, 'abspath', lambda path: '/abs/path/to/%s' % path)
self.mock(os.path, 'exists', lambda _: True)
self.mock(test_runner.TestRunner, 'set_sigterm_handler',
lambda self, handler: 0)
self.mock(test_runner.SimulatorTestRunner, 'getSimulator',
lambda _: 'fake-id')
self.mock(test_runner.SimulatorTestRunner, 'deleteSimulator',
lambda a, b: True)
self.mock(wpr_runner.WprProxySimulatorTestRunner,
'copy_trusted_certificate', lambda a: True)
def test_app_not_found(self):
"""Ensures AppNotFoundError is raised."""
self.mock(os.path, 'exists', lambda p: not p.endswith('bad-host-app-path'))
with self.assertRaises(test_runner.AppNotFoundError):
wpr_runner.WprProxySimulatorTestRunner(
'fake-app',
'bad-host-app-path',
'fake-iossim',
'replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
def test_replay_path_not_found(self):
"""Ensures ReplayPathNotFoundError is raised."""
self.mock(os.path, 'exists', lambda p: not p.endswith('bad-replay-path'))
with self.assertRaises(wpr_runner.ReplayPathNotFoundError):
wpr_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-host-app',
'fake-iossim',
'bad-replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
def test_wpr_tools_not_found(self):
"""Ensures WprToolsNotFoundError is raised."""
self.mock(os.path, 'exists', lambda p: not p.endswith('bad-tools-path'))
with self.assertRaises(wpr_runner.WprToolsNotFoundError):
wpr_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-host-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'bad-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
def test_init(self):
"""Ensures instance is created."""
tr = wpr_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-host-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
self.assertTrue(tr)
def run_wpr_test(self, test_filter=[], invert=False):
"""Wrapper that mocks the _run method and returns its result."""
class FakeStdout:
def __init__(self):
self.line_index = 0
self.lines = [
'Test Case \'-[a 1]\' started.',
'Test Case \'-[a 1]\' has uninteresting logs.',
'Test Case \'-[a 1]\' passed (0.1 seconds)',
'Test Case \'-[b 2]\' started.',
'Test Case \'-[b 2]\' passed (0.1 seconds)',
'Test Case \'-[c 3]\' started.',
'Test Case \'-[c 3]\' has interesting failure info.',
'Test Case \'-[c 3]\' failed (0.1 seconds)',
]
def readline(self):
if self.line_index < len(self.lines):
return_line = self.lines[self.line_index]
self.line_index += 1
return return_line
else:
return None
class FakeProcess:
def __init__(self):
self.stdout = FakeStdout()
self.returncode = 0
def stdout(self):
return self.stdout
def wait(self):
return
def popen(recipe_cmd, env, stdout, stderr):
return FakeProcess()
tr = wpr_runner.WprProxySimulatorTestRunner(
'fake-app',
'fake-host-app',
'fake-iossim',
'replay-path',
'platform',
'os',
'wpr-tools-path',
'xcode-version',
'xcode-build',
'out-dir',
)
self.mock(wpr_runner.WprProxySimulatorTestRunner, 'wprgo_start',
lambda a, b: None)
self.mock(wpr_runner.WprProxySimulatorTestRunner, 'wprgo_stop',
lambda _: None)
self.mock(wpr_runner.WprProxySimulatorTestRunner, 'get_wpr_test_command',
lambda a, b, c: ["command", "arg"])
self.mock(os.path, 'isfile', lambda _: True)
self.mock(glob, 'glob', lambda _: ["file1", "file2"])
self.mock(subprocess, 'Popen', popen)
tr.xctest_path = 'fake.xctest'
cmd = tr.get_launch_command(test_filter=test_filter, invert=invert)
return tr._run(cmd=cmd, shards=1)
def test_run_no_filter(self):
"""Ensures the _run method can handle passed and failed tests."""
result = self.run_wpr_test()
self.assertIn('file1.a/1', result.passed_tests)
self.assertIn('file1.b/2', result.passed_tests)
self.assertIn('file1.c/3', result.failed_tests)
self.assertIn('file2.a/1', result.passed_tests)
self.assertIn('file2.b/2', result.passed_tests)
self.assertIn('file2.c/3', result.failed_tests)
def test_run_with_filter(self):
"""Ensures the _run method works with a filter."""
result = self.run_wpr_test(test_filter=["file1"], invert=False)
self.assertIn('file1.a/1', result.passed_tests)
self.assertIn('file1.b/2', result.passed_tests)
self.assertIn('file1.c/3', result.failed_tests)
self.assertNotIn('file2.a/1', result.passed_tests)
self.assertNotIn('file2.b/2', result.passed_tests)
self.assertNotIn('file2.c/3', result.failed_tests)
def test_run_with_inverted_filter(self):
"""Ensures the _run method works with an inverted filter."""
result = self.run_wpr_test(test_filter=["file1"], invert=True)
self.assertNotIn('file1.a/1', result.passed_tests)
self.assertNotIn('file1.b/2', result.passed_tests)
self.assertNotIn('file1.c/3', result.failed_tests)
self.assertIn('file2.a/1', result.passed_tests)
self.assertIn('file2.b/2', result.passed_tests)
self.assertIn('file2.c/3', result.failed_tests)
if __name__ == '__main__':
logging.basicConfig(
format='[%(asctime)s:%(levelname)s] %(message)s',
level=logging.DEBUG,
datefmt='%I:%M:%S')
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment