Skip to content

Commit cef0905

Browse files
committed
Revert changes that aren't related to moving pytest validations
1 parent 35c2011 commit cef0905

7 files changed

Lines changed: 94 additions & 118 deletions

File tree

src/software/ai/hl/stp/tactic/crease_defender/crease_defender_tactic_test.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
import pytest
22
import software.python_bindings as tbots_cpp
33

4-
from proto.import_all_protos import (
5-
BallStealMode,
6-
CreaseDefenderAlignment,
7-
CreaseDefenderTactic,
8-
MaxAllowedSpeedMode,
9-
)
10-
from proto.message_translation.tbots_protobuf import create_world_state
11-
from software.simulated_tests.validation.ball_is_off_ground import (
12-
BallIsAlwaysOnGround,
13-
BallIsEventuallyOffGround,
14-
)
15-
from software.simulated_tests.validation.excessive_dribbling import (
16-
NeverExcessivelyDribbles,
17-
)
18-
from software.simulated_tests.validation.robot_enters_region import (
19-
RobotEventuallyEntersRegion,
20-
RobotNeverEntersRegion,
21-
)
224
from proto.import_all_protos import *
23-
from software.simulated_tests.simulated_test_fixture import (
24-
pytest_main,
25-
)
5+
from proto.message_translation.tbots_protobuf import create_world_state
6+
from software.simulated_tests.simulated_test_fixture import pytest_main
7+
from software.simulated_tests.validation.ball_is_off_ground import *
8+
from software.simulated_tests.validation.excessive_dribbling import *
9+
from software.simulated_tests.validation.robot_enters_region import *
2610

2711

2812
@pytest.mark.parametrize(

src/software/ai/hl/stp/tactic/goalie/goalie_tactic_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
import software.python_bindings as tbots_cpp
4-
from proto.import_all_protos import GoalieTactic, MaxAllowedSpeedMode
4+
from proto.import_all_protos import *
55
from software.simulated_tests.validation.robot_enters_region import *
66
from software.simulated_tests.validation.ball_enters_region import *
77
from software.simulated_tests.validation.ball_moves_in_direction import *

src/software/ai/hl/stp/tactic/pass_defender/pass_defender_tactic_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
import software.python_bindings as tbots_cpp
4-
from proto.import_all_protos import PassDefenderTactic, BallStealMode
4+
from proto.import_all_protos import *
55
from software.simulated_tests.validation.robot_enters_region import *
66
from software.simulated_tests.validation.ball_enters_region import *
77
from software.simulated_tests.validation.ball_moves_in_direction import *

src/software/python_bindings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ PYBIND11_MODULE(python_bindings, m)
152152

153153
py::class_<Vector>(m, "Vector")
154154
.def(py::init<float, float>())
155-
.def_static("createFromAngle", &Vector::createFromAngle)
156155
.def("x", &Vector::x)
157156
.def("y", &Vector::y)
158157
.def("setX", &Vector::setX)

src/software/simulated_tests/simulated_test_fixture.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
from software.thunderscope.binary_context_managers.game_controller import Gamecontroller
1919
from software.thunderscope.thunderscope_config import configure_simulated_test_view
2020
from software.thunderscope.thread_safe_buffer import ThreadSafeBuffer
21-
from software.thunderscope.constants import SimulatedTestConstants
2221

2322
from software.logger.logger import create_logger
2423
from typing import override
2524

2625
logger = create_logger(__name__)
2726

27+
LAUNCH_DELAY_S = 0.1
28+
WORLD_BUFFER_TIMEOUT = 0.5
29+
PROCESS_BUFFER_DELAY_S = 0.01
30+
PAUSE_AFTER_FAIL_DELAY_S = 3
31+
2832

2933
class SimulatedTestRunner(TbotsTestRunner):
3034
"""Run a simulated test"""
@@ -71,11 +75,11 @@ def excepthook(self, args):
7175
7276
:param args: The args passed in from the hook
7377
"""
74-
self.__stopper(delay=SimulatedTestConstants.PAUSE_AFTER_FAIL_DELAY_S)
78+
self.__stopper(delay=PAUSE_AFTER_FAIL_DELAY_S)
7579
self.last_exception = args.exc_value
7680
raise self.last_exception
7781

78-
def __stopper(self, delay=SimulatedTestConstants.PROCESS_BUFFER_DELAY_S):
82+
def __stopper(self, delay=PROCESS_BUFFER_DELAY_S):
7983
"""Stop running the test
8084
8185
:param delay: How long to wait before closing everything, defaults
@@ -102,7 +106,7 @@ def sync_setup(self, setup, param):
102106

103107
try:
104108
world_state_received_buffer.get(
105-
block=True, timeout=SimulatedTestConstants.WORLD_BUFFER_TIMEOUT
109+
block=True, timeout=WORLD_BUFFER_TIMEOUT
106110
)
107111
except queue.Empty:
108112
# Did not receive a response within timeout period
@@ -162,19 +166,15 @@ def runner(
162166
while True:
163167
try:
164168
world = self.world_buffer.get(
165-
block=True,
166-
timeout=SimulatedTestConstants.WORLD_BUFFER_TIMEOUT,
167-
return_cached=False,
169+
block=True, timeout=WORLD_BUFFER_TIMEOUT, return_cached=False
168170
)
169171

170172
# We block until the timeout for the new primitives from AI. if not found still,
171173
# the SSL Wrapper packet is resent in a loop until we actually get a primitive set from AI
172174
# Otherwise, if the AI misses the first SSL Wrapper packet and doesn't start
173175
# the simulated test will continue to tick forward, causes syncing issues with the AI
174176
self.primitive_set_buffer.get(
175-
block=True,
176-
timeout=SimulatedTestConstants.WORLD_BUFFER_TIMEOUT,
177-
return_cached=False,
177+
block=True, timeout=WORLD_BUFFER_TIMEOUT, return_cached=False
178178
)
179179

180180
break
@@ -257,6 +257,7 @@ def run_test(
257257
always_validation_sequence_set,
258258
eventually_validation_sequence_set,
259259
test_timeout_s=3,
260+
tick_duration_s=0.0166, # Default to 60hz
260261
index=0,
261262
ci_cmd_with_delay=[],
262263
run_till_end=True,
@@ -267,6 +268,7 @@ def run_test(
267268
:param always_validation_sequence_set: validation that should always be true
268269
:param eventually_validation_sequence_set: validation that should eventually be true
269270
:param test_timeout_s: how long the test should run before timing out
271+
:param tick_duration_s: length of a tick
270272
:param index: index of the current test. default is 0 (invariant test)
271273
values can be passed in during aggregate testing for different timeout durations
272274
:param ci_cmd_with_delay: A list consisting of tuples with a duration and CI command, e.g.
@@ -293,7 +295,7 @@ def run_test(
293295
always_validation_sequence_set,
294296
eventually_validation_sequence_set,
295297
test_timeout_duration,
296-
SimulatedTestConstants.TICK_DURATION_S,
298+
tick_duration_s,
297299
ci_cmd_with_delay,
298300
run_till_end,
299301
],
@@ -311,7 +313,7 @@ def run_test(
311313
always_validation_sequence_set,
312314
eventually_validation_sequence_set,
313315
test_timeout_duration,
314-
SimulatedTestConstants.TICK_DURATION_S,
316+
tick_duration_s,
315317
ci_cmd_with_delay=ci_cmd_with_delay,
316318
run_till_end=run_till_end,
317319
)
@@ -530,29 +532,25 @@ def simulated_test_runner():
530532
test_name = current_test.split("-")[0]
531533

532534
# Launch all binaries
533-
with (
534-
Simulator(
535-
f"{args.simulator_runtime_dir}/test/{test_name}",
536-
args.debug_simulator,
537-
args.enable_realism,
538-
) as simulator,
539-
FullSystem(
540-
"software/unix_full_system",
541-
f"{args.blue_full_system_runtime_dir}/test/{test_name}",
542-
args.debug_blue_full_system,
543-
False,
544-
should_restart_on_crash=False,
545-
running_in_realtime=args.enable_thunderscope,
546-
) as blue_fs,
547-
FullSystem(
548-
"software/unix_full_system",
549-
f"{args.yellow_full_system_runtime_dir}/test/{test_name}",
550-
args.debug_yellow_full_system,
551-
True,
552-
should_restart_on_crash=False,
553-
running_in_realtime=args.enable_thunderscope,
554-
) as yellow_fs,
555-
):
535+
with Simulator(
536+
f"{args.simulator_runtime_dir}/test/{test_name}",
537+
args.debug_simulator,
538+
args.enable_realism,
539+
) as simulator, FullSystem(
540+
"software/unix_full_system",
541+
f"{args.blue_full_system_runtime_dir}/test/{test_name}",
542+
args.debug_blue_full_system,
543+
False,
544+
should_restart_on_crash=False,
545+
running_in_realtime=args.enable_thunderscope,
546+
) as blue_fs, FullSystem(
547+
"software/unix_full_system",
548+
f"{args.yellow_full_system_runtime_dir}/test/{test_name}",
549+
args.debug_yellow_full_system,
550+
True,
551+
should_restart_on_crash=False,
552+
running_in_realtime=args.enable_thunderscope,
553+
) as yellow_fs:
556554
with Gamecontroller(
557555
suppress_logs=(not args.show_gamecontroller_logs)
558556
) as gamecontroller:
@@ -582,7 +580,7 @@ def simulated_test_runner():
582580
layout_path=args.layout,
583581
)
584582

585-
time.sleep(SimulatedTestConstants.LAUNCH_DELAY_S)
583+
time.sleep(LAUNCH_DELAY_S)
586584

587585
runner = None
588586

src/software/simulated_tests/validation/validation.py

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,23 @@ def flip_validation(self, world):
8282
# We simply pass the validation_geometry from the validation object through.
8383
common = {
8484
"__init__": constructor,
85-
"get_validation_geometry": lambda self,
86-
world: self.validation.get_validation_geometry(world),
85+
"get_validation_geometry": lambda self, world: (
86+
self.validation.get_validation_geometry(world)
87+
),
8788
}
8889

8990
eventually_true = type(
9091
"EventuallyTrueValidation",
9192
(Validation,),
9293
{
9394
**common,
94-
"__repr__": lambda self: "EventuallyTrueValidation: "
95-
+ repr(self.validation),
95+
"__repr__": lambda self: (
96+
"EventuallyTrueValidation: " + repr(self.validation)
97+
),
9698
"get_validation_type": lambda self: ValidationType.EVENTUALLY,
97-
"get_validation_status": lambda self,
98-
world: self.validation.get_validation_status(world),
99+
"get_validation_status": lambda self, world: (
100+
self.validation.get_validation_status(world)
101+
),
99102
},
100103
)
101104

@@ -104,8 +107,9 @@ def flip_validation(self, world):
104107
(Validation,),
105108
{
106109
**common,
107-
"__repr__": lambda self: "EventuallyFalseValidation: "
108-
+ repr(self.validation),
110+
"__repr__": lambda self: (
111+
"EventuallyFalseValidation: " + repr(self.validation)
112+
),
109113
"get_validation_type": lambda self: ValidationType.EVENTUALLY,
110114
"get_validation_status": lambda self, world: flip_validation(self, world),
111115
},
@@ -118,8 +122,9 @@ def flip_validation(self, world):
118122
**common,
119123
"__repr__": lambda self: "AlwaysTrueValidation: " + repr(self.validation),
120124
"get_validation_type": lambda self: ValidationType.ALWAYS,
121-
"get_validation_status": lambda self,
122-
world: self.validation.get_validation_status(world),
125+
"get_validation_status": lambda self, world: (
126+
self.validation.get_validation_status(world)
127+
),
123128
},
124129
)
125130

@@ -137,44 +142,6 @@ def flip_validation(self, world):
137142
return eventually_true, eventually_false, always_true, always_false
138143

139144

140-
def create_validation_geometry(geometry=[]) -> ValidationGeometry:
141-
"""Creates a ValidationGeometry which is a visual representation of the
142-
validation to be rendered as either green (PASSING) or red (FAILING)
143-
144-
Given a list of (vectors, polygons, circles), creates a ValidationGeometry
145-
proto containing the protobuf representations.
146-
147-
:param geometry: A list of geom
148-
:return: ValidationGeometry
149-
"""
150-
validation_geometry = ValidationGeometry()
151-
152-
CREATE_PROTO_DISPATCH = {
153-
tbots_cpp.Vector.__name__: tbots_cpp.createVectorProto,
154-
tbots_cpp.Polygon.__name__: tbots_cpp.createPolygonProto,
155-
tbots_cpp.Rectangle.__name__: tbots_cpp.createPolygonProto,
156-
tbots_cpp.Circle.__name__: tbots_cpp.createCircleProto,
157-
tbots_cpp.Segment.__name__: tbots_cpp.createSegmentProto,
158-
tbots_cpp.Stadium.__name__: tbots_cpp.createStadiumProto,
159-
}
160-
161-
ADD_TO_VALIDATION_GEOMETRY_DISPATCH = {
162-
tbots_cpp.Vector.__name__: validation_geometry.vectors.append,
163-
tbots_cpp.Polygon.__name__: validation_geometry.polygons.append,
164-
tbots_cpp.Rectangle.__name__: validation_geometry.polygons.append,
165-
tbots_cpp.Circle.__name__: validation_geometry.circles.append,
166-
tbots_cpp.Segment.__name__: validation_geometry.segments.append,
167-
tbots_cpp.Stadium.__name__: validation_geometry.stadiums.append,
168-
}
169-
170-
for geom in geometry:
171-
ADD_TO_VALIDATION_GEOMETRY_DISPATCH[type(geom).__name__](
172-
CREATE_PROTO_DISPATCH[type(geom).__name__](geom)
173-
)
174-
175-
return validation_geometry
176-
177-
178145
def run_validation_sequence_sets(
179146
world, eventually_validation_sequence_set, always_validation_sequence_set
180147
):
@@ -248,6 +215,44 @@ def create_validation_proto_helper(validation_proto_set, validation):
248215
return eventually_validation_proto_set, always_validation_proto_set
249216

250217

218+
def create_validation_geometry(geometry=[]) -> ValidationGeometry:
219+
"""Creates a ValidationGeometry which is a visual representation of the
220+
validation to be rendered as either green (PASSING) or red (FAILING)
221+
222+
Given a list of (vectors, polygons, circles), creates a ValidationGeometry
223+
proto containing the protobuf representations.
224+
225+
:param geometry: A list of geom
226+
:return: ValidationGeometry
227+
"""
228+
validation_geometry = ValidationGeometry()
229+
230+
CREATE_PROTO_DISPATCH = {
231+
tbots_cpp.Vector.__name__: tbots_cpp.createVectorProto,
232+
tbots_cpp.Polygon.__name__: tbots_cpp.createPolygonProto,
233+
tbots_cpp.Rectangle.__name__: tbots_cpp.createPolygonProto,
234+
tbots_cpp.Circle.__name__: tbots_cpp.createCircleProto,
235+
tbots_cpp.Segment.__name__: tbots_cpp.createSegmentProto,
236+
tbots_cpp.Stadium.__name__: tbots_cpp.createStadiumProto,
237+
}
238+
239+
ADD_TO_VALIDATION_GEOMETRY_DISPATCH = {
240+
tbots_cpp.Vector.__name__: validation_geometry.vectors.append,
241+
tbots_cpp.Polygon.__name__: validation_geometry.polygons.append,
242+
tbots_cpp.Rectangle.__name__: validation_geometry.polygons.append,
243+
tbots_cpp.Circle.__name__: validation_geometry.circles.append,
244+
tbots_cpp.Segment.__name__: validation_geometry.segments.append,
245+
tbots_cpp.Stadium.__name__: validation_geometry.stadiums.append,
246+
}
247+
248+
for geom in geometry:
249+
ADD_TO_VALIDATION_GEOMETRY_DISPATCH[type(geom).__name__](
250+
CREATE_PROTO_DISPATCH[type(geom).__name__](geom)
251+
)
252+
253+
return validation_geometry
254+
255+
251256
def check_validation(validation_proto_set):
252257
"""Check validation and make sure its always true
253258

src/software/thunderscope/constants.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,3 @@ class RuntimeManagerConstants:
413413
RELEASES_URL = "https://api.github.com/repos/UBC-Thunderbots/Software/releases"
414414
DOWNLOAD_URL = "https://github.com/UBC-Thunderbots/Software/releases/download/"
415415
MAX_RELEASES_FETCHED = 5
416-
417-
418-
class SimulatedTestConstants:
419-
"""Constants for Simulated Tests"""
420-
421-
LAUNCH_DELAY_S = 0.1
422-
WORLD_BUFFER_TIMEOUT = 0.5
423-
PROCESS_BUFFER_DELAY_S = 0.01
424-
PAUSE_AFTER_FAIL_DELAY_S = 3
425-
TICK_DURATION_S = 0.0166 # 60 Hz

0 commit comments

Comments
 (0)