Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a config file to bptestrunner #340

Merged
merged 3 commits into from
Jun 27, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow passing a config file to bptestrunner
Also, bump rules_apple and subpar to latest versions
ob committed Jun 26, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit a7587f2883169fdacbbdd73d17a66d67c121b0a0
16 changes: 9 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

git_repository(

http_archive(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
tag = "0.15.0",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.17.2/rules_apple.0.17.2.tar.gz",
sha256 = "6efdde60c91724a2be7f89b0c0a64f01138a45e63ba5add2dca2645d981d23a1",
)

load(
@@ -28,8 +29,9 @@ load(
apple_support_dependencies()

# For packaging python scripts.
git_repository(
http_archive(
name = "subpar",
remote = "https://github.com/google/subpar",
commit = "edb8409041b521959b6ed4b7412c0eec59d4af78",
url = "https://github.com/google/subpar/archive/2.0.0.zip",
sha256 = "8876244a984d75f28b1c64d711b6e5dfab5f992a3b741480e63cfc5e26acba93",
strip_prefix = "subpar-2.0.0",
)
18 changes: 13 additions & 5 deletions bptestrunner/bluepill_test_runner.template.sh
Original file line number Diff line number Diff line change
@@ -16,27 +16,33 @@ TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/test_runner_work_dir.XXXXXX")"
TEST_BUNDLE_PATH="%(test_bundle_path)s"

if [[ "$TEST_BUNDLE_PATH" == *.xctest ]]; then
runner_flags+=("--test_bundle_path=${TEST_BUNDLE_PATH}")
runner_flags+=("--Xbp=--test_bundle_path=${TEST_BUNDLE_PATH}")
else
TEST_BUNDLE_NAME=$(basename_without_extension "${TEST_BUNDLE_PATH}")
TEST_BUNDLE_TMP_DIR="${TMP_DIR}/${TEST_BUNDLE_NAME}"
unzip -qq -d "${TEST_BUNDLE_TMP_DIR}" "${TEST_BUNDLE_PATH}"
runner_flags+=("--test-bundle-path=${TEST_BUNDLE_TMP_DIR}/${TEST_BUNDLE_NAME}.xctest")
runner_flags+=("--Xbp=--test-bundle-path=${TEST_BUNDLE_TMP_DIR}/${TEST_BUNDLE_NAME}.xctest")
fi

TEST_HOST_PATH="%(test_host_path)s"

if [[ -n "$TEST_HOST_PATH" ]]; then
if [[ "$TEST_HOST_PATH" == *.app ]]; then
runner_flags+=("--app_under_test_path=$TEST_HOST_PATH")
runner_flags+=("--Xbp=--app=$TEST_HOST_PATH")
else
TEST_HOST_NAME=$(basename_without_extension "${TEST_HOST_PATH}")
TEST_HOST_TMP_DIR="${TMP_DIR}/${TEST_HOST_NAME}"
unzip -qq -d "${TEST_HOST_TMP_DIR}" "${TEST_HOST_PATH}"
runner_flags+=("--app=${TEST_HOST_TMP_DIR}/Payload/${TEST_HOST_NAME}.app")
runner_flags+=("--Xbp=--app=${TEST_HOST_TMP_DIR}/Payload/${TEST_HOST_NAME}.app")
fi
fi

ATTR_CONFIG_FILE="%(config_file)s"

if [[ "$ATTR_CONFIG_FILE" != "%(config_file)s" ]]; then
runner_flags+=("--attr_config_file=$ATTR_CONFIG_FILE")
fi

# Constructs the json string to configure the test env and tests to run.
# It will be written into a temp json file which is passed to the test runner
# flags --config.
@@ -71,9 +77,11 @@ if [[ -n "${CONFIG_FILE_JSON_STR}" ]]; then
CONFIG_FILE_JSON_STR="{${CONFIG_FILE_JSON_STR}}"
CONFIG_FILE_JSON_PATH="${TMP_DIR}/config.json"
echo "${CONFIG_FILE_JSON_STR}" > "${CONFIG_FILE_JSON_PATH}"
runner_flags+=("-c" "${CONFIG_FILE_JSON_PATH}")
runner_flags+=("--rule_config_file" "${CONFIG_FILE_JSON_PATH}")
fi

runner_flags+=("-v")

cmd=("%(testrunner_binary)s"
"${runner_flags[@]}"
"$@")
10 changes: 10 additions & 0 deletions bptestrunner/ios_bluepill_test_runner.bzl
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@ def _get_template_substitutions(ctx):
"num_sims": str(ctx.attr.num_sims),
"testrunner_binary": ctx.executable._testrunner.short_path,
}
if ctx.attr.config_file:
# we get a Target in config_file
subs["config_file"] = ctx.attr.config_file.files.to_list()[0].path
return {"%(" + k + ")s": subs[k] for k in subs}

def _get_execution_environment(ctx):
@@ -79,6 +82,13 @@ Spawn simulator by clone from simulator template.
Number of simulators to run in parallel.
""",
),
"config_file": attr.label(
doc = """
A configuration file that will be passed to bluepill. Rule attributes
take precedence over conflicting values in the config file.
""",
allow_single_file = True,
),
"execution_requirements": attr.string_dict(
allow_empty = False,
default = {"requires-darwin": ""},
49 changes: 43 additions & 6 deletions bptestrunner/main.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,9 @@
# WITHOUT WARRANTIES OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
from __future__ import print_function

import argparse
import glob
import json
import logging
import os
import pkg_resources
@@ -25,21 +27,34 @@
def main():
"""Parse the arguments in an xctestrunner-compatible way
"""
args = sys.argv[1:]
if '-v' in args:
parser = argparse.ArgumentParser()
# attr_config_file is a config.json that comes from the rule's attributes (e.g. num_sims)
parser.add_argument('--attr_config-file')
# rule_config_file is the config.json that comes from the 'config_file' rule attribute
parser.add_argument('--rule_config_file')
parser.add_argument('--Xbp', nargs=1, action='append')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(message)s')
else:
logging.basicConfig(format='%(asctime)s %(message)s')

logging.debug("PWD: '%s'", os.getcwd())
# flatten Xbp args
bpargs = [a for sl in args.Xbp for a in sl]
# Add xcode path to CLI
args += ['--xcode-path', find_xcode_path()]
bpargs += ['--xcode-path', find_xcode_path()]
output_dir = os.environ['TEST_UNDECLARED_OUTPUTS_DIR']
args += ['--output-dir', output_dir]
bpargs += ['--output-dir', output_dir]
config_file = merge_config_files(args.attr_config_file,
args.rule_config_file)
bpargs += ['-c', config_file]

logging.debug("Running: bluepill %s", ' '.join(args))
rc = run('bluepill', args)
logging.debug("Running: bluepill %s", ' '.join(bpargs))
rc = run('bluepill', bpargs)
os.remove(config_file)
pattern = os.path.join(output_dir, '*.xml')
xml_files = glob.glob(pattern)
final_xml_output = None
@@ -53,6 +68,28 @@ def main():
sys.exit(rc)


def merge_config_files(config1, config2):
"""Merge two config files. Keys in config2 trump keys in config1,
returns the path of the new merged file.
"""
logging.debug("Merging '{}' '{}'".format(config1, config2))
cfg1 = {}
if config1:
with open(config1) as f:
cfg1 = json.load(f)
cfg2 = {}
if config2:
with open(config2) as f:
cfg2 = json.load(f)
merged_cfg = {key: value for (key, value) in (cfg1.items() + cfg2.items())}
f = tempfile.NamedTemporaryFile(delete=False)
json.dump(merged_cfg, f)
f.close()
logging.debug("merged cfg file: {}".format(f.name))
logging.debug("{}".format(merged_cfg))
return f.name


def find_xcode_path():
"""Return the path to Xcode's Developer directory.
"""