2019-10-09 18:10:08 +00:00
|
|
|
"""Defines a rule for runtime test targets."""
|
|
|
|
|
|
|
|
load("@io_bazel_rules_go//go:def.bzl", "go_test")
|
2019-06-18 08:40:12 +00:00
|
|
|
|
2019-09-19 00:03:06 +00:00
|
|
|
def runtime_test(
|
2019-10-30 23:14:30 +00:00
|
|
|
name,
|
2019-09-19 00:03:06 +00:00
|
|
|
lang,
|
2019-10-30 23:14:30 +00:00
|
|
|
image_repo = "gcr.io/gvisor-presubmit",
|
|
|
|
image_name = None,
|
|
|
|
blacklist_file = None,
|
2019-09-24 00:42:13 +00:00
|
|
|
shard_count = 50,
|
2019-10-30 23:14:30 +00:00
|
|
|
size = "enormous"):
|
|
|
|
"""Generates sh_test and blacklist test targets for a given runtime.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: The name of the runtime being tested. Typically, the lang + version.
|
|
|
|
This is used in the names of the generated test targets.
|
|
|
|
lang: The language being tested.
|
|
|
|
image_repo: The docker repository containing the proctor image to run.
|
|
|
|
i.e., the prefix to the fully qualified docker image id.
|
|
|
|
image_name: The name of the image in the image_repo.
|
|
|
|
Defaults to the test name.
|
|
|
|
blacklist_file: A test blacklist to pass to the runtime test's runner.
|
|
|
|
shard_count: See Bazel common test attributes.
|
|
|
|
size: See Bazel common test attributes.
|
|
|
|
"""
|
|
|
|
if image_name == None:
|
|
|
|
image_name = name
|
2019-10-01 19:46:54 +00:00
|
|
|
args = [
|
|
|
|
"--lang",
|
|
|
|
lang,
|
|
|
|
"--image",
|
2019-10-30 23:14:30 +00:00
|
|
|
"/".join([image_repo, image_name]),
|
2019-10-01 19:46:54 +00:00
|
|
|
]
|
|
|
|
data = [
|
|
|
|
":runner",
|
|
|
|
]
|
2019-10-30 23:14:30 +00:00
|
|
|
if blacklist_file:
|
2019-10-01 19:46:54 +00:00
|
|
|
args += ["--blacklist_file", "test/runtimes/" + blacklist_file]
|
|
|
|
data += [blacklist_file]
|
|
|
|
|
2019-10-09 18:10:08 +00:00
|
|
|
# Add a test that the blacklist parses correctly.
|
2019-10-30 23:14:30 +00:00
|
|
|
blacklist_test(name, blacklist_file)
|
2019-10-09 18:10:08 +00:00
|
|
|
|
2019-09-19 00:03:06 +00:00
|
|
|
sh_test(
|
2019-10-30 23:14:30 +00:00
|
|
|
name = name + "_test",
|
2019-09-19 00:03:06 +00:00
|
|
|
srcs = ["runner.sh"],
|
2019-10-01 19:46:54 +00:00
|
|
|
args = args,
|
|
|
|
data = data,
|
2019-09-19 00:03:06 +00:00
|
|
|
size = size,
|
|
|
|
shard_count = shard_count,
|
|
|
|
tags = [
|
|
|
|
# Requires docker and runsc to be configured before the test runs.
|
|
|
|
"local",
|
2019-11-01 18:51:50 +00:00
|
|
|
# Don't include test target in wildcard target patterns.
|
|
|
|
"manual",
|
2019-09-19 00:03:06 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2019-10-30 23:14:30 +00:00
|
|
|
def blacklist_test(name, blacklist_file):
|
2019-10-09 18:10:08 +00:00
|
|
|
"""Test that a blacklist parses correctly."""
|
|
|
|
go_test(
|
2019-10-30 23:14:30 +00:00
|
|
|
name = name + "_blacklist_test",
|
2019-10-09 18:10:08 +00:00
|
|
|
embed = [":runner"],
|
|
|
|
srcs = ["blacklist_test.go"],
|
|
|
|
args = ["--blacklist_file", "test/runtimes/" + blacklist_file],
|
|
|
|
data = [blacklist_file],
|
|
|
|
)
|
|
|
|
|
2019-09-19 00:03:06 +00:00
|
|
|
def sh_test(**kwargs):
|
|
|
|
"""Wraps the standard sh_test."""
|
|
|
|
native.sh_test(
|
|
|
|
**kwargs
|
|
|
|
)
|