Skip to content

Commit

Permalink
test_duration
Browse files Browse the repository at this point in the history
  • Loading branch information
bongbui321 committed May 20, 2024
1 parent 05b9b49 commit 4579458
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
${{ env.RUN }} "export MAPBOX_TOKEN='pk.eyJ1Ijoiam5ld2IiLCJhIjoiY2xxNW8zZXprMGw1ZzJwbzZneHd2NHljbSJ9.gV7VPRfbXFetD-1OVF0XZg' && \
source selfdrive/test/setup_xvfb.sh && \
source selfdrive/test/setup_vsound.sh && \
CI=1 pytest tools/sim/tests/test_metadrive_bridge.py --time_done=90 -W ignore::pyopencl.CompilerWarning"
CI=1 pytest tools/sim/tests/test_metadrive_bridge.py --test_duration=90 -W ignore::pyopencl.CompilerWarning"
devcontainer:
name: devcontainer
Expand Down
6 changes: 3 additions & 3 deletions tools/sim/bridge/metadrive/metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def create_map(track_size=60):
class MetaDriveBridge(SimulatorBridge):
TICKS_PER_FRAME = 5

def __init__(self, dual_camera, high_quality, time_done=math.inf, test_run=False):
def __init__(self, dual_camera, high_quality, test_duration=math.inf, test_run=False):
self.should_render = False
self.test_run = test_run
self.time_done = time_done if self.test_run else math.inf
self.test_duration = test_duration if self.test_run else math.inf

super().__init__(dual_camera, high_quality)

Expand Down Expand Up @@ -87,4 +87,4 @@ def spawn_world(self, queue: Queue):
preload_models=False
)

return MetaDriveWorld(queue, config, self.time_done, self.test_run, self.dual_camera)
return MetaDriveWorld(queue, config, self.test_duration, self.test_run, self.dual_camera)
10 changes: 5 additions & 5 deletions tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def arrive_destination_patch(self, *args, **kwargs):

def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera_array, image_lock,
controls_recv: Connection, simulation_state_send: Connection, vehicle_state_send: Connection,
exit_event, start_time, time_done, test_run):
exit_event, start_time, test_duration, test_run):
arrive_dest_done = config.pop("arrive_dest_done", True)
apply_metadrive_patches(arrive_dest_done)

Expand Down Expand Up @@ -113,16 +113,16 @@ def get_cam_as_rgb(cam):

if rk.frame % 5 == 0:
_, _, terminated, _, _ = env.step(vc)
time_out = True if time.monotonic() - start_time >= time_done else False
timeout = True if time.monotonic() - start_time >= test_duration else False
out_of_lane = env.vehicle.on_broken_line or env.vehicle.on_yellow_continuous_line or env.vehicle.on_white_continuous_line or env.vehicle.crash_sidewalk

if terminated or ((out_of_lane or time_out) and test_run):
if terminated or ((out_of_lane or timeout) and test_run):
if terminated:
done_result = env.done_function("default_agent")
elif out_of_lane:
done_result = (True, {"out_of_lane" : True})
elif time_out:
done_result = (True, {"time_done" : True})
elif timeout:
done_result = (True, {"timeout" : True})

simulation_state = metadrive_simulation_state(
running=False,
Expand Down
4 changes: 2 additions & 2 deletions tools/sim/bridge/metadrive/metadrive_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class MetaDriveWorld(World):
def __init__(self, status_q, config, time_done, test_run, dual_camera=False):
def __init__(self, status_q, config, test_duration, test_run, dual_camera=False):
super().__init__(dual_camera)
self.status_q = status_q
self.camera_array = Array(ctypes.c_uint8, W*H*3)
Expand All @@ -35,7 +35,7 @@ def __init__(self, status_q, config, time_done, test_run, dual_camera=False):
functools.partial(metadrive_process, dual_camera, config,
self.camera_array, self.wide_camera_array, self.image_lock,
self.controls_recv, self.simulation_state_send,
self.vehicle_state_send, self.exit_event, start_time, time_done, test_run))
self.vehicle_state_send, self.exit_event, start_time, test_duration, test_run))

self.metadrive_process.start()
self.status_q.put(QueueMessage(QueueMessageType.START_STATUS, "starting"))
Expand Down
6 changes: 3 additions & 3 deletions tools/sim/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest

def pytest_addoption(parser):
parser.addoption("--time_done", action="store", default=60, type=int, help="Seconds to run metadrive drive")
parser.addoption("--test_duration", action="store", default=60, type=int, help="Seconds to run metadrive drive")

@pytest.fixture
def time_done(request):
return request.config.getoption("--time_done")
def test_duration(request):
return request.config.getoption("--test_duration")
6 changes: 3 additions & 3 deletions tools/sim/tests/test_metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@pytest.mark.slow
class TestMetaDriveBridge(TestSimBridgeBase):
@pytest.fixture(autouse=True)
def setup_class(self, time_done):
self.time_done = time_done
def setup_class(self, test_duration):
self.test_duration = test_duration

def create_bridge(self):
return MetaDriveBridge(False, False, self.time_done, True)
return MetaDriveBridge(False, False, self.test_duration, True)
2 changes: 1 addition & 1 deletion tools/sim/tests/test_sim_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_driving(self):
state = q.get()
if state.type == QueueMessageType.TERMINATION_INFO:
done_info = state.info
failure_states = [done_state for done_state in done_info if done_state != "time_done" and done_info[done_state]]
failure_states = [done_state for done_state in done_info if done_state != "timeout" and done_info[done_state]]
break
assert len(failure_states) == 0, f"Simulator fails to finish a loop. Failure states: {failure_states}"

Expand Down

0 comments on commit 4579458

Please sign in to comment.