Commit 7e79b25f authored by Xavier Deguillard's avatar Xavier Deguillard Committed by Facebook GitHub Bot

getdeps: add filtering of tests

Summary:
For large projects, with lots of tests, running all the tests can take a lot
of time, but for quick development iteration, only a subset of the tests may
be needed to run.

On non-Windows platforms, this can be easily achieved by manually executing
the individual tests binaries and use the builtin filtering mechanism of that
test binary to achieve the goal. On Windows, this can quickly become
impossible as DLLs might not be available, and the right PATH would need to
be manually specified by hand to execute the tests binaries[0].

To solve this, let's simply provide a unified way of running specific tests
by passing in a regexp. Both testpilot and CTest do support regex to execute
specific tests. My understanding is that cargo doesn't yet allows regex, but
will in the future.

[0]: And a missing DLLs would produce no output when executed from
     PowerShell, which makes this very confusing.

Reviewed By: wez

Differential Revision: D21484774

fbshipit-source-id: ee32e950e25bb2a498a2b364a447955a917b0590
parent 4103ac13
......@@ -700,6 +700,7 @@ class TestCmd(ProjectCmdBase):
install_dirs,
schedule_type=args.schedule_type,
owner=args.test_owner,
test_filter=args.filter,
)
install_dirs.append(inst_dir)
......@@ -709,6 +710,7 @@ class TestCmd(ProjectCmdBase):
"--schedule-type", help="Indicates how the build was activated"
)
parser.add_argument("--test-owner", help="Owner for testpilot")
parser.add_argument("--filter", help="Only run the tests matching the regex")
@cmd("generate-github-actions", "generate a GitHub actions configuration")
......
......@@ -94,7 +94,7 @@ class BuilderBase(object):
dep_dirs = self.get_dev_run_extra_path_dirs(install_dirs, dep_munger)
dep_munger.emit_dev_run_script(script_path, dep_dirs)
def run_tests(self, install_dirs, schedule_type, owner):
def run_tests(self, install_dirs, schedule_type, owner, test_filter):
""" Execute any tests that we know how to run. If they fail,
raise an exception. """
pass
......@@ -524,7 +524,7 @@ if __name__ == "__main__":
env=env,
)
def run_tests(self, install_dirs, schedule_type, owner):
def run_tests(self, install_dirs, schedule_type, owner, test_filter):
env = self._compute_env(install_dirs)
ctest = path_search(env, "ctest")
cmake = path_search(env, "cmake")
......@@ -665,6 +665,9 @@ if __name__ == "__main__":
else:
runs.append(["--collection", "oss-diff", "--purpose", "diff"])
if test_filter:
testpilot_args += [test_filter]
for run in runs:
self._run_cmd(
testpilot_args + run,
......@@ -673,11 +676,10 @@ if __name__ == "__main__":
use_cmd_prefix=use_cmd_prefix,
)
else:
self._run_cmd(
[ctest, "--output-on-failure", "-j", str(self.build_opts.num_jobs)],
env=env,
use_cmd_prefix=use_cmd_prefix,
)
args = [ctest, "--output-on-failure", "-j", str(self.build_opts.num_jobs)]
if test_filter:
args += ["-R", test_filter]
self._run_cmd(args, env=env, use_cmd_prefix=use_cmd_prefix)
class NinjaBootstrap(BuilderBase):
......@@ -1005,8 +1007,13 @@ git-fetch-with-cli = true
self.run_cargo(install_dirs, "build")
self.recreate_dir(build_source_dir, os.path.join(self.inst_dir, "source"))
def run_tests(self, install_dirs, schedule_type, owner):
self.run_cargo(install_dirs, "test")
def run_tests(self, install_dirs, schedule_type, owner, test_filter):
if test_filter:
args = ["--", test_filter]
else:
args = None
self.run_cargo(install_dirs, "test", args)
if self.build_doc:
self.run_cargo(install_dirs, "doc", ["--no-deps"])
......
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