diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e557f2d2a5..7080adbade 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,6 @@ jobs: cd src bazel build --show_timestamps --copt=-O3 --verbose_failures \ -- //... -//software:unix_full_system \ - -//software/simulated_tests/... \ -//software/ai/hl/... \ -//software/field_tests/... \ -//software/embedded/... \ @@ -52,7 +51,6 @@ jobs: cd src bazel test --copt=-O3 --show_timestamps --verbose_failures \ -- //... -//software:unix_full_system \ - -//software/simulated_tests/... \ -//software/ai/hl/... \ -//software/field_tests/... \ -//software/ai/navigator/... \ @@ -87,7 +85,6 @@ jobs: cd src bazel test --copt=-O3 --flaky_test_attempts=3 --show_timestamps \ //software:unix_full_system \ - //software/simulated_tests/... \ //software/ai/hl/... \ //software/ai/navigator/... diff --git a/scripts/compile_pip_requirements.sh b/scripts/compile_pip_requirements.sh index baa1946e74..2e76cb9b13 100755 --- a/scripts/compile_pip_requirements.sh +++ b/scripts/compile_pip_requirements.sh @@ -17,6 +17,6 @@ BAZEL_ROOT_DIR="$CURR_DIR/../src" cd $BAZEL_ROOT_DIR bazel run //software/thunderscope:requirements.update bazel run //software/embedded/ansible:requirements.update -bazel run //software/simulated_tests:requirements.update +bazel run //software/gameplay_tests:requirements.update bazel run //software/embedded/robot_diagnostics_cli:requirements.update bazel run //starlark/nanopb:requirements.update diff --git a/src/MODULE.bazel b/src/MODULE.bazel index 323fd7de00..853820601d 100644 --- a/src/MODULE.bazel +++ b/src/MODULE.bazel @@ -50,12 +50,12 @@ pip.parse( ) use_repo(pip, "ansible_deps") pip.parse( - hub_name = "simulated_tests_deps", + hub_name = "gameplay_tests_deps", python_interpreter = "/opt/tbotspython/bin/python", python_version = "3.12", - requirements_lock = "//software/simulated_tests:requirements_lock.txt", + requirements_lock = "//software/gameplay_tests:requirements_lock.txt", ) -use_repo(pip, "simulated_tests_deps") +use_repo(pip, "gameplay_tests_deps") pip.parse( hub_name = "robot_diagnostics_cli_deps", python_interpreter = "/opt/tbotspython/bin/python", diff --git a/src/software/BUILD b/src/software/BUILD index dbafc6f2e8..5f410e59ff 100644 --- a/src/software/BUILD +++ b/src/software/BUILD @@ -125,7 +125,6 @@ py_library( name = "conftest", srcs = ["conftest.py"], deps = [ - "//software/field_tests:field_test_fixture", - "//software/simulated_tests:simulated_test_fixture", + "//software/gameplay_tests:fixture", ], ) diff --git a/src/software/ai/hl/stp/play/BUILD b/src/software/ai/hl/stp/play/BUILD index a74371ace5..9f40f8cc8f 100644 --- a/src/software/ai/hl/stp/play/BUILD +++ b/src/software/ai/hl/stp/play/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -82,7 +82,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) @@ -100,7 +100,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) @@ -156,7 +156,7 @@ py_test( "//proto:software_py_proto", "//proto:tbots_py_proto", "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/ball_placement/BUILD b/src/software/ai/hl/stp/play/ball_placement/BUILD index 6621cec3d4..2258fee4b2 100644 --- a/src/software/ai/hl/stp/play/ball_placement/BUILD +++ b/src/software/ai/hl/stp/play/ball_placement/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -40,7 +40,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/ball_placement/ball_placement_play_test.py b/src/software/ai/hl/stp/play/ball_placement/ball_placement_play_test.py index 77e4e196ab..100a22e459 100644 --- a/src/software/ai/hl/stp/play/ball_placement/ball_placement_play_test.py +++ b/src/software/ai/hl/stp/play/ball_placement/ball_placement_play_test.py @@ -5,14 +5,14 @@ from proto.import_all_protos import * from proto.ssl_gc_common_pb2 import Team from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_enters_region import ( +from software.gameplay_tests.validation.ball_enters_region import ( BallAlwaysStaysInRegion, BallEventuallyEntersRegion, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( RobotEventuallyExitsRegion, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -33,10 +33,10 @@ ], ) def test_two_ai_ball_placement( - simulated_test_runner, ball_start_point, ball_placement_point + gameplay_test_runner, ball_start_point, ball_placement_point ): run_ball_placement_scenario( - simulated_test_runner, ball_start_point, ball_placement_point + gameplay_test_runner, ball_start_point, ball_placement_point ) @@ -64,21 +64,21 @@ def test_two_ai_ball_placement( ], ) def test_robocup_technical_challenge_placement( - simulated_test_runner, ball_start_point, ball_placement_point + gameplay_test_runner, ball_start_point, ball_placement_point ): run_ball_placement_scenario( - simulated_test_runner, ball_start_point, ball_placement_point, blue_only=True + gameplay_test_runner, ball_start_point, ball_placement_point, blue_only=True ) def ball_placement_play_setup( - ball_start_point, ball_placement_point, simulated_test_runner, blue_only + ball_start_point, ball_placement_point, gameplay_test_runner, blue_only ): """Set up ball placement test by initializing bot positions, ball placement targets, and test settings :param ball_start_point: Initial point of the ball :param ball_placement_point: Target point of the ball - :param simulated_test_runner: Simulated test runner + :param gameplay_test_runner: Simulated test runner :param blue_only: If True, only the blue team is active; the yellow team is ignored. """ # Setup blue robots @@ -113,7 +113,7 @@ def ball_placement_play_setup( ] # Create world state - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -123,28 +123,28 @@ def ball_placement_play_setup( ) # Game Controller Setup - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) # Pass in placement point here - not required for all play tests - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.BALL_PLACEMENT, team=Team.BLUE, final_ball_placement_point=ball_placement_point, ) # Force play override here - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.BallPlacementPlay, yellow_play=PlayName.HaltPlay ) def run_ball_placement_scenario( - simulated_test_runner, ball_start_point, ball_placement_point, blue_only=False + gameplay_test_runner, ball_start_point, ball_placement_point, blue_only=False ): """Runs a ball placement test scenario with the specified parameters. - :param simulated_test_runner: The test runner used to simulate robot and ball behavior. + :param gameplay_test_runner: The test runner used to simulate robot and ball behavior. :param ball_start_point: The initial position of the ball. :param ball_placement_point: The target position where the ball should be placed. :param blue_only: If True, only the blue team is active; the yellow team is ignored. @@ -183,33 +183,22 @@ def run_ball_placement_scenario( ] ] - simulated_test_runner.run_test( - setup=lambda test_setup_arg: ball_placement_play_setup( - test_setup_arg["ball_start_point"], - test_setup_arg["ball_placement_point"], - simulated_test_runner, + gameplay_test_runner.run_test( + setup=lambda: ball_placement_play_setup( + ball_start_point, + ball_placement_point, + gameplay_test_runner, blue_only, ), - params=[ - { - "ball_start_point": ball_start_point, - "ball_placement_point": ball_placement_point, - } - ], - inv_always_validation_sequence_set=[[]], - inv_eventually_validation_sequence_set=placement_eventually_validation_sequence_set, - ag_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=placement_eventually_validation_sequence_set, - test_timeout_s=[15], + eventually_validation_sequence_set=placement_eventually_validation_sequence_set, + test_timeout_s=15, ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( # setup argument isn't passed to preserve world state from previous test run - inv_always_validation_sequence_set=drop_ball_always_validation_sequence_set, - inv_eventually_validation_sequence_set=drop_ball_eventually_validation_sequence_set, - ag_always_validation_sequence_set=drop_ball_always_validation_sequence_set, - ag_eventually_validation_sequence_set=drop_ball_eventually_validation_sequence_set, - test_timeout_s=[5], + always_validation_sequence_set=drop_ball_always_validation_sequence_set, + eventually_validation_sequence_set=drop_ball_eventually_validation_sequence_set, + test_timeout_s=5, ) diff --git a/src/software/ai/hl/stp/play/crease_defense/BUILD b/src/software/ai/hl/stp/play/crease_defense/BUILD index ca6980db81..eca2d78c1e 100644 --- a/src/software/ai/hl/stp/play/crease_defense/BUILD +++ b/src/software/ai/hl/stp/play/crease_defense/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -39,7 +39,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/crease_defense/crease_defense_play_test.py b/src/software/ai/hl/stp/play/crease_defense/crease_defense_play_test.py index 10dd36212d..ed805f5c07 100644 --- a/src/software/ai/hl/stp/play/crease_defense/crease_defense_play_test.py +++ b/src/software/ai/hl/stp/play/crease_defense/crease_defense_play_test.py @@ -3,24 +3,24 @@ from proto.import_all_protos import * from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -from software.simulated_tests.validation.robot_speed_threshold import ( +from software.gameplay_tests.validation.robot_speed_threshold import ( RobotSpeedEventuallyBelowThreshold, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( NumberOfRobotsEventuallyEntersRegion, ) -from software.simulated_tests.validation.delay_validation import DelayValidation +from software.gameplay_tests.validation.delay_validation import DelayValidation -def test_crease_defense_play(simulated_test_runner): +def test_crease_defense_play(gameplay_test_runner): field = tbots_cpp.Field.createSSLDivisionBField() goalie_position = tbots_cpp.Point(-4.5, 0) - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ goalie_position, @@ -43,11 +43,11 @@ def setup(*args): ), ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.CreaseDefensePlay, yellow_play=PlayName.HaltPlay ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) @@ -70,10 +70,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/defense/BUILD b/src/software/ai/hl/stp/play/defense/BUILD index 2f2d8de10e..46b7731aef 100644 --- a/src/software/ai/hl/stp/play/defense/BUILD +++ b/src/software/ai/hl/stp/play/defense/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -42,7 +42,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/defense/defense_play_test.py b/src/software/ai/hl/stp/play/defense/defense_play_test.py index 07e29ed85b..5af0e21a86 100644 --- a/src/software/ai/hl/stp/play/defense/defense_play_test.py +++ b/src/software/ai/hl/stp/play/defense/defense_play_test.py @@ -2,13 +2,13 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.friendly_has_ball_possession import ( +from software.gameplay_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.friendly_has_ball_possession import ( FriendlyEventuallyHasBallPossession, ) from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -35,11 +35,11 @@ ) ], ) -def test_defense_play_ball_steal(simulated_test_runner, blue_bots, yellow_bots): - def setup(*args): +def test_defense_play_ball_steal(gameplay_test_runner, blue_bots, yellow_bots): + def setup(): ball_initial_pos = tbots_cpp.Point(0.93, 0) - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -48,32 +48,29 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.DefensePlay, yellow_play=PlayName.HaltPlay ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - params=[0, 1, 2, 3, 4], # The aggregate test runs 5 times - inv_always_validation_sequence_set=[ + always_validation_sequence_set=[ [ BallNeverEntersRegion( regions=[tbots_cpp.Field.createSSLDivisionBField().friendlyGoal()] ) ] ], - inv_eventually_validation_sequence_set=[ + eventually_validation_sequence_set=[ [FriendlyEventuallyHasBallPossession(tolerance=0.2)] ], - ag_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=[[]], test_timeout_s=20, ) @@ -100,11 +97,11 @@ def setup(*args): ) ], ) -def test_defense_play(simulated_test_runner, blue_bots, yellow_bots): - def setup(*args): +def test_defense_play(gameplay_test_runner, blue_bots, yellow_bots): + def setup(): ball_initial_pos = tbots_cpp.Point(0.9, 2.85) - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -113,32 +110,29 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.DefensePlay, yellow_play=PlayName.ShootOrPassPlay ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - params=[0, 1, 2, 3, 4], # The aggregate test runs 5 times - inv_always_validation_sequence_set=[ + always_validation_sequence_set=[ [ BallNeverEntersRegion( regions=[tbots_cpp.Field.createSSLDivisionBField().friendlyGoal()] ) ] ], - inv_eventually_validation_sequence_set=[ + eventually_validation_sequence_set=[ [FriendlyEventuallyHasBallPossession(tolerance=0.1)] ], - ag_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=[[]], test_timeout_s=30, ) diff --git a/src/software/ai/hl/stp/play/enemy_ball_placement/BUILD b/src/software/ai/hl/stp/play/enemy_ball_placement/BUILD index de72dcf77f..42570608d9 100644 --- a/src/software/ai/hl/stp/play/enemy_ball_placement/BUILD +++ b/src/software/ai/hl/stp/play/enemy_ball_placement/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -31,7 +31,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/enemy_ball_placement/enemy_ball_placement_play_test.py b/src/software/ai/hl/stp/play/enemy_ball_placement/enemy_ball_placement_play_test.py index 686f71d1a5..b2cf5585f9 100644 --- a/src/software/ai/hl/stp/play/enemy_ball_placement/enemy_ball_placement_play_test.py +++ b/src/software/ai/hl/stp/play/enemy_ball_placement/enemy_ball_placement_play_test.py @@ -2,8 +2,8 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.robot_enters_placement_region import * -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.validation.robot_enters_placement_region import * +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state @@ -20,9 +20,9 @@ ], ) def test_two_ai_ball_placement( - simulated_test_runner, ball_start_point, ball_placement_point + gameplay_test_runner, ball_start_point, ball_placement_point ): - def setup(*args): + def setup(): blue_bots = [ tbots_cpp.Point(-4.5, 0), tbots_cpp.Point(-4, 0.5), @@ -45,7 +45,7 @@ def setup(*args): .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -54,16 +54,16 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.BALL_PLACEMENT, team=Team.YELLOW, final_ball_placement_point=ball_placement_point, ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.EnemyBallPlacementPlay, yellow_play=PlayName.BallPlacementPlay, ) @@ -72,13 +72,9 @@ def setup(*args): [RobotNeverEntersPlacementRegion(ball_placement_point)] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - params=[0], - inv_always_validation_sequence_set=always_validation_sequence_set, - inv_eventually_validation_sequence_set=[[]], - ag_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=[[]], + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=15, ) diff --git a/src/software/ai/hl/stp/play/enemy_free_kick/BUILD b/src/software/ai/hl/stp/play/enemy_free_kick/BUILD index ca05d2fd7f..cd32aceafc 100644 --- a/src/software/ai/hl/stp/play/enemy_free_kick/BUILD +++ b/src/software/ai/hl/stp/play/enemy_free_kick/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -45,7 +45,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/enemy_free_kick/enemy_free_kick_play_test.py b/src/software/ai/hl/stp/play/enemy_free_kick/enemy_free_kick_play_test.py index 2ee008c340..6b08210f5b 100644 --- a/src/software/ai/hl/stp/play/enemy_free_kick/enemy_free_kick_play_test.py +++ b/src/software/ai/hl/stp/play/enemy_free_kick/enemy_free_kick_play_test.py @@ -3,17 +3,17 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.or_validation import OrValidation +from software.gameplay_tests.validation.or_validation import OrValidation -from software.simulated_tests.validation.friendly_team_scored import * -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.friendly_team_scored import * +from software.gameplay_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.robot_enters_region import ( RobotEventuallyEntersRegion, RobotNeverEntersRegion, ) from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -97,10 +97,10 @@ "Disabling this test because OrValidation is passed both an always validation and eventually validation" ) def test_enemy_free_kick_play( - simulated_test_runner, blue_bots, yellow_bots, ball_initial_pos + gameplay_test_runner, blue_bots, yellow_bots, ball_initial_pos ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -109,14 +109,14 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.DIRECT, team=Team.YELLOW ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.EnemyFreeKickPlay, yellow_play=PlayName.FreeKickPlay ) @@ -141,13 +141,10 @@ def setup(*args): [RobotEventuallyEntersRegion(regions=[tbots_cpp.Circle(ball_initial_pos, 1)])] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - params=[0, 1, 2], - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=8, ) diff --git a/src/software/ai/hl/stp/play/example/BUILD b/src/software/ai/hl/stp/play/example/BUILD index 1b1f1de048..709a3d4121 100644 --- a/src/software/ai/hl/stp/play/example/BUILD +++ b/src/software/ai/hl/stp/play/example/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -41,7 +41,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/example/example_play_test.py b/src/software/ai/hl/stp/play/example/example_play_test.py index 9fbede9cf6..8c030a9ce0 100644 --- a/src/software/ai/hl/stp/play/example/example_play_test.py +++ b/src/software/ai/hl/stp/play/example/example_play_test.py @@ -1,5 +1,5 @@ import software.python_bindings as tbots_cpp -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( NumberOfRobotsEventuallyExitsRegion, NumberOfRobotsEventuallyEntersRegion, ) @@ -7,15 +7,15 @@ from proto.ssl_gc_common_pb2 import Team from proto.play_pb2 import PlayName from proto.import_all_protos import Command -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -def test_example_play(simulated_test_runner): +def test_example_play(gameplay_test_runner): ball_initial_pos = tbots_cpp.Point(0, 0) - def setup(*args): + def setup(): blue_bots = [ tbots_cpp.Point(-3, 2.5), tbots_cpp.Point(-3, 1.5), @@ -38,7 +38,7 @@ def setup(*args): .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -47,17 +47,17 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.NORMAL_START, team=Team.BLUE ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.DIRECT, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.ExamplePlay, yellow_play=PlayName.HaltPlay ) @@ -72,10 +72,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/free_kick/BUILD b/src/software/ai/hl/stp/play/free_kick/BUILD index bf0f2ee4df..1d1186aaf9 100644 --- a/src/software/ai/hl/stp/play/free_kick/BUILD +++ b/src/software/ai/hl/stp/play/free_kick/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -40,7 +40,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/free_kick/free_kick_play_test.py b/src/software/ai/hl/stp/play/free_kick/free_kick_play_test.py index 264d6ff9f3..2e4e186fee 100644 --- a/src/software/ai/hl/stp/play/free_kick/free_kick_play_test.py +++ b/src/software/ai/hl/stp/play/free_kick/free_kick_play_test.py @@ -7,16 +7,16 @@ from proto.ssl_gc_common_pb2 import Team from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.friendly_team_scored import ( +from software.gameplay_tests.validation.friendly_team_scored import ( FriendlyTeamEventuallyScored, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( RobotEventuallyEntersRegion, ) -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -31,8 +31,8 @@ (tbots_cpp.Point(1.5, 0.5), True), ], ) -def test_free_kick_play_friendly(ball_initial_pos, must_score, simulated_test_runner): - def setup(*args): +def test_free_kick_play_friendly(ball_initial_pos, must_score, gameplay_test_runner): + def setup(): blue_bots = [ tbots_cpp.Point(-4.5, 0), tbots_cpp.Point(-3, 1.5), @@ -53,7 +53,7 @@ def setup(*args): .enemyDefenseArea() .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_bots, yellow_robot_locations=yellow_bots, @@ -62,17 +62,17 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.NORMAL_START, team=Team.BLUE ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.DIRECT, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.FreeKickPlay, yellow_play=PlayName.HaltPlay ) @@ -89,10 +89,9 @@ def setup(*args): ], ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/halt_play/BUILD b/src/software/ai/hl/stp/play/halt_play/BUILD index f67983bfc4..81c3ad55ad 100644 --- a/src/software/ai/hl/stp/play/halt_play/BUILD +++ b/src/software/ai/hl/stp/play/halt_play/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -43,7 +43,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/halt_play/halt_play_test.py b/src/software/ai/hl/stp/play/halt_play/halt_play_test.py index 1d7412c750..38a92593ce 100644 --- a/src/software/ai/hl/stp/play/halt_play/halt_play_test.py +++ b/src/software/ai/hl/stp/play/halt_play/halt_play_test.py @@ -1,16 +1,16 @@ import software.python_bindings as tbots_cpp -from software.simulated_tests.validation.robot_speed_threshold import * +from software.gameplay_tests.validation.robot_speed_threshold import * from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) # TODO issue #2599 - Remove Duration parameter from test # @pytest.mark.parametrize("run_enemy_ai,test_duration", [(False, 20), (True, 20)]) -def test_halt_play(simulated_test_runner): - def setup(*args): +def test_halt_play(gameplay_test_runner): + def setup(): ball_initial_pos = tbots_cpp.Point(0, 0) blue_bots = [ @@ -35,7 +35,7 @@ def setup(*args): .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -44,25 +44,16 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.UNKNOWN ) - # params just have to be a list of length 1 to ensure the test runs at least once - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - params=[0], - inv_always_validation_sequence_set=[[]], - inv_eventually_validation_sequence_set=[ - [RobotSpeedEventuallyBelowThreshold(1e-3)] - ], - ag_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=[ - [RobotSpeedEventuallyBelowThreshold(1e-3)] - ], + eventually_validation_sequence_set=[[RobotSpeedEventuallyBelowThreshold(1e-3)]], ci_cmd_with_delay=[ (3, Command.Type.HALT, Team.BLUE), (3, Command.Type.HALT, Team.YELLOW), diff --git a/src/software/ai/hl/stp/play/kickoff_enemy/BUILD b/src/software/ai/hl/stp/play/kickoff_enemy/BUILD index 409b7ba865..4d1a520603 100644 --- a/src/software/ai/hl/stp/play/kickoff_enemy/BUILD +++ b/src/software/ai/hl/stp/play/kickoff_enemy/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -32,7 +32,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/kickoff_enemy/kickoff_enemy_play_test.py b/src/software/ai/hl/stp/play/kickoff_enemy/kickoff_enemy_play_test.py index ce8968de8f..08753d4ca5 100644 --- a/src/software/ai/hl/stp/play/kickoff_enemy/kickoff_enemy_play_test.py +++ b/src/software/ai/hl/stp/play/kickoff_enemy/kickoff_enemy_play_test.py @@ -3,26 +3,26 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( NumberOfRobotsEventuallyEntersRegion, NumberOfRobotsAlwaysStaysInRegion, RobotNeverEntersRegion, ) -from software.simulated_tests.validation.or_validation import OrValidation -from software.simulated_tests.validation.ball_enters_region import BallNeverEntersRegion +from software.gameplay_tests.validation.or_validation import OrValidation +from software.gameplay_tests.validation.ball_enters_region import BallNeverEntersRegion from proto.message_translation.tbots_protobuf import create_world_state from proto.import_all_protos import Command from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -def test_kickoff_enemy_play(simulated_test_runner): +def test_kickoff_enemy_play(gameplay_test_runner): ball_initial_pos = tbots_cpp.Point(0, 0) field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): + def setup(): blue_bots = [ tbots_cpp.Point(-3, 2.5), tbots_cpp.Point(-2.8, 2.5), @@ -41,7 +41,7 @@ def setup(*args): field.enemyDefenseArea().negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_bots, yellow_robot_locations=yellow_bots, @@ -50,22 +50,22 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.KICKOFF, team=Team.YELLOW ) # Let robots get ready before starting kickoff threading.Timer( 4.0, - lambda: simulated_test_runner.send_gamecontroller_command( + lambda: gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.NORMAL_START, team=Team.YELLOW ), ).start() - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.KickoffEnemyPlay, yellow_play=PlayName.KickoffFriendlyPlay, ) @@ -138,12 +138,10 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/kickoff_friendly/BUILD b/src/software/ai/hl/stp/play/kickoff_friendly/BUILD index 35325ce76a..b04c36bf90 100644 --- a/src/software/ai/hl/stp/play/kickoff_friendly/BUILD +++ b/src/software/ai/hl/stp/play/kickoff_friendly/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -31,7 +31,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_test.py b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_test.py index a7e33d5d34..87515802eb 100644 --- a/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_test.py +++ b/src/software/ai/hl/stp/play/kickoff_friendly/kickoff_friendly_play_test.py @@ -3,29 +3,29 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( NumberOfRobotsEventuallyEntersRegion, NumberOfRobotsAlwaysStaysInRegion, NumberOfRobotsNeverEntersRegion, RobotEventuallyEntersRegion, ) -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.validation.ball_enters_region import BallNeverEntersRegion -from software.simulated_tests.validation.or_validation import OrValidation +from software.gameplay_tests.validation.ball_enters_region import BallNeverEntersRegion +from software.gameplay_tests.validation.or_validation import OrValidation from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team from proto.import_all_protos import Command -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -def test_kickoff_friendly_play(simulated_test_runner): +def test_kickoff_friendly_play(gameplay_test_runner): ball_initial_pos = tbots_cpp.Point(0, 0) - def setup(*args): + def setup(): field = tbots_cpp.Field.createSSLDivisionBField() blue_bots = [ @@ -46,7 +46,7 @@ def setup(*args): field.enemyDefenseArea().negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_bots, yellow_robot_locations=yellow_bots, @@ -55,22 +55,22 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.KICKOFF, team=Team.BLUE ) # Let robots get ready before starting kickoff threading.Timer( 4.0, - lambda: simulated_test_runner.send_gamecontroller_command( + lambda: gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.NORMAL_START, team=Team.BLUE ), ).start() - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.KickoffFriendlyPlay, yellow_play=PlayName.KickoffEnemyPlay, ) @@ -138,12 +138,10 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/kickoff_play_test.py b/src/software/ai/hl/stp/play/kickoff_play_test.py index f56f5eb8dd..80cbc15057 100644 --- a/src/software/ai/hl/stp/play/kickoff_play_test.py +++ b/src/software/ai/hl/stp/play/kickoff_play_test.py @@ -2,22 +2,22 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.robot_enters_region import * -from software.simulated_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.robot_enters_region import * +from software.gameplay_tests.validation.ball_enters_region import * from proto.import_all_protos import * from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -from software.simulated_tests.validation.or_validation import OrValidation +from software.gameplay_tests.validation.or_validation import OrValidation @pytest.mark.parametrize("is_friendly_test", [True, False]) -def test_kickoff_play(simulated_test_runner, is_friendly_test): +def test_kickoff_play(gameplay_test_runner, is_friendly_test): ball_initial_pos = tbots_cpp.Point(0, 0) - def setup(*args): + def setup(): blue_bots = [ tbots_cpp.Point(-3, 2.5), tbots_cpp.Point(-3, 1.5), @@ -40,7 +40,7 @@ def setup(*args): .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -49,28 +49,28 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) if is_friendly_test: - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.KICKOFF, team=Team.BLUE ) blue_play = PlayName.KickoffFriendlyPlay yellow_play = PlayName.KickoffEnemyPlay else: - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.KICKOFF, team=Team.YELLOW ) blue_play = PlayName.KickoffEnemyPlay yellow_play = PlayName.KickoffFriendlyPlay - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.NORMAL_START, team=Team.BLUE ) - simulated_test_runner.set_plays(blue_play=blue_play, yellow_play=yellow_play) + gameplay_test_runner.set_plays(blue_play=blue_play, yellow_play=yellow_play) # TODO (#3650): fix validation logic @@ -136,10 +136,10 @@ def setup(*args): ) ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/offense/BUILD b/src/software/ai/hl/stp/play/offense/BUILD index 930f5d13d6..ee7995a153 100644 --- a/src/software/ai/hl/stp/play/offense/BUILD +++ b/src/software/ai/hl/stp/play/offense/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -39,7 +39,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/offense/offense_play_test.py b/src/software/ai/hl/stp/play/offense/offense_play_test.py index 29f49b039a..4ddfb9a82b 100644 --- a/src/software/ai/hl/stp/play/offense/offense_play_test.py +++ b/src/software/ai/hl/stp/play/offense/offense_play_test.py @@ -1,19 +1,19 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.validation.friendly_team_scored import * -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.friendly_has_ball_possession import * -from software.simulated_tests.validation.excessive_dribbling import * +from software.gameplay_tests.validation.friendly_team_scored import * +from software.gameplay_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.friendly_has_ball_possession import * +from software.gameplay_tests.validation.excessive_dribbling import * from proto.message_translation.tbots_protobuf import create_world_state from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -def test_offense_play(simulated_test_runner): - def setup(start_point): - ball_initial_pos = start_point +def test_offense_play(gameplay_test_runner): + def setup(): + ball_initial_pos = tbots_cpp.Point(-4.4, 2.9) blue_bots = [ tbots_cpp.Point(-4.5, 3.0), @@ -37,7 +37,7 @@ def setup(start_point): .negXPosYCorner(), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=yellow_bots, blue_robot_locations=blue_bots, @@ -46,38 +46,28 @@ def setup(start_point): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.OffensePlay, yellow_play=PlayName.HaltPlay ) field = tbots_cpp.Field.createSSLDivisionBField() # Always Validation - inv_always_validation_sequence_set = [ + always_validation_sequence_set = [ [BallAlwaysStaysInRegion(regions=[field.fieldBoundary()])], [NeverExcessivelyDribbles()], ] - ag_always_validation_sequence_set = [[FriendlyAlwaysHasBallPossession()]] - - # Eventually Validation - inv_eventually_validation_sequence_set = [[]] - ag_eventually_validation_sequence_set = [[FriendlyTeamEventuallyScored()]] - - simulated_test_runner.run_test( - params=[tbots_cpp.Point(-4.4, 2.9)], + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=inv_eventually_validation_sequence_set, - inv_always_validation_sequence_set=inv_always_validation_sequence_set, - ag_eventually_validation_sequence_set=ag_eventually_validation_sequence_set, - ag_always_validation_sequence_set=ag_always_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=15, run_till_end=True, ) diff --git a/src/software/ai/hl/stp/play/passing_sim_test.py b/src/software/ai/hl/stp/play/passing_sim_test.py index bf915965fd..f549a9aded 100644 --- a/src/software/ai/hl/stp/play/passing_sim_test.py +++ b/src/software/ai/hl/stp/play/passing_sim_test.py @@ -1,20 +1,20 @@ import pytest import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.friendly_receives_ball_slow import ( +from software.gameplay_tests.validation.friendly_receives_ball_slow import ( FriendlyAlwaysReceivesBallSlow, ) -from software.simulated_tests.validation.friendly_has_ball_possession import ( +from software.gameplay_tests.validation.friendly_has_ball_possession import ( FriendlyEventuallyHasBallPossession, ) -from software.simulated_tests.validation.ball_moves_in_direction import ( +from software.gameplay_tests.validation.ball_moves_in_direction import ( BallMovesForwardInRegions, ) -from software.simulated_tests.validation.ball_enters_region import ( +from software.gameplay_tests.validation.ball_enters_region import ( BallEventuallyExitsRegion, BallEventuallyEntersRegion, ) @@ -28,7 +28,7 @@ def setup_pass_and_robots( friendly_orientations, enemy_robot_positions, receive_pass, - simulated_test_runner, + gameplay_test_runner, ): """Sets up a test involving 1 robot passing the ball With any number of friendly and enemy robots on the field @@ -40,13 +40,13 @@ def setup_pass_and_robots( :param friendly_orientations: the orientations of the friendly robots :param enemy_robot_positions: the positions of the enemy robots :param receive_pass: whether a friendly robot should try to receive the pass - :param simulated_test_runner: the test runner + :param gameplay_test_runner: the test runner :return: the best pass we generate """ blue_robot_locations = [attacker_robot_position, *receiver_robot_positions] # Setup the world state - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=enemy_robot_positions, blue_robot_locations=blue_robot_locations, @@ -139,7 +139,7 @@ def setup_pass_and_robots( blue_tactics[1] = ReceiverTactic(**receiver_args) - simulated_test_runner.set_tactics(blue_tactics=blue_tactics, yellow_tactics=None) + gameplay_test_runner.set_tactics(blue_tactics=blue_tactics, yellow_tactics=None) return best_pass @@ -227,7 +227,7 @@ def test_passing_receive_speed( receiver_robot_positions, friendly_orientations, enemy_robot_positions, - simulated_test_runner, + gameplay_test_runner, ): # Eventually Validation eventually_validation_sequence_set = [ @@ -245,20 +245,19 @@ def test_passing_receive_speed( [FriendlyAlwaysReceivesBallSlow(robot_id=1, max_receive_speed=2.1)], ] - simulated_test_runner.run_test( - setup=lambda param: setup_pass_and_robots( + gameplay_test_runner.run_test( + setup=lambda: setup_pass_and_robots( ball_initial_position=ball_initial_position, ball_initial_velocity=ball_initial_velocity, attacker_robot_position=attacker_robot_position, receiver_robot_positions=receiver_robot_positions, friendly_orientations=friendly_orientations, enemy_robot_positions=enemy_robot_positions, - simulated_test_runner=simulated_test_runner, + gameplay_test_runner=gameplay_test_runner, receive_pass=True, ), - params=[0], - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, run_till_end=False, ) @@ -342,7 +341,7 @@ def test_passing_no_backwards_passes( receiver_robot_positions, friendly_orientations, enemy_robot_positions, - simulated_test_runner, + gameplay_test_runner, ): field = tbots_cpp.Field.createSSLDivisionBField() best_pass = setup_pass_and_robots( @@ -353,7 +352,7 @@ def test_passing_no_backwards_passes( friendly_orientations=friendly_orientations, enemy_robot_positions=enemy_robot_positions, receive_pass=True, - simulated_test_runner=simulated_test_runner, + gameplay_test_runner=gameplay_test_runner, ) # Eventually Validation @@ -381,9 +380,9 @@ def test_passing_no_backwards_passes( ], ] - simulated_test_runner.run_test( - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, + gameplay_test_runner.run_test( + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, run_till_end=False, ) diff --git a/src/software/ai/hl/stp/play/penalty_kick_enemy/BUILD b/src/software/ai/hl/stp/play/penalty_kick_enemy/BUILD index b83140a6e5..99224e202b 100644 --- a/src/software/ai/hl/stp/play/penalty_kick_enemy/BUILD +++ b/src/software/ai/hl/stp/play/penalty_kick_enemy/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -40,7 +40,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/penalty_kick_enemy/penalty_kick_enemy_play_test.py b/src/software/ai/hl/stp/play/penalty_kick_enemy/penalty_kick_enemy_play_test.py index 366518b3bb..83ce5e85fa 100644 --- a/src/software/ai/hl/stp/play/penalty_kick_enemy/penalty_kick_enemy_play_test.py +++ b/src/software/ai/hl/stp/play/penalty_kick_enemy/penalty_kick_enemy_play_test.py @@ -4,19 +4,19 @@ from software.py_constants import ROBOT_MAX_RADIUS_METERS from proto.play_pb2 import PlayName -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( NumberOfRobotsEventuallyEntersRegion, ) -from software.simulated_tests.validation.robot_at_position import ( +from software.gameplay_tests.validation.robot_at_position import ( RobotEventuallyAtPosition, ) -from software.simulated_tests.validation.robot_at_orientation import ( +from software.gameplay_tests.validation.robot_at_orientation import ( RobotEventuallyAtOrientation, ) from proto.message_translation.tbots_protobuf import create_world_state from proto.import_all_protos import Command from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -97,13 +97,13 @@ def test_penalty_kick_enemy_play_setup( friendly_robot_positions, enemy_distance_behind_ball, - simulated_test_runner, + gameplay_test_runner, ): field = tbots_cpp.Field.createSSLDivisionBField() ball_initial_pos = field.enemyPenaltyMark() enemy_penalty_x = ball_initial_pos.x() - def setup(*args): + def setup(): # Enemy robots behind the penalty mark yellow_bots = [ tbots_cpp.Point(enemy_penalty_x + 0.3, 0), # kicker robot @@ -126,7 +126,7 @@ def setup(*args): ), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=friendly_robot_positions, yellow_robot_locations=yellow_bots, @@ -135,14 +135,14 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.HALT, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.PENALTY, team=Team.YELLOW ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.PenaltyKickEnemyPlay, yellow_play=PlayName.HaltPlay, ) @@ -171,10 +171,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=20, ) diff --git a/src/software/ai/hl/stp/play/shoot_or_chip/BUILD b/src/software/ai/hl/stp/play/shoot_or_chip/BUILD index 2d74dd1993..a6b275c7f5 100644 --- a/src/software/ai/hl/stp/play/shoot_or_chip/BUILD +++ b/src/software/ai/hl/stp/play/shoot_or_chip/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -42,7 +42,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_test.py b/src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_test.py index 7c07dd531c..7c9b12fd06 100644 --- a/src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_test.py +++ b/src/software/ai/hl/stp/play/shoot_or_chip/shoot_or_chip_play_test.py @@ -3,7 +3,7 @@ import software.python_bindings as tbots_cpp from proto.play_pb2 import PlayName -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) from proto.import_all_protos import * @@ -12,8 +12,8 @@ from proto.geometry_pb2 import Point, Vector, Angle, AngularVelocity -def test_shoot_or_chip_play(simulated_test_runner): - def setup(*args): +def test_shoot_or_chip_play(gameplay_test_runner): + def setup(): ball_initial_pos = tbots_cpp.Point(-1.4, 2) ball_initial_vel = tbots_cpp.Vector(0, 0) @@ -48,24 +48,22 @@ def setup(*args): world_state.yellow_robots[5].CopyFrom(last_robot) - simulated_test_runner.set_world_state(world_state) + gameplay_test_runner.set_world_state(world_state) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.ShootOrChipPlay, yellow_play=PlayName.HaltPlay ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) # TODO (#3651): add validations - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=[[]], test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/play/shoot_or_pass/BUILD b/src/software/ai/hl/stp/play/shoot_or_pass/BUILD index bc366bd8a0..3824dadbdc 100644 --- a/src/software/ai/hl/stp/play/shoot_or_pass/BUILD +++ b/src/software/ai/hl/stp/play/shoot_or_pass/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -58,7 +58,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_test.py b/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_test.py index 25bcd71c33..1f69af1708 100644 --- a/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_test.py +++ b/src/software/ai/hl/stp/play/shoot_or_pass/shoot_or_pass_play_test.py @@ -5,20 +5,20 @@ from proto.play_pb2 import PlayName from proto.ssl_gc_common_pb2 import Team from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.friendly_team_scored import ( +from software.gameplay_tests.validation.friendly_team_scored import ( FriendlyTeamEventuallyScored, ) -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.util import pytest_main @pytest.mark.skip( "Skipping test. TODO (#3233): attacker robot sometimes doesn't kick the ball towards the receiver" ) -def test_shoot_or_pass_play(simulated_test_runner): +def test_shoot_or_pass_play(gameplay_test_runner): field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ field.friendlyGoalCenter(), @@ -41,24 +41,23 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.ShootOrPassPlay, yellow_play=PlayName.HaltPlay ) # Eventually Validation eventually_validations = [[FriendlyTeamEventuallyScored()]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=15, run_till_end=False, ) diff --git a/src/software/ai/hl/stp/play/stop_play_test.py b/src/software/ai/hl/stp/play/stop_play_test.py index 8735319ffe..5eee0982cd 100644 --- a/src/software/ai/hl/stp/play/stop_play_test.py +++ b/src/software/ai/hl/stp/play/stop_play_test.py @@ -5,14 +5,14 @@ from proto.play_pb2 import PlayName from proto.ssl_gc_common_pb2 import Team from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.robot_speed_threshold import ( +from software.gameplay_tests.validation.robot_speed_threshold import ( RobotSpeedAlwaysBelowThreshold, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( RobotNeverEntersRegion, ) -from software.simulated_tests.validation.delay_validation import DelayValidation -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.validation.delay_validation import DelayValidation +from software.gameplay_tests.util import pytest_main @pytest.mark.parametrize( @@ -117,11 +117,11 @@ # ), ], ) -def test_stop_play(ball_position, blue_robot_positions, simulated_test_runner): +def test_stop_play(ball_position, blue_robot_positions, gameplay_test_runner): field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_robot_positions, yellow_robot_locations=[ @@ -137,11 +137,11 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.UNKNOWN ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.StopPlay, yellow_play=PlayName.HaltPlay ) @@ -163,10 +163,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_always_validation_sequence_set=always_stop_play_rules, - ag_always_validation_sequence_set=always_stop_play_rules, + always_validation_sequence_set=always_stop_play_rules, test_timeout_s=6, ) diff --git a/src/software/ai/hl/stp/tactic/attacker/BUILD b/src/software/ai/hl/stp/tactic/attacker/BUILD index 86634c632e..8cc99c74ae 100644 --- a/src/software/ai/hl/stp/tactic/attacker/BUILD +++ b/src/software/ai/hl/stp/tactic/attacker/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -41,7 +41,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/attacker/attacker_tactic_test.py b/src/software/ai/hl/stp/tactic/attacker/attacker_tactic_test.py index df4a815277..2215d861ed 100644 --- a/src/software/ai/hl/stp/tactic/attacker/attacker_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/attacker/attacker_tactic_test.py @@ -4,22 +4,22 @@ from proto.import_all_protos import AttackerTactic, Pass from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.validation.excessive_dribbling import ( +from software.gameplay_tests.validation.excessive_dribbling import ( NeverExcessivelyDribbles, ) -from software.simulated_tests.validation.friendly_team_scored import ( +from software.gameplay_tests.validation.friendly_team_scored import ( FriendlyTeamEventuallyScored, ) -from software.simulated_tests.validation.robot_at_orientation import ( +from software.gameplay_tests.validation.robot_at_orientation import ( RobotEventuallyAtOrientation, ) -from software.simulated_tests.validation.robot_at_position import ( +from software.gameplay_tests.validation.robot_at_position import ( RobotEventuallyAtPosition, ) -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.util import pytest_main def calculate_ball_velocity(passer_point, receiver_point, speed): @@ -119,10 +119,10 @@ def test_attacker_passing( robot_pos, ball_pos, ball_velocity, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -140,7 +140,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: AttackerTactic( best_pass_so_far=Pass( @@ -166,10 +166,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, run_till_end=False, test_timeout_s=7, ) @@ -219,7 +218,7 @@ def test_attacker_keep_away( ball_velocity, enemy_positions, ignore_score_checks, - simulated_test_runner, + gameplay_test_runner, ): # TODO (#3638): Port C++ validation functions that don't exist in Python yet # In C++ test: @@ -231,7 +230,7 @@ def test_attacker_keep_away( field_top_left = field.fieldLines().negXPosYCorner() # Keep away near field corner (second test case from C++) - def setup(*args): + def setup(): robot_pos = field_top_left ball_pos = tbots_cpp.Point(field_top_left.x() + 0.05, field_top_left.y() - 0.2) enemy_positions = [ @@ -241,7 +240,7 @@ def setup(*args): tbots_cpp.Point(-4, 2.75), ] - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -258,7 +257,7 @@ def setup(*args): ) receiver_point = tbots_cpp.Point(0, 0) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: AttackerTactic( best_pass_so_far=Pass( @@ -277,10 +276,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) @@ -348,12 +346,12 @@ def setup(*args): ], ) def test_attacker_shoot_goal( - ball_pos, ball_velocity, robot_pos, enemy_positions, simulated_test_runner + ball_pos, ball_velocity, robot_pos, enemy_positions, gameplay_test_runner ): field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[robot_pos], yellow_robot_locations=enemy_positions, @@ -362,7 +360,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: AttackerTactic( chip_target=tbots_cpp.createPointProto( @@ -378,10 +376,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, run_till_end=False, test_timeout_s=9, ) diff --git a/src/software/ai/hl/stp/tactic/chip/BUILD b/src/software/ai/hl/stp/tactic/chip/BUILD index 5b5124cb78..a7bc7ba44e 100644 --- a/src/software/ai/hl/stp/tactic/chip/BUILD +++ b/src/software/ai/hl/stp/tactic/chip/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -39,7 +39,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/chip/chip_tactic_test.py b/src/software/ai/hl/stp/tactic/chip/chip_tactic_test.py index 4aad0c5249..5baebae99b 100644 --- a/src/software/ai/hl/stp/tactic/chip/chip_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/chip/chip_tactic_test.py @@ -3,13 +3,13 @@ import software.python_bindings as tbots_cpp from software.py_constants import ROBOT_MAX_RADIUS_METERS -from software.simulated_tests.validation.ball_is_off_ground import ( +from software.gameplay_tests.validation.ball_is_off_ground import ( BallIsEventuallyOffGround, ) -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state @@ -48,12 +48,12 @@ ), ], ) -def test_chip(ball_offset_from_robot, angle_to_chip_at, simulated_test_runner): +def test_chip(ball_offset_from_robot, angle_to_chip_at, gameplay_test_runner): robot_position = tbots_cpp.Point(0, 0) ball_position = robot_position + ball_offset_from_robot - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -65,7 +65,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: ChipTactic( chip_origin=tbots_cpp.createPointProto(ball_position), @@ -84,10 +84,9 @@ def setup(*args): ], ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, ) diff --git a/src/software/ai/hl/stp/tactic/crease_defender/BUILD b/src/software/ai/hl/stp/tactic/crease_defender/BUILD index 58467ae6a5..d7c2814986 100644 --- a/src/software/ai/hl/stp/tactic/crease_defender/BUILD +++ b/src/software/ai/hl/stp/tactic/crease_defender/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -43,7 +43,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic_test.py b/src/software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic_test.py index bfa92f4afd..f16a8a01eb 100644 --- a/src/software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic_test.py @@ -8,31 +8,31 @@ MaxAllowedSpeedMode, ) from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_is_off_ground import ( +from software.gameplay_tests.validation.ball_is_off_ground import ( BallIsAlwaysOnGround, BallIsEventuallyOffGround, ) -from software.simulated_tests.validation.ball_speed_threshold import ( +from software.gameplay_tests.validation.ball_speed_threshold import ( BallSpeedAlwaysBelowThreshold, ) -from software.simulated_tests.validation.delay_validation import DelayValidation -from software.simulated_tests.validation.excessive_dribbling import ( +from software.gameplay_tests.validation.delay_validation import DelayValidation +from software.gameplay_tests.validation.excessive_dribbling import ( NeverExcessivelyDribbles, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( RobotEventuallyEntersRegion, RobotNeverEntersRegion, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -def test_not_bumping_ball_towards_net(simulated_test_runner): +def test_not_bumping_ball_towards_net(gameplay_test_runner): enemy_threat_point = tbots_cpp.Point(3, 0) - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[tbots_cpp.Point(0, 0)], yellow_robot_locations=[tbots_cpp.Point(4, 0)], @@ -41,7 +41,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: CreaseDefenderTactic( enemy_threat_origin=tbots_cpp.createPointProto(enemy_threat_point), @@ -52,10 +52,9 @@ def setup(*args): always_validations = [[BallSpeedAlwaysBelowThreshold(0.001)]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_always_validation_sequence_set=always_validations, - ag_always_validation_sequence_set=always_validations, + always_validation_sequence_set=always_validations, ) @@ -79,12 +78,12 @@ def setup(*args): ], ) def test_crease_region_positioning( - enemy_threat_point, crease_alignment, region_index, simulated_test_runner + enemy_threat_point, crease_alignment, region_index, gameplay_test_runner ): field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[tbots_cpp.Point(-3, 1.5)], yellow_robot_locations=[ @@ -100,7 +99,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: CreaseDefenderTactic( enemy_threat_origin=tbots_cpp.createPointProto(enemy_threat_point), @@ -174,10 +173,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=5, ) @@ -211,10 +209,10 @@ def test_crease_positioning( yellow_bots, ball_initial_pos, ball_initial_velocity, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[blue_bots], yellow_robot_locations=[yellow_bots], @@ -223,7 +221,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: CreaseDefenderTactic( enemy_threat_origin=tbots_cpp.createPointProto(ball_initial_pos), @@ -259,12 +257,10 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=4, ) @@ -321,10 +317,10 @@ def test_crease_autochip( ball_initial_pos, ball_initial_velocity, should_chip, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[blue_bots], yellow_robot_locations=[yellow_bots], @@ -333,7 +329,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: CreaseDefenderTactic( enemy_threat_origin=tbots_cpp.createPointProto(ball_initial_pos), @@ -356,12 +352,10 @@ def setup(*args): always_validation_sequence_set = [[]] eventually_validation_sequence_set = [[BallIsEventuallyOffGround()]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=3, ) @@ -393,10 +387,10 @@ def test_crease_get_ball( ball_initial_pos, ball_initial_velocity, should_dribble, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[blue_bots], yellow_robot_locations=[yellow_bots], @@ -405,7 +399,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: CreaseDefenderTactic( enemy_threat_origin=tbots_cpp.createPointProto(ball_initial_pos), @@ -437,12 +431,10 @@ def setup(*args): RobotNeverEntersRegion(regions=[tbots_cpp.Circle(ball_initial_pos, 0.2)]) ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) diff --git a/src/software/ai/hl/stp/tactic/defender/BUILD b/src/software/ai/hl/stp/tactic/defender/BUILD index 7c0610ce93..f4bedf6d73 100644 --- a/src/software/ai/hl/stp/tactic/defender/BUILD +++ b/src/software/ai/hl/stp/tactic/defender/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) diff --git a/src/software/ai/hl/stp/tactic/dribble/BUILD b/src/software/ai/hl/stp/tactic/dribble/BUILD index 7916893668..b4387617cd 100644 --- a/src/software/ai/hl/stp/tactic/dribble/BUILD +++ b/src/software/ai/hl/stp/tactic/dribble/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -42,7 +42,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/dribble/dribble_tactic_test.py b/src/software/ai/hl/stp/tactic/dribble/dribble_tactic_test.py index c138969def..e53ed80746 100644 --- a/src/software/ai/hl/stp/tactic/dribble/dribble_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/dribble/dribble_tactic_test.py @@ -4,24 +4,24 @@ from proto.import_all_protos import DribbleTactic from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_enters_region import ( +from software.gameplay_tests.validation.ball_enters_region import ( BallAlwaysStaysInRegion, BallEventuallyEntersRegion, ) -from software.simulated_tests.validation.excessive_dribbling import ( +from software.gameplay_tests.validation.excessive_dribbling import ( EventuallyStartsExcessivelyDribbling, NeverExcessivelyDribbles, ) -from software.simulated_tests.validation.robot_at_orientation import ( +from software.gameplay_tests.validation.robot_at_orientation import ( RobotEventuallyAtOrientation, ) -from software.simulated_tests.validation.robot_received_ball import ( +from software.gameplay_tests.validation.robot_received_ball import ( RobotEventuallyReceivedBall, ) -from software.simulated_tests.validation.delay_validation import ( +from software.gameplay_tests.validation.delay_validation import ( DelayValidation, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -129,10 +129,10 @@ def test_dribble( dribble_orientation, ball_pos, ball_vel, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -156,7 +156,7 @@ def setup(*args): tbots_cpp.createAngleProto(dribble_orientation) ) - simulated_test_runner.set_tactics(blue_tactics={1: dribble_params}) + gameplay_test_runner.set_tactics(blue_tactics={1: dribble_params}) eventually_validations = [[RobotEventuallyReceivedBall(robot_id=1)]] @@ -177,10 +177,9 @@ def setup(*args): # TODO (#2514): tune dribbling and re-enable # Robot always not excessively dribbling - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=25, run_till_end=False, ) @@ -296,11 +295,11 @@ def test_excessive_dribbling_without_enemies( dribble_destination, final_dribble_orientation, should_excessively_dribble, - simulated_test_runner, + gameplay_test_runner, blue_robot_location, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[blue_robot_location], yellow_robot_locations=[], @@ -309,7 +308,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: DribbleTactic( dribble_destination=tbots_cpp.createPointProto(dribble_destination), @@ -330,22 +329,20 @@ def setup(*args): always_validation_sequence_set = [[NeverExcessivelyDribbles()]] eventually_validation_sequence_set = [[]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) -def test_dribble_with_excessive_dribbling(simulated_test_runner): +def test_dribble_with_excessive_dribbling(gameplay_test_runner): dribble_destination = tbots_cpp.Point(3, 2) initial_position = tbots_cpp.Point(4.5, -3.0) dribble_orientation = tbots_cpp.Angle.half() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -357,7 +354,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: DribbleTactic( dribble_destination=tbots_cpp.createPointProto(dribble_destination), @@ -378,16 +375,15 @@ def setup(*args): [EventuallyStartsExcessivelyDribbling()], ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=10, ) def test_run_into_enemy_robot_knock_ball_away( - simulated_test_runner, + gameplay_test_runner, ): initial_position = tbots_cpp.Point(-2, 1.5) dribble_destination = tbots_cpp.Point(-1, 2) @@ -395,8 +391,8 @@ def test_run_into_enemy_robot_knock_ball_away( ball_pos = tbots_cpp.Point(2, -2) ball_vel = tbots_cpp.Vector(2, 4) - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -415,7 +411,7 @@ def setup(*args): final_dribble_orientation=tbots_cpp.createAngleProto(dribble_orientation), ) - simulated_test_runner.set_tactics(blue_tactics={1: dribble_params}) + gameplay_test_runner.set_tactics(blue_tactics={1: dribble_params}) eventually_validations = [ [ @@ -429,24 +425,23 @@ def setup(*args): # TODO (#2514): tune dribbling and re-enable # Robot always not excessively dribbling - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, test_timeout_s=10, ) def test_robot_not_bumping_ball_when_turning( - simulated_test_runner, + gameplay_test_runner, ): # The ball is placed right behind the friendly robot. Verify that the robot # does not bump the ball away when turning around to dribble it. robot_location = tbots_cpp.Point(-1, 0) ball_location = robot_location + tbots_cpp.Vector(ROBOT_MAX_RADIUS_METERS, 0) - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[tbots_cpp.Point(-3, 2.5), robot_location], blue_robot_orientations=[ @@ -461,7 +456,7 @@ def setup(*args): ) dribble_params = DribbleTactic() - simulated_test_runner.set_tactics(blue_tactics={1: dribble_params}) + gameplay_test_runner.set_tactics(blue_tactics={1: dribble_params}) eventually_validations = [ [ @@ -475,12 +470,10 @@ def setup(*args): [BallAlwaysStaysInRegion([tbots_cpp.Circle(ball_location, 0.05)])] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, - inv_always_validation_sequence_set=always_validations, - ag_always_validation_sequence_set=always_validations, + eventually_validation_sequence_set=eventually_validations, + always_validation_sequence_set=always_validations, ) diff --git a/src/software/ai/hl/stp/tactic/goalie/BUILD b/src/software/ai/hl/stp/tactic/goalie/BUILD index 47d8f9f8af..ffc112a166 100644 --- a/src/software/ai/hl/stp/tactic/goalie/BUILD +++ b/src/software/ai/hl/stp/tactic/goalie/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -58,7 +58,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/goalie/goalie_tactic_test.py b/src/software/ai/hl/stp/tactic/goalie/goalie_tactic_test.py index 2111109524..dfca076d6d 100644 --- a/src/software/ai/hl/stp/tactic/goalie/goalie_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/goalie/goalie_tactic_test.py @@ -2,14 +2,14 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.robot_enters_region import * -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.ball_moves_in_direction import * -from software.simulated_tests.validation.friendly_has_ball_possession import * -from software.simulated_tests.validation.ball_speed_threshold import * -from software.simulated_tests.validation.robot_speed_threshold import * -from software.simulated_tests.validation.excessive_dribbling import * -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.validation.robot_enters_region import * +from software.gameplay_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.ball_moves_in_direction import * +from software.gameplay_tests.validation.friendly_has_ball_possession import * +from software.gameplay_tests.validation.ball_speed_threshold import * +from software.gameplay_tests.validation.robot_speed_threshold import * +from software.gameplay_tests.validation.excessive_dribbling import * +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state @@ -112,10 +112,10 @@ def test_goalie_blocks_shot( ball_initial_position, ball_initial_velocity, robot_initial_position, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( [], blue_robot_locations=[robot_initial_position], @@ -124,7 +124,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: GoalieTactic( max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT @@ -155,12 +155,10 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) @@ -189,10 +187,10 @@ def setup(*args): def test_goalie_clears_from_dead_zone( ball_position, should_clear, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( [], blue_robot_locations=[ @@ -205,7 +203,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: GoalieTactic( max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT @@ -238,13 +236,11 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, test_timeout_s=8, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) diff --git a/src/software/ai/hl/stp/tactic/halt/BUILD b/src/software/ai/hl/stp/tactic/halt/BUILD index f32f65094e..ac0a3f05e3 100644 --- a/src/software/ai/hl/stp/tactic/halt/BUILD +++ b/src/software/ai/hl/stp/tactic/halt/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -37,7 +37,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/halt/halt_tactic_test.py b/src/software/ai/hl/stp/tactic/halt/halt_tactic_test.py index 4c7466c2e8..d6bed914f8 100644 --- a/src/software/ai/hl/stp/tactic/halt/halt_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/halt/halt_tactic_test.py @@ -5,11 +5,11 @@ HaltTactic, ) from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.robot_speed_threshold import ( +from software.gameplay_tests.validation.robot_speed_threshold import ( RobotSpeedEventuallyBelowThreshold, ) -from software.simulated_tests.validation.delay_validation import DelayValidation -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.validation.delay_validation import DelayValidation +from software.gameplay_tests.util import ( pytest_main, ) @@ -31,9 +31,9 @@ ), ], ) -def test_robot_halt(blue_robot_locations, blue_robot_velocities, simulated_test_runner): - def setup(*args): - simulated_test_runner.set_world_state( +def test_robot_halt(blue_robot_locations, blue_robot_velocities, gameplay_test_runner): + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_robot_locations, blue_robot_velocities=blue_robot_velocities, @@ -43,7 +43,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics(blue_tactics={1: HaltTactic()}) + gameplay_test_runner.set_tactics(blue_tactics={1: HaltTactic()}) robot_stopped_validation = RobotSpeedEventuallyBelowThreshold(speed_threshold=0.001) @@ -61,10 +61,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, ) diff --git a/src/software/ai/hl/stp/tactic/kick/BUILD b/src/software/ai/hl/stp/tactic/kick/BUILD index 17c554eca9..b8569fc5bc 100644 --- a/src/software/ai/hl/stp/tactic/kick/BUILD +++ b/src/software/ai/hl/stp/tactic/kick/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -39,7 +39,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/kick/kick_tactic_test.py b/src/software/ai/hl/stp/tactic/kick/kick_tactic_test.py index 19eceb1f0e..c3deae0e31 100644 --- a/src/software/ai/hl/stp/tactic/kick/kick_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/kick/kick_tactic_test.py @@ -4,10 +4,10 @@ from proto.import_all_protos import KickTactic from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -38,12 +38,12 @@ (tbots_cpp.Vector(ROBOT_MAX_RADIUS_METERS, 0), tbots_cpp.Angle.zero()), ], ) -def test_kick(ball_offset_from_robot, angle_to_kick_at, simulated_test_runner): +def test_kick(ball_offset_from_robot, angle_to_kick_at, gameplay_test_runner): robot_position = tbots_cpp.Point(0, 0) ball_position = robot_position + ball_offset_from_robot - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -55,7 +55,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: KickTactic( kick_origin=tbots_cpp.createPointProto(ball_position), @@ -71,10 +71,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validations, - ag_eventually_validation_sequence_set=eventually_validations, + eventually_validation_sequence_set=eventually_validations, ) diff --git a/src/software/ai/hl/stp/tactic/move/BUILD b/src/software/ai/hl/stp/tactic/move/BUILD index 8d772fd72d..3b04ab038d 100644 --- a/src/software/ai/hl/stp/tactic/move/BUILD +++ b/src/software/ai/hl/stp/tactic/move/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -38,7 +38,8 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests:util", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/move/move_tactic_test.py b/src/software/ai/hl/stp/tactic/move/move_tactic_test.py index 6b3e53fd83..528ca68a79 100644 --- a/src/software/ai/hl/stp/tactic/move/move_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/move/move_tactic_test.py @@ -1,36 +1,40 @@ import pytest import software.python_bindings as tbots_cpp -from software.simulated_tests.validation.robot_at_position import ( +from software.gameplay_tests.validation.robot_at_position import ( RobotEventuallyAtPosition, ) -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.validation.robot_at_orientation import ( +from software.gameplay_tests.validation.robot_at_orientation import ( RobotEventuallyAtOrientation, ) -from software.simulated_tests.validation.ball_is_off_ground import ( +from software.gameplay_tests.validation.ball_is_off_ground import ( BallIsEventuallyOffGround, ) -from software.simulated_tests.validation.robot_at_angular_velocity import ( +from software.gameplay_tests.validation.robot_at_angular_velocity import ( RobotEventuallyAtAngularVelocity, ) -from software.simulated_tests.validation.duration_validation import DurationValidation -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.validation.duration_validation import DurationValidation + +# from software.gameplay_tests.util import ( +# pytest_main, +# ) +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state from proto.import_all_protos import * -def test_move_across_field(simulated_test_runner): +def test_move_across_field(gameplay_test_runner): initial_position = tbots_cpp.Point(-3, 1.5) destination = tbots_cpp.Point(2.5, -1.1) field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -49,7 +53,7 @@ def setup(*args): ), ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: MoveTactic( destination=tbots_cpp.createPointProto(destination), @@ -69,21 +73,20 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=5, ) -def test_autochip_move(simulated_test_runner): +def test_autochip_move(gameplay_test_runner): initial_position = tbots_cpp.Point(-3, 1.5) destination = tbots_cpp.Point(0, 1.5) field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -102,7 +105,7 @@ def setup(*args): ), ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: MoveTactic( destination=tbots_cpp.createPointProto(destination), @@ -131,21 +134,20 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=10, ) -def test_autokick_move(simulated_test_runner): +def test_autokick_move(gameplay_test_runner): initial_position = tbots_cpp.Point(-1, -0.5) destination = tbots_cpp.Point(-1, -1) field = tbots_cpp.Field.createSSLDivisionBField() - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[initial_position], blue_robot_orientations=[tbots_cpp.Angle.threeQuarter()], @@ -162,7 +164,7 @@ def setup(*args): ), ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: MoveTactic( destination=tbots_cpp.createPointProto(destination), @@ -190,10 +192,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=5, ) @@ -246,10 +247,10 @@ def setup(*args): ], ) def test_spinning_move( - orientation, initial_position, destination, angular_velocity, simulated_test_runner + orientation, initial_position, destination, angular_velocity, gameplay_test_runner ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[initial_position], yellow_robot_locations=[tbots_cpp.Point(4, 0)], @@ -258,7 +259,7 @@ def setup(*args): ), ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: MoveTactic( destination=tbots_cpp.createPointProto(destination), @@ -290,10 +291,9 @@ def setup(*args): ], ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=5, ) diff --git a/src/software/ai/hl/stp/tactic/pass_defender/BUILD b/src/software/ai/hl/stp/tactic/pass_defender/BUILD index b83739a0dd..e1702deea4 100644 --- a/src/software/ai/hl/stp/tactic/pass_defender/BUILD +++ b/src/software/ai/hl/stp/tactic/pass_defender/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -45,7 +45,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic_test.py b/src/software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic_test.py index fd8ab0c74a..c7436656ec 100644 --- a/src/software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic_test.py @@ -2,14 +2,14 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.robot_enters_region import * -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.ball_moves_in_direction import * -from software.simulated_tests.validation.friendly_has_ball_possession import * -from software.simulated_tests.validation.ball_speed_threshold import * -from software.simulated_tests.validation.robot_speed_threshold import * -from software.simulated_tests.validation.excessive_dribbling import * -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.validation.robot_enters_region import * +from software.gameplay_tests.validation.ball_enters_region import * +from software.gameplay_tests.validation.ball_moves_in_direction import * +from software.gameplay_tests.validation.friendly_has_ball_possession import * +from software.gameplay_tests.validation.ball_speed_threshold import * +from software.gameplay_tests.validation.robot_speed_threshold import * +from software.gameplay_tests.validation.excessive_dribbling import * +from software.gameplay_tests.util import ( pytest_main, ) from proto.message_translation.tbots_protobuf import create_world_state @@ -34,10 +34,10 @@ def test_ball_chipped_on_intercept( ball_initial_position, ball_initial_velocity, position_to_block_from, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( [], blue_robot_locations=[position_to_block_from], @@ -46,7 +46,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: PassDefenderTactic( position_to_block_from=tbots_cpp.createPointProto( @@ -73,12 +73,10 @@ def setup(*args): eventually_validation_sequence_set = [[BallSpeedEventuallyBelowThreshold(0.4)]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) @@ -107,10 +105,10 @@ def test_avoid_intercept_scenario( ball_initial_position, ball_initial_velocity, position_to_block_from, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( [], blue_robot_locations=[position_to_block_from], @@ -119,7 +117,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: PassDefenderTactic( position_to_block_from=tbots_cpp.createPointProto( @@ -164,12 +162,10 @@ def setup(*args): eventually_validation_sequence_set = [[BallSpeedEventuallyBelowThreshold(0.4)]] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) @@ -240,10 +236,10 @@ def test_steal_ball( position_to_block_from, enemy_kicker_position, should_steal, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[position_to_block_from], yellow_robot_locations=[enemy_kicker_position], @@ -252,7 +248,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 0: PassDefenderTactic( position_to_block_from=tbots_cpp.createPointProto( @@ -285,12 +281,10 @@ def setup(*args): FriendlyNeverHasBallPossession(tolerance=0.05) ) - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, ) diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/BUILD b/src/software/ai/hl/stp/tactic/penalty_kick/BUILD index 0c3b424a8a..63a217f74e 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/BUILD +++ b/src/software/ai/hl/stp/tactic/penalty_kick/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -41,7 +41,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic_test.py b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic_test.py index 0e4713e5ac..2a2bca523f 100644 --- a/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/penalty_kick/penalty_kick_tactic_test.py @@ -3,17 +3,17 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import PenaltyKickTactic -from software.simulated_tests.validation.friendly_team_scored import ( +from software.gameplay_tests.validation.friendly_team_scored import ( FriendlyTeamEventuallyScored, ) -from software.simulated_tests.validation.excessive_dribbling import ( +from software.gameplay_tests.validation.excessive_dribbling import ( NeverExcessivelyDribbles, ) -from software.simulated_tests.validation.ball_moves_in_direction import ( +from software.gameplay_tests.validation.ball_moves_in_direction import ( BallAlwaysMovesForward, ) from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -51,16 +51,14 @@ @pytest.mark.skip( "Disabling this test because of poor dribbling controls, does not consistently score goal. TODO (#2232)" ) -def test_penalty_kick( - enemy_robot_location, enemy_robot_velocity, simulated_test_runner -): +def test_penalty_kick(enemy_robot_location, enemy_robot_velocity, gameplay_test_runner): field = tbots_cpp.Field.createSSLDivisionBField() ball_initial_pos = field.friendlyPenaltyMark() - def setup(*args): + def setup(): shooter_position = ball_initial_pos - tbots_cpp.Vector(0.1, 0) - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[shooter_position], yellow_robot_locations=[enemy_robot_location], @@ -69,7 +67,7 @@ def setup(*args): ), ) - simulated_test_runner.set_tactics(blue_tactics={0: PenaltyKickTactic()}) + gameplay_test_runner.set_tactics(blue_tactics={0: PenaltyKickTactic()}) eventually_validation_sequence_set = [ [ @@ -82,10 +80,10 @@ def setup(*args): [BallAlwaysMovesForward(ball_initial_pos), NeverExcessivelyDribbles()] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=10, ) diff --git a/src/software/ai/hl/stp/tactic/pivot_kick/BUILD b/src/software/ai/hl/stp/tactic/pivot_kick/BUILD index 7df9c6095d..985381803d 100644 --- a/src/software/ai/hl/stp/tactic/pivot_kick/BUILD +++ b/src/software/ai/hl/stp/tactic/pivot_kick/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -41,7 +41,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/pivot_kick/pivot_kick_tactic_test.py b/src/software/ai/hl/stp/tactic/pivot_kick/pivot_kick_tactic_test.py index 8a281bb09b..4363d4939c 100644 --- a/src/software/ai/hl/stp/tactic/pivot_kick/pivot_kick_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/pivot_kick/pivot_kick_tactic_test.py @@ -4,10 +4,10 @@ from proto.import_all_protos import * from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.ball_kicked_in_direction import ( +from software.gameplay_tests.validation.ball_kicked_in_direction import ( BallEventuallyKickedInDirection, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -36,12 +36,12 @@ @pytest.mark.skip( "Disabling this flaky test. TODO (#2859): the robot does not dribble far enough into the ball" ) -def test_pivot_kick(ball_offset_from_robot, angle_to_kick_at, simulated_test_runner): +def test_pivot_kick(ball_offset_from_robot, angle_to_kick_at, gameplay_test_runner): robot_position = tbots_cpp.Point(0, 0) ball_position = robot_position + ball_offset_from_robot - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -53,7 +53,7 @@ def setup(*args): ) ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ 1: PivotKickTactic( kick_origin=tbots_cpp.createPointProto(ball_position), @@ -69,12 +69,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_always_validation_sequence_set=[[]], + eventually_validation_sequence_set=eventually_validation_sequence_set, test_timeout_s=5, ) diff --git a/src/software/ai/hl/stp/tactic/receiver/BUILD b/src/software/ai/hl/stp/tactic/receiver/BUILD index 2a6f5d59ac..877ca871cb 100644 --- a/src/software/ai/hl/stp/tactic/receiver/BUILD +++ b/src/software/ai/hl/stp/tactic/receiver/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -43,7 +43,7 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/hl/stp/tactic/receiver/receiver_tactic_test.py b/src/software/ai/hl/stp/tactic/receiver/receiver_tactic_test.py index 9c07bb3762..b4e5fd04fd 100644 --- a/src/software/ai/hl/stp/tactic/receiver/receiver_tactic_test.py +++ b/src/software/ai/hl/stp/tactic/receiver/receiver_tactic_test.py @@ -3,16 +3,16 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import Pass, ReceiverTactic from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.validation.friendly_team_scored import ( +from software.gameplay_tests.validation.friendly_team_scored import ( FriendlyTeamEventuallyScored, ) -from software.simulated_tests.validation.robot_at_orientation import ( +from software.gameplay_tests.validation.robot_at_orientation import ( RobotEventuallyAtOrientation, ) -from software.simulated_tests.validation.robot_received_ball import ( +from software.gameplay_tests.validation.robot_received_ball import ( RobotEventuallyReceivedBall, ) -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.util import pytest_main def calculate_ball_velocity(passer_point, receiver_point, speed): @@ -187,14 +187,14 @@ def test_receiver( robot_pos, robot_orientation, one_touch, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): + def setup(): ball_velocity = calculate_ball_velocity( passer_point, receiver_point, pass_speed ) - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=[ tbots_cpp.Point(-3, 2.5), @@ -216,7 +216,7 @@ def setup(*args): "disable_one_touch_shot": not one_touch, } - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={1: ReceiverTactic(**receiver_args)} ) @@ -232,10 +232,9 @@ def setup(*args): ] ] - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - ag_eventually_validation_sequence_set=eventually_validation_sequence_set, + eventually_validation_sequence_set=eventually_validation_sequence_set, run_till_end=False, ) diff --git a/src/software/ai/hl/stp/tactic/shadow_enemy/BUILD b/src/software/ai/hl/stp/tactic/shadow_enemy/BUILD index a56ba5e49d..078ebe5b3e 100644 --- a/src/software/ai/hl/stp/tactic/shadow_enemy/BUILD +++ b/src/software/ai/hl/stp/tactic/shadow_enemy/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) diff --git a/src/software/ai/navigator/trajectory/BUILD b/src/software/ai/navigator/trajectory/BUILD index abc4f5c82f..aed39a7737 100644 --- a/src/software/ai/navigator/trajectory/BUILD +++ b/src/software/ai/navigator/trajectory/BUILD @@ -1,8 +1,8 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = [ "//software/ai:__subpackages__", - "//software/simulated_tests:__subpackages__", + "//software/gameplay_tests:__subpackages__", ]) cc_library( @@ -157,7 +157,7 @@ py_test( deps = [ "//proto/message_translation:py_tbots_protobuf", "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/ai/navigator/trajectory/simulated_hrvo_test.py b/src/software/ai/navigator/trajectory/simulated_hrvo_test.py index 5bcd2a99d2..0c447f724f 100644 --- a/src/software/ai/navigator/trajectory/simulated_hrvo_test.py +++ b/src/software/ai/navigator/trajectory/simulated_hrvo_test.py @@ -1,16 +1,15 @@ import pytest -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) -from software.simulated_tests.validation.avoid_collisions import * +from software.gameplay_tests.validation.avoid_collisions import * import software.python_bindings as tbots from software.py_constants import * from proto.message_translation.tbots_protobuf import create_world_state import math from proto.import_all_protos import * from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import SimulatedTestRunner -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( create_validation_types, create_validation_geometry, ) @@ -168,7 +167,7 @@ def hrvo_setup( friendly_robots_final_orientations: list[tbots.Angle], enemy_robots_positions: list[tbots.Point], enemy_robots_destinations: list[tbots.Point], - simulated_test_runner: SimulatedTestRunner, + gameplay_test_runner, ): """Setup for the hrvo tests @@ -177,7 +176,7 @@ def hrvo_setup( :param friendly_robots_final_orientations: final orientations of friendly robots :param enemy_robots_positions: starting positions of enemy robots :param enemy_robots_destinations: destinations of enemy robots - :param simulated_test_runner: the current test runner being used + :param gameplay_test_runner: the current test runner being used """ desired_orientation = tbots.Angle.fromRadians(0) @@ -185,7 +184,7 @@ def hrvo_setup( ball_initial_vel = tbots.Point(0, 0) - simulated_test_runner.set_world_state( + gameplay_test_runner.set_world_state( create_world_state( yellow_robot_locations=enemy_robots_positions, blue_robot_locations=friendly_robots_positions, @@ -194,13 +193,13 @@ def hrvo_setup( ) ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.BLUE ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.STOP, team=Team.YELLOW ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.FORCE_START, team=Team.BLUE ) @@ -226,7 +225,7 @@ def hrvo_setup( tbots.Angle.fromRadians(0), ) - simulated_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics=blue_tactics, yellow_tactics=yellow_tactics ) @@ -472,7 +471,7 @@ def hrvo_setup( ], ) def test_robot_movement( - simulated_test_runner: SimulatedTestRunner, + gameplay_test_runner, friendly_robot_positions: list[tbots.Point], friendly_robot_destinations: list[tbots.Point], friendly_robots_final_orientations: list[tbots.Angle], @@ -491,20 +490,17 @@ def test_robot_movement( else get_reached_destination_validation(friendly_robot_destinations) ) - simulated_test_runner.run_test( - setup=lambda param: hrvo_setup( + gameplay_test_runner.run_test( + setup=lambda: hrvo_setup( friendly_robot_positions, friendly_robot_destinations, friendly_robots_final_orientations, enemy_robots_positions, enemy_robots_destinations, - simulated_test_runner, + gameplay_test_runner, ), - params=[0], - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ag_eventually_validation_sequence_set=[[]], - ag_always_validation_sequence_set=[[]], + eventually_validation_sequence_set=eventually_validation_sequence_set, + always_validation_sequence_set=always_validation_sequence_set, test_timeout_s=timeout_s, run_till_end=run_till_end, ) diff --git a/src/software/conftest.py b/src/software/conftest.py index 61da04ba49..aed4da95be 100644 --- a/src/software/conftest.py +++ b/src/software/conftest.py @@ -1,6 +1,5 @@ import pytest # noqa: F401 -from software.simulated_tests.simulated_test_fixture import simulated_test_runner # noqa: F401 -from software.field_tests.field_test_fixture import field_test_runner # noqa: F401 +from software.gameplay_tests.fixture import gameplay_test_runner # noqa: F401 # Pytest requires that all tests fixtures shared across a package be defined # in a single conftest.py file in the parent directory of the package. diff --git a/src/software/field_tests/BUILD b/src/software/field_tests/BUILD index 96ec19c6e3..8aefdb45a0 100644 --- a/src/software/field_tests/BUILD +++ b/src/software/field_tests/BUILD @@ -1,32 +1,7 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) -py_library( - name = "field_test_fixture", - srcs = [ - "field_test_fixture.py", - ], - data = [ - "//software:py_constants.so", - ], - deps = [ - "//proto:import_all_protos", - "//software/logger:py_logger", - "//software/networking/unix:threaded_unix_listener_py", - "//software/networking/unix:threaded_unix_sender_py", - "//software/simulated_tests:tbots_test_runner", - "//software/simulated_tests/validation:validations", - "//software/thunderscope", - "//software/thunderscope:constants", - "//software/thunderscope:estop_helpers", - "//software/thunderscope:robot_communication", - "//software/thunderscope/binary_context_managers:full_system", - "//software/thunderscope/binary_context_managers:game_controller", - "//software/thunderscope/binary_context_managers:simulator", - ], -) - py_test( name = "movement_robot_field_test", srcs = [ @@ -38,8 +13,8 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests:tbots_test_runner", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests:util", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) @@ -55,8 +30,8 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests:tbots_test_runner", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests:util", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) @@ -68,7 +43,8 @@ py_test( ], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests:util", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/field_tests/field_test_fixture.py b/src/software/field_tests/field_test_fixture.py deleted file mode 100644 index ebf0480ac3..0000000000 --- a/src/software/field_tests/field_test_fixture.py +++ /dev/null @@ -1,433 +0,0 @@ -import queue -import time -import os -import threading - -import pytest -import argparse -from proto.import_all_protos import * - -from software.simulated_tests.validation import validation -from software.thunderscope.constants import EstopMode, IndividualRobotMode -from software.thunderscope.thunderscope import Thunderscope -from software.thunderscope.proto_unix_io import ProtoUnixIO -from software.thunderscope.binary_context_managers.full_system import FullSystem -from software.thunderscope.binary_context_managers.game_controller import Gamecontroller -from software.thunderscope.wifi_communication_manager import WifiCommunicationManager -from software.logger.logger import create_logger - - -from software.thunderscope.thunderscope_config import configure_field_test_view -from software.simulated_tests.tbots_test_runner import TbotsTestRunner -from software.thunderscope.robot_communication import RobotCommunication -from software.thunderscope.estop_helpers import get_estop_config -from software.py_constants import * -from typing import override - -logger = create_logger(__name__) - -WORLD_BUFFER_TIMEOUT = 5.0 -PROCESS_BUFFER_DELAY_S = 0.01 -PAUSE_AFTER_FAIL_DELAY_S = 3 -LAUNCH_DELAY_S = 0.1 -TEST_END_DELAY = 0.3 - - -class FieldTestRunner(TbotsTestRunner): - """Run a field test""" - - def __init__( - self, - test_name, - thunderscope, - blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io, - gamecontroller, - publish_validation_protos=True, - is_yellow_friendly=False, - ): - """Initialize the FieldTestRunner - - :param test_name: The name of the test to run - :param thunderscope: The Thunderscope to use, None if not used - :param blue_full_system_proto_unix_io: The blue full system proto unix io to use - :param yellow_full_system_proto_unix_io: The yellow full system proto unix io to use - :param gamecontroller: The gamecontroller context managed instance - :param publish_validation_protos: whether to publish validation protos - :param: is_yellow_friendly: if yellow is the friendly team - """ - super(FieldTestRunner, self).__init__( - test_name, - thunderscope, - blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io, - gamecontroller, - is_yellow_friendly, - ) - self.publish_validation_protos = publish_validation_protos - self.is_yellow_friendly = is_yellow_friendly - - logger.info("determining robots on field") - # survey field for available robot ids - try: - world = self.world_buffer.get(block=True, timeout=WORLD_BUFFER_TIMEOUT) - self.initial_world = world - self.friendly_robot_ids_field = [ - robot.id for robot in world.friendly_team.team_robots - ] - - logger.info(f"friendly team ids {self.friendly_robot_ids_field}") - - if len(self.friendly_robot_ids_field) == 0: - raise Exception("no friendly robots found on field") - - except queue.Empty: - raise Exception( - f"No Worlds were received with in {WORLD_BUFFER_TIMEOUT} seconds. Please make sure atleast 1 robot and 1 ball is present on the field." - ) - - @override - def send_gamecontroller_command( - self, - gc_command: proto.ssl_gc_state_pb2.Command, - team: proto.ssl_gc_common_pb2.Team, - final_ball_placement_point=None, - ): - """Send a command to the gamecontroller - - :param gc_command: The command to send - :param team: The team which the command as attributed to - :param final_ball_placement_point: The ball placement point - """ - self.gamecontroller.send_ci_input( - gc_command=gc_command, - team=team, - final_ball_placement_point=final_ball_placement_point, - ) - - @override - def run_test( - self, - always_validation_sequence_set=[[]], - eventually_validation_sequence_set=[[]], - test_timeout_s=3, - ): - """Run a test. In a field test this means beginning validation. - - :param always_validation_sequence_set: Validation functions that should - hold on every tick - :param eventually_validation_sequence_set: Validation that should - eventually be true, before the test ends - :param test_timeout_s: The timeout for the test, if any eventually_validations - remain after the timeout, the test fails. - """ - - def stop_test(delay): - time.sleep(delay) - if self.thunderscope: - self.thunderscope.close() - - def __runner(): - time.sleep(LAUNCH_DELAY_S) - - test_end_time = time.time() + test_timeout_s - - while time.time() < test_end_time: - while True: - try: - world = self.world_buffer.get( - block=True, timeout=WORLD_BUFFER_TIMEOUT - ) - break - except queue.Empty: - # If we timeout, that means full_system missed the last - # wrapper and robot status, lets resend it. - logger.warning( - f"No World was received for {WORLD_BUFFER_TIMEOUT} seconds. Ending test early." - ) - - # Validate - ( - eventually_validation_proto_set, - always_validation_proto_set, - ) = validation.run_validation_sequence_sets( - world, - eventually_validation_sequence_set, - always_validation_sequence_set, - ) - - if self.publish_validation_protos: - # Set the test name - eventually_validation_proto_set.test_name = self.test_name - always_validation_proto_set.test_name = self.test_name - - # Send out the validation proto to thunderscope - self.blue_full_system_proto_unix_io.send_proto( - ValidationProtoSet, eventually_validation_proto_set - ) - self.blue_full_system_proto_unix_io.send_proto( - ValidationProtoSet, always_validation_proto_set - ) - - # Check that all always validations are always valid - validation.check_validation(always_validation_proto_set) - - # Check that all eventually validations are eventually valid - validation.check_validation(eventually_validation_proto_set) - stop_test(TEST_END_DELAY) - - def excepthook(args): - """This function is _critical_ for show_thunderscope to work. - If the test Thread will raises an exception we won't be able to close - the window from the main thread. - - :param args: The args passed in from the hook - """ - stop_test(delay=PAUSE_AFTER_FAIL_DELAY_S) - self.last_exception = args.exc_value - raise self.last_exception - - threading.excepthook = excepthook - - if self.thunderscope: - run_test_thread = threading.Thread(target=__runner, daemon=True) - run_test_thread.start() - self.thunderscope.show() - run_test_thread.join() - - if self.last_exception: - pytest.fail(str(ex.last_exception)) - - else: - __runner() - - -def load_command_line_arguments(): - """Load in command-line arguments using argparse - - NOTE: Pytest has its own built in argument parser (conftest.py, pytest_addoption) - but it doesn't seem to play nicely with bazel. We just use argparse instead. - """ - parser = argparse.ArgumentParser(description="Run simulated or field pytests") - parser.add_argument( - "--simulator_runtime_dir", - type=str, - help="simulator runtime directory", - default="/tmp/tbots", - ) - parser.add_argument( - "--blue_full_system_runtime_dir", - type=str, - help="blue full_system runtime directory", - default="/tmp/tbots/blue", - ) - parser.add_argument( - "--yellow_full_system_runtime_dir", - type=str, - help="yellow full_system runtime directory", - default="/tmp/tbots/yellow", - ) - parser.add_argument( - "--layout", - action="store", - help="Which layout to run, if not specified the last layout will run", - ) - parser.add_argument( - "--debug_blue_full_system", - action="store_true", - default=False, - help="Debug blue full_system", - ) - parser.add_argument( - "--debug_yellow_full_system", - action="store_true", - default=False, - help="Debug yellow full_system", - ) - parser.add_argument( - "--debug_simulator", - action="store_true", - default=False, - help="Debug the simulator", - ) - parser.add_argument( - "--visualization_buffer_size", - action="store", - type=int, - default=5, - help="How many packets to buffer while rendering", - ) - parser.add_argument( - "--show_gamecontroller_logs", - action="store_true", - default=False, - help="How many packets to buffer while rendering", - ) - parser.add_argument( - "--run_field_test", - action="store_true", - default=False, - help="whether to run test as a field test instead of a simulated test", - ) - parser.add_argument( - "--test_filter", - action="store", - default="", - help="The test filter, if not specified all tests will run. " - + "See https://docs.pytest.org/en/latest/how-to/usage.html#specifying-tests-selecting-tests", - ) - - parser.add_argument( - "--interface", - action="store", - type=str, - default=None, - help="Which interface to communicate over", - ) - - parser.add_argument( - "--channel", - action="store", - type=int, - default=0, - help="Which channel to communicate over", - ) - - parser.add_argument( - "--estop_baudrate", - action="store", - type=int, - default=115200, - help="Estop Baudrate", - ) - - parser.add_argument( - "--run_yellow", - action="store_true", - default=False, - help="Run the test with friendly robots in yellow mode", - ) - - estop_group = parser.add_mutually_exclusive_group() - estop_group.add_argument( - "--keyboard_estop", - action="store_true", - default=False, - help="Allows the use of the spacebar as an estop instead of a physical one", - ) - estop_group.add_argument( - "--disable_communication", - action="store_true", - default=False, - help="Disables checking for estop plugged in (ONLY USE FOR LOCAL TESTING)", - ) - - return parser.parse_args() - - -@pytest.fixture -def field_test_runner(): - """Runs a field test - - :return: yields the runner to the test fixture - """ - simulator_proto_unix_io = ProtoUnixIO() - yellow_full_system_proto_unix_io = ProtoUnixIO() - blue_full_system_proto_unix_io = ProtoUnixIO() - args = load_command_line_arguments() - - # Grab the current test name to store the proto log for the test case - current_test = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] - current_test = current_test.replace("]", "") - current_test = current_test.replace("[", "-") - - test_name = current_test.split("-")[0] - debug_full_sys = args.debug_blue_full_system - runtime_dir = f"{args.blue_full_system_runtime_dir}/test/{test_name}" - friendly_proto_unix_io = blue_full_system_proto_unix_io - - if args.run_yellow: - debug_full_sys = args.debug_yellow_full_system - runtime_dir = f"{args.yellow_full_system_runtime_dir}/test/{test_name}" - friendly_proto_unix_io = yellow_full_system_proto_unix_io - - estop_mode, estop_path = get_estop_config( - args.keyboard_estop, args.disable_communication - ) - - # Launch all binaries - with FullSystem( - "software/unix_full_system", - full_system_runtime_dir=runtime_dir, - debug_full_system=debug_full_sys, - friendly_colour_yellow=args.run_yellow, - should_restart_on_crash=False, - ) as friendly_fs, Gamecontroller( - # we would be using conventional port if and only if we are playing in robocup. - suppress_logs=(not args.show_gamecontroller_logs), - use_conventional_port=False, - ) as gamecontroller, WifiCommunicationManager( - current_proto_unix_io=friendly_proto_unix_io, - multicast_channel=getRobotMulticastChannel(args.channel), - should_setup_full_system=True, - interface=args.interface, - referee_port=gamecontroller.get_referee_port() - if gamecontroller - else SSL_REFEREE_PORT, - ) as wifi_communication_manager, RobotCommunication( - current_proto_unix_io=friendly_proto_unix_io, - communication_manager=wifi_communication_manager, - estop_mode=estop_mode, - estop_path=estop_path, - ) as rc_friendly: - friendly_fs.setup_proto_unix_io(friendly_proto_unix_io) - - gamecontroller.setup_proto_unix_io( - blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, - simulator_proto_unix_io=simulator_proto_unix_io, - ) - # Inject the proto unix ios into thunderscope and start the test - tscope = Thunderscope( - configure_field_test_view( - simulator_proto_unix_io=simulator_proto_unix_io, - blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, - yellow_is_friendly=args.run_yellow, - ), - layout_path=None, - ) - - # Set control mode for all robots to AI so that packets are sent to the robots - for robot_id in range(MAX_ROBOT_IDS_PER_SIDE): - rc_friendly.toggle_individual_robot_control_mode( - robot_id, - IndividualRobotMode.AI, - ) - - # connect the keyboard estop toggle to the key event if needed - if estop_mode == EstopMode.KEYBOARD_ESTOP: - tscope.keyboard_estop_shortcut.activated.connect( - rc_friendly.toggle_keyboard_estop - ) - # we call this method to enable estop automatically when a field test starts - rc_friendly.toggle_keyboard_estop() - logger.warning( - "\x1b[31;20m" - + "Keyboard Estop Enabled, robots will start moving automatically when test starts!" - + "\x1b[0m" - ) - - time.sleep(LAUNCH_DELAY_S) - runner = FieldTestRunner( - test_name=current_test, - blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, - gamecontroller=gamecontroller, - thunderscope=tscope, - is_yellow_friendly=args.run_yellow, - ) - - friendly_proto_unix_io.register_observer(World, runner.world_buffer) - - yield runner diff --git a/src/software/field_tests/movement_robot_field_test.py b/src/software/field_tests/movement_robot_field_test.py index 56c31df60b..d4455839ef 100644 --- a/src/software/field_tests/movement_robot_field_test.py +++ b/src/software/field_tests/movement_robot_field_test.py @@ -1,20 +1,28 @@ -from proto.import_all_protos import * -from software.field_tests.field_test_fixture import * +import math + +import pytest +import software.python_bindings as tbots_cpp -from software.simulated_tests.simulated_test_fixture import * +from proto.import_all_protos import * +from proto.message_translation.tbots_protobuf import create_world_state +from software.gameplay_tests.util import pytest_main +from software.gameplay_tests.validation.robot_enters_region import ( + RobotEventuallyEntersRegion, +) +from software.gameplay_tests.validation.delay_validation import DelayValidation from software.logger.logger import create_logger -import math logger = create_logger(__name__) +# TODO(#3744) -# TODO 2908: Support running this test in both simulator or field mode +# TODO(#2908): Support running this test in both simulator or field mode # this test can be run either in simulation or on the field # @pytest.mark.parametrize( # "robot_x_destination, robot_y_destination", # [(-2.0, -1), (-2.0, 1.0), (0.0, 1.0), (0.0, -1.0)], # ) -# def test_basic_movement(simulated_test_runner): +# def test_basic_movement(gameplay_test_runner): # # robot_starting_x = 0 # robot_starting_y = 0 @@ -40,7 +48,7 @@ # ball_location=tbots_cpp.Point(1, 1), # ball_velocity=tbots_cpp.Point(0, 0), # ) -# simulated_test_runner.set_world_state(initial_worldstate) +# gameplay_test_runner.set_world_state(initial_worldstate) # # # Setup Tactic # params = AssignedTacticPlayControlParams() @@ -59,145 +67,136 @@ # ), # ] # ] -# simulated_test_runner.set_tactics(params, True) +# gameplay_test_runner.set_tactics(params, True) # -# simulated_test_runner.run_test( +# gameplay_test_runner.run_test( # eventually_validation_sequence_set=eventually_validation_sequence_set, # test_timeout_s=5, # ) - +# TODO(#2908): uncomment this # this test can only be run on the field -def test_basic_rotation(field_test_runner): - test_angles = [0, 45, 90, 180, 270, 0] - - world = field_test_runner.world_buffer.get(block=True, timeout=WORLD_BUFFER_TIMEOUT) - if len(world.friendly_team.team_robots) == 0: - raise Exception("The first world received had no robots in it!") - - print("Here are the robots:") - print( - [ - robot.current_state.global_position - for robot in world.friendly_team.team_robots - ] - ) - - id = world.friendly_team.team_robots[0].id - print(f"Running test on robot {id}") - - robot = world.friendly_team.team_robots[0] - rob_pos_p = robot.current_state.global_position - logger.info("staying in pos {rob_pos_p}") - - for angle in test_angles: - move_tactic = MoveTactic() - move_tactic.destination.CopyFrom(rob_pos_p) - move_tactic.dribbler_mode = DribblerMode.OFF - move_tactic.final_orientation.CopyFrom(Angle(radians=angle)) - move_tactic.ball_collision_type = BallCollisionType.AVOID - move_tactic.auto_chip_or_kick.CopyFrom( - AutoChipOrKick(autokick_speed_m_per_s=0.0) +# def test_basic_rotation(field_test_runner): +# test_angles = [0, 45, 90, 180, 270, 0] +# +# world = field_test_runner.world_buffer.get(block=True, timeout=WORLD_BUFFER_TIMEOUT) +# if len(world.friendly_team.team_robots) == 0: +# raise Exception("The first world received had no robots in it!") +# +# print("Here are the robots:") +# print( +# [ +# robot.current_state.global_position +# for robot in world.friendly_team.team_robots +# ] +# ) +# +# id = world.friendly_team.team_robots[0].id +# print(f"Running test on robot {id}") +# +# robot = world.friendly_team.team_robots[0] +# rob_pos_p = robot.current_state.global_position +# logger.info("staying in pos {rob_pos_p}") +# +# for angle in test_angles: +# move_tactic = MoveTactic() +# move_tactic.destination.CopyFrom(rob_pos_p) +# move_tactic.dribbler_mode = DribblerMode.OFF +# move_tactic.final_orientation.CopyFrom(Angle(radians=angle)) +# move_tactic.ball_collision_type = BallCollisionType.AVOID +# move_tactic.auto_chip_or_kick.CopyFrom( +# AutoChipOrKick(autokick_speed_m_per_s=0.0) +# ) +# move_tactic.max_allowed_speed_mode = MaxAllowedSpeedMode.PHYSICAL_LIMIT +# move_tactic.obstacle_avoidance_mode = ObstacleAvoidanceMode.SAFE +# +# # Setup Tactic +# field_test_runner.set_tactics( +# blue_tactics={id: move_tactic}, yellow_tactics=None +# ) +# field_test_runner.run_test( +# always_validation_sequence_set=[[]], +# eventually_validation_sequence_set=[[]], +# test_timeout_s=5, +# ) +# # Send a halt tactic after the test finishes +# field_test_runner.set_tactics( +# blue_tactics={id: HaltTactic()}, yellow_tactics=None +# ) +# +# # validate by eye +# logger.info(f"robot set to {angle} orientation") +# +# time.sleep(2) + + +@pytest.mark.parametrize( + "start_position, end_position", + [ + ( + tbots_cpp.Point(-1.5, 0.6), + tbots_cpp.Point(-0.3, 0.6), + ), + ( + tbots_cpp.Point(-0.3, 0.6), + tbots_cpp.Point(-0.3, -0.6), + ), + ( + tbots_cpp.Point(-0.3, -0.6), + tbots_cpp.Point(-1.5, -0.6), + ), + ( + tbots_cpp.Point(-1.5, -0.6), + tbots_cpp.Point(-1.5, 0.6), + ), + ], +) +def test_one_robots_square(start_position, end_position, gameplay_test_runner): + def setup(): + gameplay_test_runner.set_world_state( + create_world_state( + blue_robot_locations=[ + start_position, + ], + yellow_robot_locations=[], + ball_location=tbots_cpp.Point(0, 0), + ball_velocity=tbots_cpp.Vector(0, 0), + ), ) - move_tactic.max_allowed_speed_mode = MaxAllowedSpeedMode.PHYSICAL_LIMIT - move_tactic.obstacle_avoidance_mode = ObstacleAvoidanceMode.SAFE - # Setup Tactic - field_test_runner.set_tactics( - blue_tactics={id: move_tactic}, yellow_tactics=None - ) - field_test_runner.run_test( - always_validation_sequence_set=[[]], - eventually_validation_sequence_set=[[]], - test_timeout_s=5, + tactic = MoveTactic( + destination=tbots_cpp.createPointProto(end_position), + dribbler_mode=DribblerMode.OFF, + final_orientation=Angle(radians=-math.pi / 2), + ball_collision_type=BallCollisionType.AVOID, + auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), + max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, + obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, ) - # Send a halt tactic after the test finishes - field_test_runner.set_tactics( - blue_tactics={id: HaltTactic()}, yellow_tactics=None - ) - - # validate by eye - logger.info(f"robot set to {angle} orientation") - - time.sleep(2) - - -def test_one_robots_square(field_test_runner): - world = field_test_runner.world_buffer.get(block=True, timeout=WORLD_BUFFER_TIMEOUT) - if len(world.friendly_team.team_robots) == 0: - raise Exception("The first world received had no robots in it!") - - print("Here are the robots:") - print( - [ - robot.current_state.global_position - for robot in world.friendly_team.team_robots - ] - ) - id = world.friendly_team.team_robots[0].id - print(f"Running test on robot {id}") - - point1 = Point(x_meters=-0.3, y_meters=0.6) - point2 = Point(x_meters=-0.3, y_meters=-0.6) - point3 = Point(x_meters=-1.5, y_meters=-0.6) - point4 = Point(x_meters=-1.5, y_meters=0.6) - - tactic_0 = MoveTactic( - destination=point1, - dribbler_mode=DribblerMode.OFF, - final_orientation=Angle(radians=-math.pi / 2), - ball_collision_type=BallCollisionType.AVOID, - auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), - max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, - obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, - ) - tactic_1 = MoveTactic( - destination=point2, - dribbler_mode=DribblerMode.OFF, - final_orientation=Angle(radians=-math.pi / 2), - ball_collision_type=BallCollisionType.AVOID, - auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), - max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, - obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, - ) - tactic_2 = MoveTactic( - destination=point3, - dribbler_mode=DribblerMode.OFF, - final_orientation=Angle(radians=-math.pi / 2), - ball_collision_type=BallCollisionType.AVOID, - auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), - max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, - obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, - ) - tactic_3 = MoveTactic( - destination=point4, - dribbler_mode=DribblerMode.OFF, - final_orientation=Angle(radians=-math.pi / 2), - ball_collision_type=BallCollisionType.AVOID, - auto_chip_or_kick=AutoChipOrKick(autokick_speed_m_per_s=0.0), - max_allowed_speed_mode=MaxAllowedSpeedMode.PHYSICAL_LIMIT, - obstacle_avoidance_mode=ObstacleAvoidanceMode.SAFE, - ) - tactics = [tactic_0, tactic_1, tactic_2, tactic_3] - - for tactic in tactics: - print(f"Going to {tactic.destination}") - - field_test_runner.set_tactics( + gameplay_test_runner.set_tactics( blue_tactics={ - id: tactic, + 0: tactic, }, - yellow_tactics=None, - ) - field_test_runner.run_test( - always_validation_sequence_set=[[]], - eventually_validation_sequence_set=[[]], - test_timeout_s=4, ) - # Send a halt tactic after the test finishes - field_test_runner.set_tactics(blue_tactics={id: HaltTactic()}, yellow_tactics=None) + gameplay_test_runner.run_test( + setup=setup, + test_timeout_s=4, + eventually_validation_sequence_set=[ + [ + RobotEventuallyEntersRegion( + regions=[tbots_cpp.Circle(end_position, 0.05)] + ), + DelayValidation( + delay_s=1, + validation=RobotEventuallyEntersRegion( + regions=[tbots_cpp.Circle(end_position, 0.05)] + ), + ), + ] + ], + ) if __name__ == "__main__": diff --git a/src/software/field_tests/passing_field_test.py b/src/software/field_tests/passing_field_test.py index 43785bb5d4..e6e2ab13fe 100644 --- a/src/software/field_tests/passing_field_test.py +++ b/src/software/field_tests/passing_field_test.py @@ -1,13 +1,14 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.field_tests.field_test_fixture import * -from software.simulated_tests.validation.friendly_receives_ball_slow import ( +from software.gameplay_tests.util import * +from software.gameplay_tests.validation.friendly_receives_ball_slow import ( FriendlyAlwaysReceivesBallSlow, ) -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) +# TODO(#3744) def test_passing(field_test_runner): passer_robot_id = 3 diff --git a/src/software/field_tests/pivot_kick_field_test.py b/src/software/field_tests/pivot_kick_field_test.py index 6205bf12cf..553e1f0cb0 100644 --- a/src/software/field_tests/pivot_kick_field_test.py +++ b/src/software/field_tests/pivot_kick_field_test.py @@ -1,15 +1,16 @@ import math from proto.import_all_protos import * -from software.field_tests.field_test_fixture import * +from software.gameplay_tests.util import * -from software.simulated_tests.simulated_test_fixture import * +from software.gameplay_tests.util import * from software.logger.logger import create_logger -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) logger = create_logger(__name__) +# TODO(#3744) def test_pivot_kick(field_test_runner): id = 5 diff --git a/src/software/simulated_tests/BUILD b/src/software/gameplay_tests/BUILD similarity index 60% rename from src/software/simulated_tests/BUILD rename to src/software/gameplay_tests/BUILD index d1acb78f3e..8298fdf4cf 100644 --- a/src/software/simulated_tests/BUILD +++ b/src/software/gameplay_tests/BUILD @@ -1,5 +1,5 @@ load("@rules_python//python:pip.bzl", "compile_pip_requirements") -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) @@ -10,63 +10,69 @@ compile_pip_requirements( ) py_library( - name = "tbots_test_runner", + name = "fixture", srcs = [ - "tbots_test_runner.py", - ], - data = [ - "//software:py_constants.so", + "fixture.py", ], deps = [ - "//proto:import_all_protos", + ":util", + ":field_test_runner", + ":simulated_test_runner", + "//software/thunderscope:estop_helpers", "//software/logger:py_logger", - "//software/networking/unix:threaded_unix_listener_py", - "//software/networking/unix:threaded_unix_sender_py", - "//software/simulated_tests/validation:validations", - "//software/thunderscope", - "//software/thunderscope:config", - "//software/thunderscope:constants", - "//software/thunderscope:time_provider", + "//software/thunderscope:thunderscope", "//software/thunderscope/binary_context_managers:full_system", "//software/thunderscope/binary_context_managers:game_controller", "//software/thunderscope/binary_context_managers:simulator", + requirement("pytest"), ], ) py_library( - name = "simulated_test_fixture", + name = "tbots_test_runner", srcs = [ - "simulated_test_fixture.py", - ], - data = [ - "//software:py_constants.so", + "tbots_test_runner.py", ], deps = [ - ":tbots_test_runner", "//proto:import_all_protos", "//software/logger:py_logger", "//software/networking/unix:threaded_unix_listener_py", "//software/networking/unix:threaded_unix_sender_py", - "//software/simulated_tests/validation:validations", - "//software/thunderscope", + "//software/gameplay_tests/validation:validations", + "//software/thunderscope:thunderscope", + "//software/thunderscope:config", + "//software/thunderscope:constants", + "//software/thunderscope:time_provider", "//software/thunderscope/binary_context_managers:full_system", "//software/thunderscope/binary_context_managers:game_controller", "//software/thunderscope/binary_context_managers:simulator", ], ) -py_test( - name = "simulated_test_ball_model", +py_library( + name = "field_test_runner", srcs = [ - "simulated_test_ball_model.py", + "field_test_runner.py", + ], + deps = [ + ":tbots_test_runner" ], - # TODO (#2619) Remove tag to run in parallel - tags = [ - "exclusive", +) + +py_library( + name = "simulated_test_runner", + srcs = [ + "simulated_test_runner.py", ], deps = [ - "//software:conftest", - "//software/simulated_tests/validation:validations", - requirement("pytest"), + ":tbots_test_runner" + ], +) + +py_library( + name = "util", + srcs = [ + "util.py", ], + deps = [], ) diff --git a/src/software/gameplay_tests/field_test_runner.py b/src/software/gameplay_tests/field_test_runner.py new file mode 100644 index 0000000000..c9a5555f6b --- /dev/null +++ b/src/software/gameplay_tests/field_test_runner.py @@ -0,0 +1,181 @@ +import queue +import time +import threading + +import pytest +from proto.import_all_protos import * + +from software.gameplay_tests.validation import validation +from software.logger.logger import create_logger + + +from software.gameplay_tests.tbots_test_runner import TbotsTestRunner +from software.py_constants import * +from typing import override + +logger = create_logger(__name__) + +WORLD_BUFFER_TIMEOUT = 5.0 +PROCESS_BUFFER_DELAY_S = 0.01 +PAUSE_AFTER_FAIL_DELAY_S = 3 +LAUNCH_DELAY_S = 0.1 +TEST_END_DELAY = 0.3 + + +class FieldTestRunner(TbotsTestRunner): + """Run a field test""" + + def __init__( + self, + test_name, + thunderscope, + blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io, + gamecontroller, + publish_validation_protos=True, + is_yellow_friendly=False, + ): + """Initialize the FieldTestRunner + + :param test_name: The name of the test to run + :param thunderscope: The Thunderscope to use, None if not used + :param blue_full_system_proto_unix_io: The blue full system proto unix io to use + :param yellow_full_system_proto_unix_io: The yellow full system proto unix io to use + :param gamecontroller: The gamecontroller context managed instance + :param publish_validation_protos: whether to publish validation protos + :param: is_yellow_friendly: if yellow is the friendly team + """ + super(FieldTestRunner, self).__init__( + test_name, + thunderscope, + blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io, + gamecontroller, + is_yellow_friendly, + ) + self.publish_validation_protos = publish_validation_protos + self.is_yellow_friendly = is_yellow_friendly + + logger.info("determining robots on field") + # survey field for available robot ids + try: + world = self.world_buffer.get(block=True, timeout=WORLD_BUFFER_TIMEOUT) + self.initial_world = world + self.friendly_robot_ids_field = [ + robot.id for robot in world.friendly_team.team_robots + ] + + logger.info(f"friendly team ids {self.friendly_robot_ids_field}") + + if len(self.friendly_robot_ids_field) == 0: + raise Exception("no friendly robots found on field") + + except queue.Empty: + raise Exception( + f"No Worlds were received with in {WORLD_BUFFER_TIMEOUT} seconds. Please make sure atleast 1 robot and 1 ball is present on the field." + ) + + @override + def set_world_state(self, world_state: WorldState): + """Does nothing... TODO + + :param world_state: The WorldState proto to use + """ + pass + + @override + def run_test( + self, + setup=lambda: None, + always_validation_sequence_set=[[]], + eventually_validation_sequence_set=[[]], + test_timeout_s=3, + ): + """Run a test. In a field test this means beginning validation. + + :param always_validation_sequence_set: Validation functions that should + hold on every tick + :param eventually_validation_sequence_set: Validation that should + eventually be true, before the test ends + :param test_timeout_s: The timeout for the test, if any eventually_validations + remain after the timeout, the test fails. + """ + + def stop_test(delay): + time.sleep(delay) + if self.thunderscope: + self.thunderscope.close() + + def runner(): + time.sleep(LAUNCH_DELAY_S) + + test_end_time = time.time() + test_timeout_s + + while time.time() < test_end_time: + while True: + try: + world = self.world_buffer.get( + block=True, timeout=WORLD_BUFFER_TIMEOUT + ) + break + except queue.Empty: + # If we timeout, that means full_system missed the last + # wrapper and robot status, lets resend it. + logger.warning( + f"No World was received for {WORLD_BUFFER_TIMEOUT} seconds. Ending test early." + ) + + # Validate + ( + eventually_validation_proto_set, + always_validation_proto_set, + ) = validation.run_validation_sequence_sets( + world, + eventually_validation_sequence_set, + always_validation_sequence_set, + ) + + if self.publish_validation_protos: + # Set the test name + eventually_validation_proto_set.test_name = self.test_name + always_validation_proto_set.test_name = self.test_name + + # Send out the validation proto to thunderscope + self.blue_full_system_proto_unix_io.send_proto( + ValidationProtoSet, eventually_validation_proto_set + ) + self.blue_full_system_proto_unix_io.send_proto( + ValidationProtoSet, always_validation_proto_set + ) + + # Check that all always validations are always valid + validation.check_validation(always_validation_proto_set) + + # Check that all eventually validations are eventually valid + validation.check_validation(eventually_validation_proto_set) + stop_test(TEST_END_DELAY) + + def excepthook(args): + """This function is _critical_ for show_thunderscope to work. + If the test Thread will raises an exception we won't be able to close + the window from the main thread. + + :param args: The args passed in from the hook + """ + stop_test(delay=PAUSE_AFTER_FAIL_DELAY_S) + self.last_exception = args.exc_value + raise self.last_exception + + threading.excepthook = excepthook + + if self.thunderscope: + run_test_thread = threading.Thread(target=runner, daemon=True) + run_test_thread.start() + self.thunderscope.show() + run_test_thread.join() + + if self.last_exception: + pytest.fail(str(ex.last_exception)) + + else: + runner() diff --git a/src/software/gameplay_tests/fixture.py b/src/software/gameplay_tests/fixture.py new file mode 100644 index 0000000000..2a218b9000 --- /dev/null +++ b/src/software/gameplay_tests/fixture.py @@ -0,0 +1,221 @@ +import time + +import pytest +from software.py_constants import ( + MAX_ROBOT_IDS_PER_SIDE, + SSL_REFEREE_PORT, + getRobotMulticastChannel, +) + +from proto.import_all_protos import World +from software.gameplay_tests.field_test_runner import FieldTestRunner +from software.gameplay_tests.simulated_test_runner import SimulatedTestRunner +from software.gameplay_tests.util import get_current_pytest, load_command_line_arguments +from software.logger.logger import create_logger +from software.thunderscope.binary_context_managers.full_system import FullSystem +from software.thunderscope.binary_context_managers.game_controller import Gamecontroller +from software.thunderscope.binary_context_managers.simulator import Simulator +from software.thunderscope.constants import EstopMode, IndividualRobotMode +from software.thunderscope.estop_helpers import get_estop_config +from software.thunderscope.proto_unix_io import ProtoUnixIO +from software.thunderscope.robot_communication import RobotCommunication +from software.thunderscope.thunderscope import Thunderscope +from software.thunderscope.thunderscope_config import ( + configure_field_test_view, + configure_simulated_test_view, +) +from software.thunderscope.wifi_communication_manager import WifiCommunicationManager + +logger = create_logger(__name__) + +LAUNCH_DELAY_S = 0.1 + + +@pytest.fixture +def gameplay_test_runner(): + args = load_command_line_arguments(allow_unrecognized=True) + + if args.run_field_test: + yield from create_field_test_runner(args) + else: + yield from create_simulated_test_runner(args) + + +def create_field_test_runner(args): + # Grab the current test name to store the proto log for the test case + current_test = get_current_pytest() + test_name = get_current_pytest().split("-")[0] + + simulator_proto_unix_io = ProtoUnixIO() + yellow_full_system_proto_unix_io = ProtoUnixIO() + blue_full_system_proto_unix_io = ProtoUnixIO() + + runtime_dir = f"{args.blue_full_system_runtime_dir}/test/{test_name}" + friendly_proto_unix_io = blue_full_system_proto_unix_io + + if args.run_yellow: + debug_full_sys = args.debug_yellow_full_system + runtime_dir = f"{args.yellow_full_system_runtime_dir}/test/{test_name}" + friendly_proto_unix_io = yellow_full_system_proto_unix_io + + estop_mode, estop_path = get_estop_config( + args.keyboard_estop, args.disable_communication + ) + + # Launch all binaries + with ( + FullSystem( + "software/unix_full_system", + full_system_runtime_dir=runtime_dir, + debug_full_system=debug_full_sys, + friendly_colour_yellow=args.run_yellow, + should_restart_on_crash=False, + ) as friendly_fs, + Gamecontroller( + # we would be using conventional port if and only if we are playing in robocup. + suppress_logs=(not args.show_gamecontroller_logs), + use_conventional_port=False, + ) as gamecontroller, + WifiCommunicationManager( + current_proto_unix_io=friendly_proto_unix_io, + multicast_channel=getRobotMulticastChannel(args.channel), + should_setup_full_system=True, + interface=args.interface, + referee_port=gamecontroller.get_referee_port() + if gamecontroller + else SSL_REFEREE_PORT, + ) as wifi_communication_manager, + RobotCommunication( + current_proto_unix_io=friendly_proto_unix_io, + communication_manager=wifi_communication_manager, + estop_mode=estop_mode, + estop_path=estop_path, + ) as rc_friendly, + ): + friendly_fs.setup_proto_unix_io(friendly_proto_unix_io) + + gamecontroller.setup_proto_unix_io( + blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, + simulator_proto_unix_io=simulator_proto_unix_io, + ) + # Inject the proto unix ios into thunderscope and start the test + tscope = Thunderscope( + configure_field_test_view( + simulator_proto_unix_io=simulator_proto_unix_io, + blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, + yellow_is_friendly=args.run_yellow, + ), + layout_path=None, + ) + + # Set control mode for all robots to AI so that packets are sent to the robots + for robot_id in range(MAX_ROBOT_IDS_PER_SIDE): + rc_friendly.toggle_individual_robot_control_mode( + robot_id, + IndividualRobotMode.AI, + ) + + # connect the keyboard estop toggle to the key event if needed + if estop_mode == EstopMode.KEYBOARD_ESTOP: + tscope.keyboard_estop_shortcut.activated.connect( + rc_friendly.toggle_keyboard_estop + ) + # we call this method to enable estop automatically when a field test starts + rc_friendly.toggle_keyboard_estop() + logger.warning( + "\x1b[31;20m" + + "Keyboard Estop Enabled, robots will start moving automatically when test starts!" + + "\x1b[0m" + ) + + time.sleep(LAUNCH_DELAY_S) + runner = FieldTestRunner( + test_name=current_test, + blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, + gamecontroller=gamecontroller, + thunderscope=tscope, + is_yellow_friendly=args.run_yellow, + ) + + friendly_proto_unix_io.register_observer(World, runner.world_buffer) + + yield runner + + +def create_simulated_test_runner(args): + # Grab the current test name to store the proto log for the test case + current_test = get_current_pytest() + test_name = get_current_pytest().split("-")[0] + + simulator_proto_unix_io = ProtoUnixIO() + yellow_full_system_proto_unix_io = ProtoUnixIO() + blue_full_system_proto_unix_io = ProtoUnixIO() + + with ( + FullSystem( + "software/unix_full_system", + f"{args.blue_full_system_runtime_dir}/test/{test_name}", + args.debug_blue_full_system, + False, + should_restart_on_crash=False, + running_in_realtime=args.enable_thunderscope, + ) as blue_fs, + FullSystem( + "software/unix_full_system", + f"{args.yellow_full_system_runtime_dir}/test/{test_name}", + args.debug_yellow_full_system, + True, + should_restart_on_crash=False, + running_in_realtime=args.enable_thunderscope, + ) as yellow_fs, + Simulator( + f"{args.simulator_runtime_dir}/test/{test_name}", + args.debug_simulator, + args.enable_realism, + ) as simulator, + ): + with Gamecontroller( + suppress_logs=(not args.show_gamecontroller_logs) + ) as gamecontroller: + blue_fs.setup_proto_unix_io(blue_full_system_proto_unix_io) + yellow_fs.setup_proto_unix_io(yellow_full_system_proto_unix_io) + simulator.setup_proto_unix_io( + simulator_proto_unix_io, + blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io, + ProtoUnixIO(), + ) + gamecontroller.setup_proto_unix_io( + blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, + simulator_proto_unix_io=simulator_proto_unix_io, + ) + + # If we want to run thunderscope, inject the proto unix ios + # and start the test + tscope = None + if args.enable_thunderscope: + tscope = Thunderscope( + configure_simulated_test_view( + blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, + simulator_proto_unix_io=simulator_proto_unix_io, + ), + layout_path=args.layout, + ) + + time.sleep(LAUNCH_DELAY_S) + + runner = SimulatedTestRunner( + current_test, + tscope, + simulator_proto_unix_io, + blue_full_system_proto_unix_io, + yellow_full_system_proto_unix_io, + gamecontroller, + ) + + yield runner diff --git a/src/software/simulated_tests/requirements.in b/src/software/gameplay_tests/requirements.in similarity index 100% rename from src/software/simulated_tests/requirements.in rename to src/software/gameplay_tests/requirements.in diff --git a/src/software/simulated_tests/requirements_lock.txt b/src/software/gameplay_tests/requirements_lock.txt similarity index 92% rename from src/software/simulated_tests/requirements_lock.txt rename to src/software/gameplay_tests/requirements_lock.txt index 8bf6d03071..e563375bdc 100644 --- a/src/software/simulated_tests/requirements_lock.txt +++ b/src/software/gameplay_tests/requirements_lock.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.12 # by the following command: # -# bazel run //software/simulated_tests:requirements.update +# bazel run //software/gameplay_tests:requirements.update # attrs==23.2.0 \ --hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \ @@ -27,7 +27,7 @@ py==1.11.0 \ pytest==6.2.5 \ --hash=sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89 \ --hash=sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134 - # via -r software/simulated_tests/requirements.in + # via -r software/gameplay_tests/requirements.in toml==0.10.2 \ --hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \ --hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f diff --git a/src/software/simulated_tests/simulated_test_fixture.py b/src/software/gameplay_tests/simulated_test_runner.py similarity index 50% rename from src/software/simulated_tests/simulated_test_fixture.py rename to src/software/gameplay_tests/simulated_test_runner.py index 25e92dce64..617883aa31 100644 --- a/src/software/simulated_tests/simulated_test_fixture.py +++ b/src/software/gameplay_tests/simulated_test_runner.py @@ -1,26 +1,16 @@ -import threading import queue -import argparse +import threading import time -import sys -import os +from typing import override import pytest -from proto.import_all_protos import * - -from software.simulated_tests.validation import validation -from software.simulated_tests.tbots_test_runner import TbotsTestRunner -from software.thunderscope.thunderscope import Thunderscope -from software.thunderscope.proto_unix_io import ProtoUnixIO from software.py_constants import MILLISECONDS_PER_SECOND -from software.thunderscope.binary_context_managers.full_system import FullSystem -from software.thunderscope.binary_context_managers.simulator import Simulator -from software.thunderscope.binary_context_managers.game_controller import Gamecontroller -from software.thunderscope.thunderscope_config import configure_simulated_test_view -from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer +from proto.import_all_protos import * from software.logger.logger import create_logger -from typing import override +from software.gameplay_tests.tbots_test_runner import TbotsTestRunner +from software.gameplay_tests.validation import validation +from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer logger = create_logger(__name__) @@ -61,12 +51,76 @@ def __init__( self.simulator_proto_unix_io = simulator_proto_unix_io @override - def set_world_state(self, worldstate: WorldState): - """Sets the simulation worldstate + def set_world_state(self, world_state: WorldState): + """Sets the world state of the simulator. + + :param world_state: The WorldState proto to use + """ + self.simulator_proto_unix_io.send_proto(WorldState, world_state) + + @override + def run_test( + self, + setup=lambda: None, + always_validation_sequence_set=[[]], + eventually_validation_sequence_set=[[]], + test_timeout_s=3, + tick_duration_s=0.0166, # Default to 60hz + ci_cmd_with_delay=[], + run_till_end=True, + ): + """Helper function to run a test, with thunderscope if enabled - :param worldstate: proto containing the desired worldstate + :param always_validation_sequence_set: validation that should always be true + :param eventually_validation_sequence_set: validation that should eventually be true + :param test_timeout_s: how long the test should run before timing out + :param tick_duration_s: length of a tick + :param ci_cmd_with_delay: A list consisting of tuples with a duration and CI command, e.g. + [ + (time, command, team), + (time, command, team), + ... + ] + :param run_till_end: If true, test runs till the end even if eventually validation passes + If false, test stops once eventually validation passes and fails if time out """ - self.simulator_proto_unix_io.send_proto(WorldState, worldstate) + + threading.excepthook = self.excepthook + self.sync_setup(setup) + + # If thunderscope is enabled, run the test in a thread and show + # thunderscope on this thread. The excepthook is setup to catch + # any test failures and propagate them to the main thread + if self.thunderscope: + run_sim_thread = threading.Thread( + target=self.runner, + daemon=True, + args=[ + always_validation_sequence_set, + eventually_validation_sequence_set, + test_timeout_s, + tick_duration_s, + ci_cmd_with_delay, + run_till_end, + ], + ) + run_sim_thread.start() + self.thunderscope.show() + run_sim_thread.join() + + if self.last_exception: + pytest.fail(str(self.last_exception)) + + # If thunderscope is disabled, just run the test + else: + self.runner( + always_validation_sequence_set, + eventually_validation_sequence_set, + test_timeout_s, + tick_duration_s, + ci_cmd_with_delay=ci_cmd_with_delay, + run_till_end=run_till_end, + ) def excepthook(self, args): """This function is _critical_ for show_thunderscope to work. @@ -90,7 +144,7 @@ def __stopper(self, delay=PROCESS_BUFFER_DELAY_S): if self.thunderscope: self.thunderscope.close() - def sync_setup(self, setup, param): + def sync_setup(self, setup): """Run setup until simulator has received game state :param setup: Function that sets up the world state @@ -102,7 +156,7 @@ def sync_setup(self, setup, param): ) while True: - setup(param) + setup() try: world_state_received_buffer.get( @@ -250,358 +304,3 @@ def runner( validation.check_validation(eventually_validation_proto_set) self.__stopper() - - @override - def run_test( - self, - always_validation_sequence_set, - eventually_validation_sequence_set, - test_timeout_s=3, - tick_duration_s=0.0166, # Default to 60hz - index=0, - ci_cmd_with_delay=[], - run_till_end=True, - **kwargs, - ): - """Helper function to run a test, with thunderscope if enabled - - :param always_validation_sequence_set: validation that should always be true - :param eventually_validation_sequence_set: validation that should eventually be true - :param test_timeout_s: how long the test should run before timing out - :param tick_duration_s: length of a tick - :param index: index of the current test. default is 0 (invariant test) - values can be passed in during aggregate testing for different timeout durations - :param ci_cmd_with_delay: A list consisting of tuples with a duration and CI command, e.g. - [ - (time, command, team), - (time, command, team), - ... - ] - :param run_till_end: If true, test runs till the end even if eventually validation passes - If false, test stops once eventually validation passes and fails if time out - """ - test_timeout_duration = ( - test_timeout_s[index] if type(test_timeout_s) == list else test_timeout_s - ) - - # If thunderscope is enabled, run the test in a thread and show - # thunderscope on this thread. The excepthook is setup to catch - # any test failures and propagate them to the main thread - if self.thunderscope: - run_sim_thread = threading.Thread( - target=self.runner, - daemon=True, - args=[ - always_validation_sequence_set, - eventually_validation_sequence_set, - test_timeout_duration, - tick_duration_s, - ci_cmd_with_delay, - run_till_end, - ], - ) - run_sim_thread.start() - self.thunderscope.show() - run_sim_thread.join() - - if self.last_exception: - pytest.fail(str(self.last_exception)) - - # If thunderscope is disabled, just run the test - else: - self.runner( - always_validation_sequence_set, - eventually_validation_sequence_set, - test_timeout_duration, - tick_duration_s, - ci_cmd_with_delay=ci_cmd_with_delay, - run_till_end=run_till_end, - ) - - -class InvariantTestRunner(SimulatedTestRunner): - """Runs a simulated test only once with a given parameter - - Test passes or fails based on the outcome of this test - """ - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - @override - def run_test( - self, - setup=(lambda x: None), - params=[0], - inv_always_validation_sequence_set=[[]], - inv_eventually_validation_sequence_set=[[]], - **kwargs, - ): - """Run an invariant test - - :param setup: Function that sets up the World state and the gamecontroller before running the test - :param params: List of parameters for each iteration of the test - (this method only uses the first element) - :param inv_always_validation_sequence_set: Validation functions for invariant testing - that should hold on every tick - :param inv_eventually_validation_sequence_set: Validation functions for invariant testing - that should eventually be true, before the test ends - """ - threading.excepthook = self.excepthook - - super().sync_setup(setup, params[0]) - - super().run_test( - inv_always_validation_sequence_set, - inv_eventually_validation_sequence_set, - **kwargs, - ) - - -class AggregateTestRunner(SimulatedTestRunner): - """Runs a simulated test multiple times with different given parameters - - Result of the test is determined by comparing the number of - passing iterations to a predetermined acceptable threshold - """ - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - @override - def run_test( - self, - setup=(lambda arg: None), - params=[], - ag_always_validation_sequence_set=[[]], - ag_eventually_validation_sequence_set=[[]], - **kwargs, - ): - """Run an aggregate test - - :param setup: Function that sets up the World state and the gamecontroller before running the test - :param params: List of parameters for each iteration of the test - :param ag_always_validation_sequence_set: Validation functions for aggregate testing - that should hold on every tick - :param ag_eventually_validation_sequence_set: Validation functions for aggregate testing - that should eventually be true, before the test end - """ - threading.excepthook = self.excepthook - - failed_tests = 0 - - # Runs the test once for each given parameter - # Catches Assertion Error thrown by failing test and increments counter - # Calculates overall results and prints them - for x in range(len(params)): - super().sync_setup(setup, params[x]) - - try: - super().run_test( - ag_always_validation_sequence_set, - ag_eventually_validation_sequence_set, - **kwargs, - ) - except AssertionError: - failed_tests += 1 - - # TODO (#2856) Fix validation and results output - - logger.info(f"{failed_tests} test failed") - - assert failed_tests == 0 - - -def load_command_line_arguments(allow_unrecognized: bool = False): - """Load in command-line arguments using argparse - - NOTE: Pytest has its own built in argument parser (conftest.py, pytest_addoption) - but it doesn't seem to play nicely with bazel. We just use argparse instead. - - :param allow_unrecognized: if true, does not raise an error for unrecognized arguments - """ - parser = argparse.ArgumentParser(description="Run simulated pytests") - parser.add_argument( - "--enable_thunderscope", action="store_true", help="enable thunderscope" - ) - parser.add_argument( - "--aggregate", action="store_true", default=False, help="Run aggregate test" - ) - parser.add_argument( - "--simulator_runtime_dir", - type=str, - help="simulator runtime directory", - default="/tmp/tbots", - ) - parser.add_argument( - "--blue_full_system_runtime_dir", - type=str, - help="blue full_system runtime directory", - default="/tmp/tbots/blue", - ) - parser.add_argument( - "--yellow_full_system_runtime_dir", - type=str, - help="yellow full_system runtime directory", - default="/tmp/tbots/yellow", - ) - parser.add_argument( - "--layout", - action="store", - help="Which layout to run, if not specified the last layout will run", - ) - parser.add_argument( - "--debug_blue_full_system", - action="store_true", - default=False, - help="Debug blue full_system", - ) - parser.add_argument( - "--debug_yellow_full_system", - action="store_true", - default=False, - help="Debug yellow full_system", - ) - parser.add_argument( - "--debug_simulator", - action="store_true", - default=False, - help="Debug the simulator", - ) - parser.add_argument( - "--visualization_buffer_size", - action="store", - type=int, - default=5, - help="How many packets to buffer while rendering", - ) - parser.add_argument( - "--show_gamecontroller_logs", - action="store_true", - default=False, - help="Show gamecontroller logs", - ) - parser.add_argument( - "--test_filter", - action="store", - default="", - help="The test filter, if not specified all tests will run. " - + "See https://docs.pytest.org/en/latest/how-to/usage.html#specifying-tests-selecting-tests", - ) - parser.add_argument( - "--enable_realism", - action="store_true", - default=False, - help="Use realism in the simulator", - ) - return parser.parse_known_args()[0] if allow_unrecognized else parser.parse_args() - - -def pytest_main(file): - """Runs the pytest file - - :param file: The test file to run - """ - args = load_command_line_arguments(allow_unrecognized=True) - - # Run the test, -s disables all capturing at -vv increases verbosity - # -W ignore::DeprecationWarning ignores deprecation warnings that spam the output - sys.exit( - pytest.main( - ["-svv", "-W ignore::DeprecationWarning", "-k", args.test_filter, file] - ) - ) - - -@pytest.fixture -def simulated_test_runner(): - args = load_command_line_arguments() - tscope = None - - aggregate = args.aggregate - - simulator_proto_unix_io = ProtoUnixIO() - yellow_full_system_proto_unix_io = ProtoUnixIO() - blue_full_system_proto_unix_io = ProtoUnixIO() - - # Grab the current test name to store the proto log for the test case - current_test = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] - current_test = current_test.replace("]", "") - current_test = current_test.replace("[", "-") - - test_name = current_test.split("-")[0] - - # Launch all binaries - with Simulator( - f"{args.simulator_runtime_dir}/test/{test_name}", - args.debug_simulator, - args.enable_realism, - ) as simulator, FullSystem( - "software/unix_full_system", - f"{args.blue_full_system_runtime_dir}/test/{test_name}", - args.debug_blue_full_system, - False, - should_restart_on_crash=False, - running_in_realtime=args.enable_thunderscope, - ) as blue_fs, FullSystem( - "software/unix_full_system", - f"{args.yellow_full_system_runtime_dir}/test/{test_name}", - args.debug_yellow_full_system, - True, - should_restart_on_crash=False, - running_in_realtime=args.enable_thunderscope, - ) as yellow_fs: - with Gamecontroller( - suppress_logs=(not args.show_gamecontroller_logs) - ) as gamecontroller: - blue_fs.setup_proto_unix_io(blue_full_system_proto_unix_io) - yellow_fs.setup_proto_unix_io(yellow_full_system_proto_unix_io) - simulator.setup_proto_unix_io( - simulator_proto_unix_io, - blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io, - ProtoUnixIO(), - ) - gamecontroller.setup_proto_unix_io( - blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, - simulator_proto_unix_io=simulator_proto_unix_io, - ) - - # If we want to run thunderscope, inject the proto unix ios - # and start the test - if args.enable_thunderscope: - tscope = Thunderscope( - configure_simulated_test_view( - blue_full_system_proto_unix_io=blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io=yellow_full_system_proto_unix_io, - simulator_proto_unix_io=simulator_proto_unix_io, - ), - layout_path=args.layout, - ) - - time.sleep(LAUNCH_DELAY_S) - - runner = None - - # Initialise the right runner based on which testing mode is selected - if aggregate: - runner = AggregateTestRunner( - current_test, - tscope, - simulator_proto_unix_io, - blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io, - gamecontroller, - ) - else: - runner = InvariantTestRunner( - current_test, - tscope, - simulator_proto_unix_io, - blue_full_system_proto_unix_io, - yellow_full_system_proto_unix_io, - gamecontroller, - ) - - yield runner diff --git a/src/software/simulated_tests/tbots_test_runner.py b/src/software/gameplay_tests/tbots_test_runner.py similarity index 96% rename from src/software/simulated_tests/tbots_test_runner.py rename to src/software/gameplay_tests/tbots_test_runner.py index 03e7d4ae85..69ff1c7f9e 100644 --- a/src/software/simulated_tests/tbots_test_runner.py +++ b/src/software/gameplay_tests/tbots_test_runner.py @@ -1,11 +1,8 @@ from proto.import_all_protos import * -from software.logger.logger import create_logger from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer from abc import abstractmethod from typing import Any -logger = create_logger(__name__) - class TbotsTestRunner: """An abstract class that represents a test runner""" @@ -138,16 +135,17 @@ def _create_assigned_tactic_params(self, tactics: dict[int, Any]): return params @abstractmethod - def set_world_state(self, worldstate: WorldState): - """Sets the worldstate for the given team + def set_world_state(self, world_state: WorldState): + """Sets the initial world state of the test. - :param worldstate: the worldstate proto to use + :param world_state: The WorldState proto to use """ raise NotImplementedError("abstract class method called set_world_state") @abstractmethod def run_test( self, + setup=lambda: None, always_validation_sequence_set=[[]], eventually_validation_sequence_set=[[]], test_timeout_s=3, diff --git a/src/software/gameplay_tests/util.py b/src/software/gameplay_tests/util.py new file mode 100644 index 0000000000..4b8b0a4f2d --- /dev/null +++ b/src/software/gameplay_tests/util.py @@ -0,0 +1,159 @@ +import argparse +import os +import sys + +import pytest + + +def load_command_line_arguments(allow_unrecognized: bool = False): + """Load in command-line arguments using argparse + + NOTE: Pytest has its own built in argument parser (conftest.py, pytest_addoption) + but it doesn't seem to play nicely with bazel. We just use argparse instead. + + :param allow_unrecognized: if true, does not raise an error for unrecognized arguments + """ + parser = argparse.ArgumentParser( + description="Run simulated or field gameplay tests" + ) + + general_group = parser.add_argument_group("General test arguments") + general_group.add_argument( + "--run_field_test", + action="store_true", + default=False, + help="Runs test as a field test instead of a simulated test", + ) + general_group.add_argument( + "--enable_thunderscope", action="store_true", help="enable thunderscope" + ) + general_group.add_argument( + "--test_filter", + action="store", + default="", + help="The test filter, if not specified all tests will run. " + + "See https://docs.pytest.org/en/latest/how-to/usage.html#specifying-tests-selecting-tests", + ) + general_group.add_argument( + "--blue_full_system_runtime_dir", + type=str, + help="blue full_system runtime directory", + default="/tmp/tbots/blue", + ) + general_group.add_argument( + "--yellow_full_system_runtime_dir", + type=str, + help="yellow full_system runtime directory", + default="/tmp/tbots/yellow", + ) + general_group.add_argument( + "--layout", + action="store", + help="Which layout to run, if not specified the last layout will run", + ) + general_group.add_argument( + "--debug_blue_full_system", + action="store_true", + default=False, + help="Debug blue full_system", + ) + general_group.add_argument( + "--debug_yellow_full_system", + action="store_true", + default=False, + help="Debug yellow full_system", + ) + general_group.add_argument( + "--show_gamecontroller_logs", + action="store_true", + default=False, + help="Show gamecontroller logs", + ) + + simulated_group = parser.add_argument_group("Simulated test arguments") + simulated_group.add_argument( + "--simulator_runtime_dir", + type=str, + help="simulator runtime directory", + default="/tmp/tbots", + ) + simulated_group.add_argument( + "--debug_simulator", + action="store_true", + default=False, + help="Debug the simulator", + ) + simulated_group.add_argument( + "--enable_realism", + action="store_true", + default=False, + help="Use realism in the simulator", + ) + + field_group = parser.add_argument_group("Field test arguments") + field_group.add_argument( + "--interface", + action="store", + type=str, + default=None, + help="Which interface to communicate over", + ) + field_group.add_argument( + "--channel", + action="store", + type=int, + default=0, + help="Which channel to communicate over", + ) + field_group.add_argument( + "--estop_baudrate", + action="store", + type=int, + default=115200, + help="Estop Baudrate", + ) + field_group.add_argument( + "--run_yellow", + action="store_true", + default=False, + help="Run the test with friendly robots in yellow mode", + ) + + estop_group = field_group.add_mutually_exclusive_group() + estop_group.add_argument( + "--keyboard_estop", + action="store_true", + default=False, + help="Allows the use of the spacebar as an estop instead of a physical one", + ) + estop_group.add_argument( + "--disable_communication", + action="store_true", + default=False, + help="Disables checking for estop plugged in (ONLY USE FOR LOCAL TESTING)", + ) + + return parser.parse_known_args()[0] if allow_unrecognized else parser.parse_args() + + +def get_current_pytest(): + current_test = os.environ.get("PYTEST_CURRENT_TEST").split(":")[-1].split(" ")[0] + current_test = current_test.replace("]", "") + current_test = current_test.replace("[", "-") + return current_test + + +def pytest_main(file): + """Runs the pytest file + + :param file: The test file to run + """ + args = load_command_line_arguments(allow_unrecognized=True) + + # Run the test, -s disables all capturing at -vv increases verbosity + # -W ignore::DeprecationWarning ignores deprecation warnings that spam the output + sys.exit( + pytest.main( + ["-svv", "-W ignore::DeprecationWarning", "-k", args.test_filter, file] + ) + ) diff --git a/src/software/simulated_tests/validation/BUILD b/src/software/gameplay_tests/validation/BUILD similarity index 100% rename from src/software/simulated_tests/validation/BUILD rename to src/software/gameplay_tests/validation/BUILD diff --git a/src/software/simulated_tests/validation/__init__.py b/src/software/gameplay_tests/validation/__init__.py similarity index 100% rename from src/software/simulated_tests/validation/__init__.py rename to src/software/gameplay_tests/validation/__init__.py diff --git a/src/software/simulated_tests/validation/avoid_collisions.py b/src/software/gameplay_tests/validation/avoid_collisions.py similarity index 99% rename from src/software/simulated_tests/validation/avoid_collisions.py rename to src/software/gameplay_tests/validation/avoid_collisions.py index 41953cd994..6ac44f7db9 100644 --- a/src/software/simulated_tests/validation/avoid_collisions.py +++ b/src/software/gameplay_tests/validation/avoid_collisions.py @@ -1,7 +1,7 @@ from software.py_constants import * import software.python_bindings as tbots from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_types, create_validation_geometry, diff --git a/src/software/simulated_tests/validation/ball_enters_region.py b/src/software/gameplay_tests/validation/ball_enters_region.py similarity index 96% rename from src/software/simulated_tests/validation/ball_enters_region.py rename to src/software/gameplay_tests/validation/ball_enters_region.py index ff6e840f59..359a44bfff 100644 --- a/src/software/simulated_tests/validation/ball_enters_region.py +++ b/src/software/gameplay_tests/validation/ball_enters_region.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/ball_is_off_ground.py b/src/software/gameplay_tests/validation/ball_is_off_ground.py similarity index 98% rename from src/software/simulated_tests/validation/ball_is_off_ground.py rename to src/software/gameplay_tests/validation/ball_is_off_ground.py index 880150c838..26b8c6a760 100644 --- a/src/software/simulated_tests/validation/ball_is_off_ground.py +++ b/src/software/gameplay_tests/validation/ball_is_off_ground.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/ball_kicked_in_direction.py b/src/software/gameplay_tests/validation/ball_kicked_in_direction.py similarity index 97% rename from src/software/simulated_tests/validation/ball_kicked_in_direction.py rename to src/software/gameplay_tests/validation/ball_kicked_in_direction.py index 3bd99978ce..40d9669b1e 100644 --- a/src/software/simulated_tests/validation/ball_kicked_in_direction.py +++ b/src/software/gameplay_tests/validation/ball_kicked_in_direction.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/ball_moves_in_direction.py b/src/software/gameplay_tests/validation/ball_moves_in_direction.py similarity index 98% rename from src/software/simulated_tests/validation/ball_moves_in_direction.py rename to src/software/gameplay_tests/validation/ball_moves_in_direction.py index 533d818fc7..fb2c99fc0f 100644 --- a/src/software/simulated_tests/validation/ball_moves_in_direction.py +++ b/src/software/gameplay_tests/validation/ball_moves_in_direction.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/ball_speed_threshold.py b/src/software/gameplay_tests/validation/ball_speed_threshold.py similarity index 94% rename from src/software/simulated_tests/validation/ball_speed_threshold.py rename to src/software/gameplay_tests/validation/ball_speed_threshold.py index f1f8dcec46..240c6db4e4 100644 --- a/src/software/simulated_tests/validation/ball_speed_threshold.py +++ b/src/software/gameplay_tests/validation/ball_speed_threshold.py @@ -1,9 +1,9 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * from software.py_constants import * -from software.simulated_tests.validation.speed_threshold_helpers import * +from software.gameplay_tests.validation.speed_threshold_helpers import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/ball_stops_in_region.py b/src/software/gameplay_tests/validation/ball_stops_in_region.py similarity index 96% rename from src/software/simulated_tests/validation/ball_stops_in_region.py rename to src/software/gameplay_tests/validation/ball_stops_in_region.py index 38b0312481..0506865964 100644 --- a/src/software/simulated_tests/validation/ball_stops_in_region.py +++ b/src/software/gameplay_tests/validation/ball_stops_in_region.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/delay_validation.py b/src/software/gameplay_tests/validation/delay_validation.py similarity index 96% rename from src/software/simulated_tests/validation/delay_validation.py rename to src/software/gameplay_tests/validation/delay_validation.py index b51725f7d4..29f455ba6b 100644 --- a/src/software/simulated_tests/validation/delay_validation.py +++ b/src/software/gameplay_tests/validation/delay_validation.py @@ -2,7 +2,7 @@ from proto.validation_pb2 import ValidationStatus, ValidationType, ValidationGeometry from software.py_constants import DEFAULT_SIMULATOR_TICK_RATE_SECONDS_PER_TICK -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, ) diff --git a/src/software/simulated_tests/validation/duration_validation.py b/src/software/gameplay_tests/validation/duration_validation.py similarity index 96% rename from src/software/simulated_tests/validation/duration_validation.py rename to src/software/gameplay_tests/validation/duration_validation.py index 1020e024d2..c400493a61 100644 --- a/src/software/simulated_tests/validation/duration_validation.py +++ b/src/software/gameplay_tests/validation/duration_validation.py @@ -2,7 +2,7 @@ from proto.validation_pb2 import ValidationStatus, ValidationType, ValidationGeometry from software.py_constants import DEFAULT_SIMULATOR_TICK_RATE_SECONDS_PER_TICK -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, ) diff --git a/src/software/simulated_tests/validation/excessive_dribbling.py b/src/software/gameplay_tests/validation/excessive_dribbling.py similarity index 98% rename from src/software/simulated_tests/validation/excessive_dribbling.py rename to src/software/gameplay_tests/validation/excessive_dribbling.py index 98a386b055..4904ba65a3 100644 --- a/src/software/simulated_tests/validation/excessive_dribbling.py +++ b/src/software/gameplay_tests/validation/excessive_dribbling.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import ValidationStatus, ValidationGeometry -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/friendly_has_ball_possession.py b/src/software/gameplay_tests/validation/friendly_has_ball_possession.py similarity index 97% rename from src/software/simulated_tests/validation/friendly_has_ball_possession.py rename to src/software/gameplay_tests/validation/friendly_has_ball_possession.py index bf1013f7ed..2bcb90baa3 100644 --- a/src/software/simulated_tests/validation/friendly_has_ball_possession.py +++ b/src/software/gameplay_tests/validation/friendly_has_ball_possession.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/friendly_receives_ball_slow.py b/src/software/gameplay_tests/validation/friendly_receives_ball_slow.py similarity index 93% rename from src/software/simulated_tests/validation/friendly_receives_ball_slow.py rename to src/software/gameplay_tests/validation/friendly_receives_ball_slow.py index 219271e001..f94ed02fe8 100644 --- a/src/software/simulated_tests/validation/friendly_receives_ball_slow.py +++ b/src/software/gameplay_tests/validation/friendly_receives_ball_slow.py @@ -1,10 +1,10 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( create_validation_types, ) -from software.simulated_tests.validation.friendly_has_ball_possession import ( +from software.gameplay_tests.validation.friendly_has_ball_possession import ( FriendlyHasBallPossession, ) from typing import override diff --git a/src/software/simulated_tests/validation/friendly_team_scored.py b/src/software/gameplay_tests/validation/friendly_team_scored.py similarity index 96% rename from src/software/simulated_tests/validation/friendly_team_scored.py rename to src/software/gameplay_tests/validation/friendly_team_scored.py index 458502f152..146e77923b 100644 --- a/src/software/simulated_tests/validation/friendly_team_scored.py +++ b/src/software/gameplay_tests/validation/friendly_team_scored.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/or_validation.py b/src/software/gameplay_tests/validation/or_validation.py similarity index 96% rename from src/software/simulated_tests/validation/or_validation.py rename to src/software/gameplay_tests/validation/or_validation.py index b14affe8c3..88ae1180c7 100644 --- a/src/software/simulated_tests/validation/or_validation.py +++ b/src/software/gameplay_tests/validation/or_validation.py @@ -1,5 +1,5 @@ from proto.validation_pb2 import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, ) from typing import override diff --git a/src/software/simulated_tests/validation/robot_at_angular_velocity.py b/src/software/gameplay_tests/validation/robot_at_angular_velocity.py similarity index 97% rename from src/software/simulated_tests/validation/robot_at_angular_velocity.py rename to src/software/gameplay_tests/validation/robot_at_angular_velocity.py index f9fec65db8..bb047de91b 100644 --- a/src/software/simulated_tests/validation/robot_at_angular_velocity.py +++ b/src/software/gameplay_tests/validation/robot_at_angular_velocity.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/robot_at_orientation.py b/src/software/gameplay_tests/validation/robot_at_orientation.py similarity index 97% rename from src/software/simulated_tests/validation/robot_at_orientation.py rename to src/software/gameplay_tests/validation/robot_at_orientation.py index df3c113257..cdb85b488f 100644 --- a/src/software/simulated_tests/validation/robot_at_orientation.py +++ b/src/software/gameplay_tests/validation/robot_at_orientation.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/robot_at_position.py b/src/software/gameplay_tests/validation/robot_at_position.py similarity index 97% rename from src/software/simulated_tests/validation/robot_at_position.py rename to src/software/gameplay_tests/validation/robot_at_position.py index 0637585254..8943551bd4 100644 --- a/src/software/simulated_tests/validation/robot_at_position.py +++ b/src/software/gameplay_tests/validation/robot_at_position.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, ValidationStatus, create_validation_geometry, diff --git a/src/software/simulated_tests/validation/robot_enters_placement_region.py b/src/software/gameplay_tests/validation/robot_enters_placement_region.py similarity index 97% rename from src/software/simulated_tests/validation/robot_enters_placement_region.py rename to src/software/gameplay_tests/validation/robot_enters_placement_region.py index db6275e1f2..37121e6b0c 100644 --- a/src/software/simulated_tests/validation/robot_enters_placement_region.py +++ b/src/software/gameplay_tests/validation/robot_enters_placement_region.py @@ -2,7 +2,7 @@ from software.py_constants import ENEMY_BALL_PLACEMENT_DISTANCE_METERS from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/robot_enters_region.py b/src/software/gameplay_tests/validation/robot_enters_region.py similarity index 97% rename from src/software/simulated_tests/validation/robot_enters_region.py rename to src/software/gameplay_tests/validation/robot_enters_region.py index d5d6584487..ebdbbf8887 100644 --- a/src/software/simulated_tests/validation/robot_enters_region.py +++ b/src/software/gameplay_tests/validation/robot_enters_region.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/robot_enters_region_and_stops.py b/src/software/gameplay_tests/validation/robot_enters_region_and_stops.py similarity index 96% rename from src/software/simulated_tests/validation/robot_enters_region_and_stops.py rename to src/software/gameplay_tests/validation/robot_enters_region_and_stops.py index 5cc4a5b052..1676347665 100644 --- a/src/software/simulated_tests/validation/robot_enters_region_and_stops.py +++ b/src/software/gameplay_tests/validation/robot_enters_region_and_stops.py @@ -2,11 +2,11 @@ from software.py_constants import * from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( create_validation_types, create_validation_geometry, ) -from software.simulated_tests.validation.robot_enters_region import ( +from software.gameplay_tests.validation.robot_enters_region import ( RobotEntersRegion, ) from typing import override diff --git a/src/software/simulated_tests/validation/robot_received_ball.py b/src/software/gameplay_tests/validation/robot_received_ball.py similarity index 97% rename from src/software/simulated_tests/validation/robot_received_ball.py rename to src/software/gameplay_tests/validation/robot_received_ball.py index 674f75c800..660a492896 100644 --- a/src/software/simulated_tests/validation/robot_received_ball.py +++ b/src/software/gameplay_tests/validation/robot_received_ball.py @@ -1,7 +1,7 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/robot_speed_threshold.py b/src/software/gameplay_tests/validation/robot_speed_threshold.py similarity index 95% rename from src/software/simulated_tests/validation/robot_speed_threshold.py rename to src/software/gameplay_tests/validation/robot_speed_threshold.py index 19e20db786..4b5126175e 100644 --- a/src/software/simulated_tests/validation/robot_speed_threshold.py +++ b/src/software/gameplay_tests/validation/robot_speed_threshold.py @@ -1,11 +1,11 @@ import software.python_bindings as tbots_cpp from proto.import_all_protos import * from software.py_constants import * -from software.simulated_tests.validation.speed_threshold_helpers import * +from software.gameplay_tests.validation.speed_threshold_helpers import * from typing import override -from software.simulated_tests.validation.validation import ( +from software.gameplay_tests.validation.validation import ( Validation, create_validation_geometry, create_validation_types, diff --git a/src/software/simulated_tests/validation/speed_threshold_helpers.py b/src/software/gameplay_tests/validation/speed_threshold_helpers.py similarity index 100% rename from src/software/simulated_tests/validation/speed_threshold_helpers.py rename to src/software/gameplay_tests/validation/speed_threshold_helpers.py diff --git a/src/software/simulated_tests/validation/validation.py b/src/software/gameplay_tests/validation/validation.py similarity index 100% rename from src/software/simulated_tests/validation/validation.py rename to src/software/gameplay_tests/validation/validation.py diff --git a/src/software/logger/logger.h b/src/software/logger/logger.h index df6691750e..44bfd16392 100644 --- a/src/software/logger/logger.h +++ b/src/software/logger/logger.h @@ -82,7 +82,7 @@ class LoggerSingleton // Standalone Simulator: // bazel-out/k8-fastbuild/bin/software/simulation/standalone_simulator_main.runfiles/__main__/ // Simulated - // tests:bazel-out/k8-fastbuild/bin/software/simulated_tests/TEST_NAME.runfiles/__main__/ + // tests:bazel-out/k8-fastbuild/bin/software/gameplay_tests/TEST_NAME.runfiles/__main__/ // where TEST_NAME is the name of the simulated test // Log locations can also be defined by setting the --logging_dir command-line diff --git a/src/software/sensor_fusion/filter/BUILD b/src/software/sensor_fusion/filter/BUILD index 6116f49da2..9f6faf6fce 100644 --- a/src/software/sensor_fusion/filter/BUILD +++ b/src/software/sensor_fusion/filter/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//software/sensor_fusion:__subpackages__"]) @@ -94,7 +94,7 @@ py_test( tags = ["exclusive"], deps = [ "//software:conftest", - "//software/simulated_tests/validation:validations", + "//software/gameplay_tests/validation:validations", requirement("pytest"), ], ) diff --git a/src/software/sensor_fusion/filter/ball_occlusion_test.py b/src/software/sensor_fusion/filter/ball_occlusion_test.py index 38b07e569f..1da5971d27 100644 --- a/src/software/sensor_fusion/filter/ball_occlusion_test.py +++ b/src/software/sensor_fusion/filter/ball_occlusion_test.py @@ -7,7 +7,7 @@ from proto.message_translation.tbots_protobuf import create_world_state from proto.import_all_protos import Command from proto.ssl_gc_common_pb2 import Team -from software.simulated_tests.simulated_test_fixture import ( +from software.gameplay_tests.util import ( pytest_main, ) @@ -171,10 +171,10 @@ def test_ball_occlusion( ball_velocity, blue_robot_positions, yellow_robot_positions, - simulated_test_runner, + gameplay_test_runner, ): - def setup(*args): - simulated_test_runner.set_world_state( + def setup(): + gameplay_test_runner.set_world_state( create_world_state( blue_robot_locations=blue_robot_positions, yellow_robot_locations=yellow_robot_positions, @@ -183,18 +183,18 @@ def setup(*args): ), ) - simulated_test_runner.send_gamecontroller_command( + gameplay_test_runner.send_gamecontroller_command( gc_command=Command.Type.HALT, team=Team.UNKNOWN ) - simulated_test_runner.set_plays( + gameplay_test_runner.set_plays( blue_play=PlayName.HaltPlay, yellow_play=PlayName.HaltPlay ) # This test validates that the ball tracking/filter handles occlusion correctly. # The validation simply waits for the simulation to run long enough (10s). # If the system crashes or has tracking issues, the test will fail. - simulated_test_runner.run_test( + gameplay_test_runner.run_test( setup=setup, test_timeout_s=10, ) diff --git a/src/software/simulated_tests/simulated_test_ball_model.py b/src/software/simulated_tests/simulated_test_ball_model.py deleted file mode 100644 index f5653d2612..0000000000 --- a/src/software/simulated_tests/simulated_test_ball_model.py +++ /dev/null @@ -1,193 +0,0 @@ -import pytest - -import software.python_bindings as tbots_cpp -from software.simulated_tests.validation.robot_enters_region import * -from software.simulated_tests.validation.ball_enters_region import * -from software.simulated_tests.validation.ball_moves_in_direction import * -from software.simulated_tests.validation.friendly_has_ball_possession import * -from software.simulated_tests.validation.ball_speed_threshold import * -from software.simulated_tests.validation.robot_speed_threshold import * -from software.simulated_tests.validation.ball_stops_in_region import * -from software.simulated_tests.validation.excessive_dribbling import * -from proto.message_translation.tbots_protobuf import create_world_state -from software.simulated_tests.simulated_test_fixture import ( - pytest_main, -) - -# the friction model currently used in the er-force simulator - -SLIDING_ACCELERATION = -3.432327 # equal to coeff_of_friction * g -ROLLING_ACCELERATION = -0.5 -TRANSITION_FACTOR = 5.0 / 7.0 -STOPPING_SPEED = 0.01 - - -@pytest.mark.parametrize( - "ball_initial_position,ball_initial_velocity", - [ - ( - tbots_cpp.Point(-3.5, 0), - tbots_cpp.Vector(2, 0), - ), - ( - tbots_cpp.Point(-3.5, 2), - tbots_cpp.Vector(3, -2), - ), - ( - tbots_cpp.Point(-3.5, -2), - tbots_cpp.Vector(3, 2), - ), - ( - tbots_cpp.Point(4.5, 3), - tbots_cpp.Vector(-3.5, -2), - ), - ], -) -def test_simulator_move_ball( - ball_initial_position, - ball_initial_velocity, - simulated_test_runner, -): - # Setup Ball - simulated_test_runner.simulator_proto_unix_io.send_proto( - WorldState, - create_world_state( - [], - blue_robot_locations=[], - ball_location=ball_initial_position, - ball_velocity=ball_initial_velocity, - ), - ) - - # Setup Tactic - params = AssignedTacticPlayControlParams() - - simulated_test_runner.blue_full_system_proto_unix_io.send_proto( - AssignedTacticPlayControlParams, params - ) - - # Setup no tactics on the enemy side - params = AssignedTacticPlayControlParams() - simulated_test_runner.yellow_full_system_proto_unix_io.send_proto( - AssignedTacticPlayControlParams, params - ) - - # expected ball position - initial_v = ball_initial_velocity.length() - - # velocity at which ball starts to roll - rolling_v = TRANSITION_FACTOR * initial_v - time_until_roll = abs((rolling_v - initial_v) / SLIDING_ACCELERATION) - time_until_stop = abs((rolling_v - STOPPING_SPEED) / ROLLING_ACCELERATION) - - d_slide = (initial_v + rolling_v) / 2 * time_until_roll - d_roll = (rolling_v / 2) * time_until_stop - total_distance = d_slide + d_roll - - ball_expected_position = ( - total_distance * ball_initial_velocity.normalize() + ball_initial_position - ) - - # Always Validation - always_validation_sequence_set = [ - [ - NeverExcessivelyDribbles(), - ] - ] - - # Eventually Validation - eventually_validation_sequence_set = [ - [ - BallEventuallyStopsInRegion( - [tbots_cpp.Circle(ball_expected_position, 0.1)] - ), - ] - ] - - simulated_test_runner.run_test( - test_timeout_s=8, - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ) - - -def test_ball_robot_collision(simulated_test_runner): - ball_initial_position = tbots_cpp.Field.createSSLDivisionBField().centerPoint() - ball_initial_velocity = tbots_cpp.Vector(2.5, 0) - robot_position = tbots_cpp.Point(2.5, 0) - - # Setup Robot - simulated_test_runner.simulator_proto_unix_io.send_proto( - WorldState, - create_world_state( - [], - blue_robot_locations=[robot_position], - ball_location=ball_initial_position, - ball_velocity=ball_initial_velocity, - ), - ) - - # Setup Ball - simulated_test_runner.simulator_proto_unix_io.send_proto( - WorldState, - create_world_state( - [], - blue_robot_locations=[], - ball_location=ball_initial_position, - ball_velocity=ball_initial_velocity, - ), - ) - - # Setup Tactic - params = AssignedTacticPlayControlParams() - - simulated_test_runner.blue_full_system_proto_unix_io.send_proto( - AssignedTacticPlayControlParams, params - ) - - # Setup no tactics on the enemy side - params = AssignedTacticPlayControlParams() - simulated_test_runner.yellow_full_system_proto_unix_io.send_proto( - AssignedTacticPlayControlParams, params - ) - - # expected ball position - initial_v = ball_initial_velocity.length() - - # velocity at which ball starts to roll - rolling_v = TRANSITION_FACTOR * initial_v - time_until_roll = abs((rolling_v - initial_v) / SLIDING_ACCELERATION) - time_until_stop = abs((rolling_v - STOPPING_SPEED) / ROLLING_ACCELERATION) - - d_slide = (initial_v + rolling_v) / 2 * time_until_roll - d_roll = (rolling_v / 2) * time_until_stop - total_distance = d_slide + d_roll - - # expected position if there was no robot collision - ball_expected_position = ( - total_distance * ball_initial_velocity.normalize() + ball_initial_position - ) - - distance_from_robot = (ball_expected_position - robot_position).length() - - # Always Validation - always_validation_sequence_set = [] - - # Eventually Validation - eventually_validation_sequence_set = [ - [ - BallEventuallyStopsInRegion( - [tbots_cpp.Circle(robot_position, distance_from_robot)] - ), - ] - ] - - simulated_test_runner.run_test( - inv_eventually_validation_sequence_set=eventually_validation_sequence_set, - inv_always_validation_sequence_set=always_validation_sequence_set, - ) - - -if __name__ == "__main__": - # Run the test, -s disables all capturing at -vv increases verbosity - pytest_main(__file__) diff --git a/src/software/thunderscope/replay/test/BUILD b/src/software/thunderscope/replay/test/BUILD index 9b994ec17b..f65f871c21 100644 --- a/src/software/thunderscope/replay/test/BUILD +++ b/src/software/thunderscope/replay/test/BUILD @@ -1,4 +1,4 @@ -load("@simulated_tests_deps//:requirements.bzl", "requirement") +load("@gameplay_tests_deps//:requirements.bzl", "requirement") package(default_visibility = ["//visibility:public"]) diff --git a/src/software/thunderscope/replay/test/replay_corruption_test.py b/src/software/thunderscope/replay/test/replay_corruption_test.py index da16eb8b2d..7d43c1ca3e 100644 --- a/src/software/thunderscope/replay/test/replay_corruption_test.py +++ b/src/software/thunderscope/replay/test/replay_corruption_test.py @@ -26,7 +26,7 @@ from software.thunderscope.constants import ProtoPlayerFlags from software.thunderscope.replay.proto_player import ProtoPlayer from software.thunderscope.proto_unix_io import ProtoUnixIO -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.util import pytest_main random.seed(0) diff --git a/src/software/thunderscope/replay/test/replay_indexing_test.py b/src/software/thunderscope/replay/test/replay_indexing_test.py index 4d58d3a05d..4d721e5d26 100644 --- a/src/software/thunderscope/replay/test/replay_indexing_test.py +++ b/src/software/thunderscope/replay/test/replay_indexing_test.py @@ -13,7 +13,7 @@ from software.thunderscope.replay.proto_player import ProtoPlayer from software.thunderscope.proto_unix_io import ProtoUnixIO -from software.simulated_tests.simulated_test_fixture import pytest_main +from software.gameplay_tests.util import pytest_main from software.thunderscope.replay.test.replay_corruption_test import ( create_valid_log_entry, create_random_proto,