Commit 083d903c authored by Lindsay Pasricha's avatar Lindsay Pasricha Committed by Commit Bot

Revert "[iOS][code coverage]Move raw coverage data to isolated output in test runner scripts."

This reverts commit dfe67264.

Reason for revert: This breaks on device runs for xcodebuild_runner.
This revert will land after the revert of crrev/c/2076765.

Original change's description:
> [iOS][code coverage]Move raw coverage data to isolated output in test runner scripts.
>
> - Added function of moving raw coverage data in a new utility file and
>   corresponding tests.
> - Added "use_clang_coverage" arg to run.py and all simulator test
>   runner classes.
> - Added check of the arg and call to the function in TestRunners after
>   running unit tests and EG tests.
>
> Bug: 943883
> Change-Id: I5f16c152a38f7a8a3d988aac9e73964d890219b8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2048851
> Reviewed-by: Rohit Rao <rohitrao@chromium.org>
> Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#744470}

Bug: 943883,1058257
Change-Id: I4ae784f831c60bf621c8135af490bdeffa3c004e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089404
Commit-Queue: Lindsay Pasricha <lindsayw@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747930}
parent 70405149
# Copyright 2020 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.
"""Utility functions related with code coverage."""
import glob
import os
import shutil
SIMULATORS_FOLDER = os.path.expanduser(
'~/Library/Developer/CoreSimulator/Devices')
def move_raw_coverage_data(udid, isolated_output_dir):
"""Moves raw coverage data files(.profraw) from simulator shared resources
directory to isolated_output/profraw.
Args:
udid: (str) UDID of the simulator that just run the tests.
isolated_out_dir: (str) Isolated output directory of current isolated
shard.
"""
profraw_origin_dir = os.path.join(SIMULATORS_FOLDER, udid, "data")
profraw_destination_dir = os.path.join(isolated_output_dir, "profraw")
if not os.path.exists(profraw_destination_dir):
os.mkdir(profraw_destination_dir)
for profraw_file in glob.glob(os.path.join(profraw_origin_dir, '*.profraw')):
shutil.move(profraw_file, profraw_destination_dir)
# Copyright 2020 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.
"""Tests of coverage_util functions."""
import os
import shutil
import unittest
import coverage_util
import test_runner_test
class TestCoverageUtil(test_runner_test.TestCase):
"""Test cases for coverage_util.py"""
def create_origin_profraw_file_if_not_exist(self):
"""Creates the profraw file in the correct udid data folder to move if it
doesn't exist
"""
if not os.path.exists(self.origin_profraw_file_path):
with open(self.origin_profraw_file_path, 'w') as outfile:
outfile.write("Some raw coverage data.\n")
def setUp(self):
super(TestCoverageUtil, self).setUp()
self.test_folder = os.path.join(os.getcwd(), "coverage_util_test_data")
self.simulators_folder = os.path.join(self.test_folder, "Devices")
self.existing_udid = "existing-udid"
self.existing_udid_folder = os.path.join(self.simulators_folder,
"existing-udid")
self.existing_udid_data_folder = os.path.join(self.simulators_folder,
self.existing_udid, "data")
if not os.path.exists(self.existing_udid_data_folder):
os.makedirs(self.existing_udid_data_folder)
self.profraw_file_name = "default.profraw"
self.origin_profraw_file_path = os.path.join(self.existing_udid_data_folder,
self.profraw_file_name)
self.not_existing_udid = "not-existing-udid"
self.not_existing_udid_data_folder = os.path.join(
self.simulators_folder, self.not_existing_udid, "data")
if os.path.exists(self.not_existing_udid_data_folder):
shutil.rmtree(self.not_existing_udid_data_folder)
self.output_folder = os.path.join(self.test_folder, "output")
if not os.path.exists(self.output_folder):
os.makedirs(self.output_folder)
self.expected_profraw_output_path = os.path.join(
self.output_folder, "profraw", self.profraw_file_name)
self.mock(coverage_util, 'SIMULATORS_FOLDER', self.simulators_folder)
def tearDown(self):
shutil.rmtree(self.test_folder)
def test_move_raw_coverage_data(self):
"""Tests if coverage_util can correctly move raw coverage data"""
self.create_origin_profraw_file_if_not_exist()
self.assertTrue(os.path.exists(self.origin_profraw_file_path))
self.assertFalse(os.path.exists(self.expected_profraw_output_path))
coverage_util.move_raw_coverage_data(self.existing_udid, self.output_folder)
self.assertFalse(os.path.exists(self.origin_profraw_file_path))
self.assertTrue(os.path.exists(self.expected_profraw_output_path))
os.remove(self.expected_profraw_output_path)
def test_move_raw_coverage_data_origin_not_exist(self):
"""Ensures that coverage_util won't break when raw coverage data folder or
file doesn't exist
"""
# Tests origin directory doesn't exist.
coverage_util.move_raw_coverage_data(self.not_existing_udid,
self.output_folder)
self.assertFalse(os.path.exists(self.expected_profraw_output_path))
# Tests profraw file doesn't exist.
if os.path.exists(self.origin_profraw_file_path):
os.remove(self.origin_profraw_file_path)
self.assertFalse(os.path.exists(self.origin_profraw_file_path))
self.assertFalse(os.path.exists(self.expected_profraw_output_path))
coverage_util.move_raw_coverage_data(self.existing_udid, self.output_folder)
self.assertFalse(os.path.exists(self.expected_profraw_output_path))
if __name__ == '__main__':
unittest.main()
...@@ -148,7 +148,6 @@ class Runner(): ...@@ -148,7 +148,6 @@ class Runner():
shards=self.args.shards, shards=self.args.shards,
test_cases=self.args.test_cases, test_cases=self.args.test_cases,
test_args=self.test_args, test_args=self.test_args,
use_clang_coverage=self.args.use_clang_coverage,
env_vars=self.args.env_var) env_vars=self.args.env_var)
elif self.args.replay_path != 'NO_PATH': elif self.args.replay_path != 'NO_PATH':
tr = wpr_runner.WprProxySimulatorTestRunner( tr = wpr_runner.WprProxySimulatorTestRunner(
...@@ -179,7 +178,6 @@ class Runner(): ...@@ -179,7 +178,6 @@ class Runner():
shards=self.args.shards, shards=self.args.shards,
test_args=self.test_args, test_args=self.test_args,
test_cases=self.args.test_cases, test_cases=self.args.test_cases,
use_clang_coverage=self.args.use_clang_coverage,
wpr_tools_path=self.args.wpr_tools_path, wpr_tools_path=self.args.wpr_tools_path,
xctest=self.args.xctest, xctest=self.args.xctest,
) )
...@@ -405,7 +403,6 @@ class Runner(): ...@@ -405,7 +403,6 @@ class Runner():
args.restart = args_json.get('restart', args.restart) args.restart = args_json.get('restart', args.restart)
args.test_cases = args.test_cases or [] args.test_cases = args.test_cases or []
args.test_cases.extend(args_json.get('test_cases', [])) args.test_cases.extend(args_json.get('test_cases', []))
args.use_clang_coverage = args_json.get('use_clang_coverage', False)
args.xctest = args_json.get('xctest', args.xctest) args.xctest = args_json.get('xctest', args.xctest)
args.xcode_parallelization = args_json.get('xcode_parallelization', args.xcode_parallelization = args_json.get('xcode_parallelization',
args.xcode_parallelization) args.xcode_parallelization)
......
...@@ -19,7 +19,6 @@ import subprocess ...@@ -19,7 +19,6 @@ import subprocess
import threading import threading
import time import time
import coverage_util
import gtest_utils import gtest_utils
import iossim_util import iossim_util
import test_apps import test_apps
...@@ -700,7 +699,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -700,7 +699,6 @@ class SimulatorTestRunner(TestRunner):
test_args=None, test_args=None,
test_cases=None, test_cases=None,
wpr_tools_path='', wpr_tools_path='',
use_clang_coverage=False,
xctest=False, xctest=False,
): ):
"""Initializes a new instance of this class. """Initializes a new instance of this class.
...@@ -719,7 +717,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -719,7 +717,6 @@ class SimulatorTestRunner(TestRunner):
launching. launching.
test_cases: List of tests to be included in the test run. None or [] to test_cases: List of tests to be included in the test run. None or [] to
include all tests. include all tests.
use_clang_coverage: Whether code coverage is enabled in this run.
wpr_tools_path: Path to pre-installed WPR-related tools wpr_tools_path: Path to pre-installed WPR-related tools
xctest: Whether or not this is an XCTest. xctest: Whether or not this is an XCTest.
...@@ -751,7 +748,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -751,7 +748,6 @@ class SimulatorTestRunner(TestRunner):
self.shards = shards self.shards = shards
self.wpr_tools_path = wpr_tools_path self.wpr_tools_path = wpr_tools_path
self.udid = iossim_util.get_simulator(self.platform, self.version) self.udid = iossim_util.get_simulator(self.platform, self.version)
self.use_clang_coverage = use_clang_coverage
@staticmethod @staticmethod
def kill_simulators(): def kill_simulators():
...@@ -798,9 +794,6 @@ class SimulatorTestRunner(TestRunner): ...@@ -798,9 +794,6 @@ class SimulatorTestRunner(TestRunner):
def extract_test_data(self): def extract_test_data(self):
"""Extracts data emitted by the test.""" """Extracts data emitted by the test."""
if self.use_clang_coverage:
coverage_util.move_raw_coverage_data(self.udid, self.out_dir)
# Find the Documents directory of the test app. The app directory names # Find the Documents directory of the test app. The app directory names
# don't correspond with any known information, so we have to examine them # don't correspond with any known information, so we have to examine them
# all until we find one with a matching CFBundleIdentifier. # all until we find one with a matching CFBundleIdentifier.
......
...@@ -12,7 +12,6 @@ import os ...@@ -12,7 +12,6 @@ import os
import subprocess import subprocess
import time import time
import coverage_util
import iossim_util import iossim_util
import test_apps import test_apps
import test_runner import test_runner
...@@ -112,7 +111,6 @@ class LaunchCommand(object): ...@@ -112,7 +111,6 @@ class LaunchCommand(object):
shards, shards,
retries, retries,
out_dir=os.path.basename(os.getcwd()), out_dir=os.path.basename(os.getcwd()),
use_clang_coverage=False,
env=None): env=None):
"""Initialize launch command. """Initialize launch command.
...@@ -138,7 +136,6 @@ class LaunchCommand(object): ...@@ -138,7 +136,6 @@ class LaunchCommand(object):
self.out_dir = out_dir self.out_dir = out_dir
self.logs = collections.OrderedDict() self.logs = collections.OrderedDict()
self.test_results = collections.OrderedDict() self.test_results = collections.OrderedDict()
self.use_clang_coverage = use_clang_coverage
self.env = env self.env = env
if distutils.version.LooseVersion('11.0') <= distutils.version.LooseVersion( if distutils.version.LooseVersion('11.0') <= distutils.version.LooseVersion(
test_runner.get_current_xcode_info()['version']): test_runner.get_current_xcode_info()['version']):
...@@ -210,13 +207,6 @@ class LaunchCommand(object): ...@@ -210,13 +207,6 @@ class LaunchCommand(object):
LOGGER.info('Start test attempt #%d for command [%s]' % ( LOGGER.info('Start test attempt #%d for command [%s]' % (
attempt, ' '.join(cmd_list))) attempt, ' '.join(cmd_list)))
output = self.launch_attempt(cmd_list) output = self.launch_attempt(cmd_list)
if self.use_clang_coverage:
# out_dir of LaunchCommand object is the TestRunner out_dir joined with
# UDID. Use os.path.dirname to retrieve the TestRunner out_dir.
coverage_util.move_raw_coverage_data(self.udid,
os.path.dirname(self.out_dir))
self.test_results['attempts'].append( self.test_results['attempts'].append(
self._log_parser.collect_test_results(outdir_attempt, output)) self._log_parser.collect_test_results(outdir_attempt, output))
if self.retries == attempt or not self.test_results[ if self.retries == attempt or not self.test_results[
...@@ -268,7 +258,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner): ...@@ -268,7 +258,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner):
shards=1, shards=1,
test_cases=None, test_cases=None,
test_args=None, test_args=None,
use_clang_coverage=False,
env_vars=None): env_vars=None):
"""Initializes a new instance of SimulatorParallelTestRunner class. """Initializes a new instance of SimulatorParallelTestRunner class.
...@@ -286,7 +275,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner): ...@@ -286,7 +275,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner):
None or [] to include all tests. None or [] to include all tests.
test_args: List of strings to pass as arguments to the test when test_args: List of strings to pass as arguments to the test when
launching. launching.
use_clang_coverage: Whether code coverage is enabled in this run.
env_vars: List of environment variables to pass to the test itself. env_vars: List of environment variables to pass to the test itself.
Raises: Raises:
...@@ -306,7 +294,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner): ...@@ -306,7 +294,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner):
shards=shards or 1, shards=shards or 1,
test_args=test_args, test_args=test_args,
test_cases=test_cases, test_cases=test_cases,
use_clang_coverage=use_clang_coverage,
xctest=False) xctest=False)
self.set_up() self.set_up()
self.host_app_path = None self.host_app_path = None
...@@ -315,10 +302,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner): ...@@ -315,10 +302,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner):
self._init_sharding_data() self._init_sharding_data()
self.logs = collections.OrderedDict() self.logs = collections.OrderedDict()
self.test_results['path_delimiter'] = '/' self.test_results['path_delimiter'] = '/'
# Do not enable parallel testing when code coverage is enabled, because raw
# coverage data won't be produced with parallel testing.
if self.use_clang_coverage:
self.shards = 1
def _init_sharding_data(self): def _init_sharding_data(self):
"""Initialize sharding data. """Initialize sharding data.
...@@ -367,7 +350,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner): ...@@ -367,7 +350,6 @@ class SimulatorParallelTestRunner(test_runner.SimulatorTestRunner):
shards=params['shards'], shards=params['shards'],
retries=self.retries, retries=self.retries,
out_dir=os.path.join(self.out_dir, params['udid']), out_dir=os.path.join(self.out_dir, params['udid']),
use_clang_coverage=self.use_clang_coverage,
env=self.get_launch_env())) env=self.get_launch_env()))
thread_pool = pool.ThreadPool(len(launch_commands)) thread_pool = pool.ThreadPool(len(launch_commands))
......
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