Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ We have a `tbots.py` test runner script in the src folder that will fuzzy find f
1. Build a specific target for running (for example): `./tbots.py build angletest`
2. Run a specific target by running (for example): `./tbots.py run goalietactictest -t`
3. Run a specific *test* by running (for example): `./tbots.py test goalietactictest -t`
4. Run a specific test suite by running (for example): `./tbots.py test simulated_gameplay_tests --suite -t`

where the `-t` flag indicates whether Thunderscope should be launched. Run `./tbots.py --help` for more info

Expand Down
5 changes: 5 additions & 0 deletions src/cli/cli_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class Platform(str, Enum):
Platform, Option("-pl", "--platform", help="The platform to build Thunderloop for")
]

QueryTestSuiteOption = Annotated[
bool,
Option("-s", "--suite", help="Search for test suites instead of bazel targets"),
]

EnableThunderscopeOption = Annotated[bool, Option("-t", "--enable_thunderscope")]
EnableVisualizerOption = Annotated[bool, Option("-v", "--enable_visualizer")]
StopAIOnStartOption = Annotated[bool, Option("-t", "--stop_ai_on_start")]
40 changes: 32 additions & 8 deletions src/tbots.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
EnableThunderscopeOption,
EnableVisualizerOption,
StopAIOnStartOption,
QueryTestSuiteOption,
DebugBinary,
Platform,
)
Expand Down Expand Up @@ -58,6 +59,7 @@ def main(
enable_thunderscope: EnableThunderscopeOption = False,
enable_visualizer: EnableVisualizerOption = False,
stop_ai_on_start: StopAIOnStartOption = False,
query_test_suite: QueryTestSuiteOption = False,
) -> None:
if bool(flash_robots) ^ bool(ssh_password):
print(
Expand All @@ -78,16 +80,36 @@ def main(
# Run the appropriate bazel query and ask thefuzz to find the best matching
# target, guaranteed to return 1 result because we set limit=1
# Combine results of multiple queries with itertools.chain
targets = list(
itertools.chain.from_iterable(
[
run(query, stdout=PIPE).stdout.rstrip(b"\n").split(b"\n")
for query in bazel_queries[action]
]
targets = (
list(
itertools.chain.from_iterable(
[
run(query, stdout=PIPE).stdout.rstrip(b"\n").split(b"\n")
for query in bazel_queries[action]
]
)
)
if not query_test_suite
else []
)
# Create a dictionary to map target names to complete bazel targets
target_dict = {target.split(b":")[-1]: target for target in targets}
target_dict = (
{target.split(b":")[-1]: target for target in targets}
if not query_test_suite
else {
b"simulated_gameplay_tests": b"""//software:unix_full_system \\
//software/simulated_tests/... \\
//software/ai/hl/... \\
//software/ai/navigator/...""",
b"software_tests": b"""-- //... -//software:unix_full_system \\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the -- necessary? It's not present in the simulated_gameplay_tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's required since the command it uses the - to ignore some bazel targets and it doesn't work without having -- first

-//software/simulated_tests/... \\
-//software/ai/hl/... \\
-//software/field_tests/... \\
-//software/ai/navigator/... \\
-//toolchains/cc/... \\
-//software:unix_full_system_tar_gen""",
}
)

# Use thefuzz to find the best matching target name
most_similar_target_name, confidence = process.extract(
Expand All @@ -110,7 +132,7 @@ def main(
target = str(iterfzf.iterfzf(iter(targets)), encoding="utf-8")
print("User selected {}".format(target))

command = ["bazel", action.value, target]
command = ["bazel", action.value]
unknown_args = ctx.args

# Trigger a debug build
Expand Down Expand Up @@ -148,6 +170,8 @@ def main(
if action == ActionArgument.run:
command += ["--"]

command.append(target)

bazel_arguments = unknown_args
if stop_ai_on_start:
bazel_arguments += ["--stop_ai_on_start"]
Expand Down