From 2e254528a223221c66f6114606217e6b118682e2 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Sun, 10 Mar 2019 12:58:56 +0100 Subject: [PATCH] Add some smoke tests --- PythonAPI/test/smoke/__init__.py | 13 ++++++ PythonAPI/test/smoke/test_blueprint.py | 25 +++++++++++ PythonAPI/test/smoke/test_client.py | 24 +++++++---- PythonAPI/test/smoke/test_sync.py | 58 ++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 PythonAPI/test/smoke/test_blueprint.py create mode 100644 PythonAPI/test/smoke/test_sync.py diff --git a/PythonAPI/test/smoke/__init__.py b/PythonAPI/test/smoke/__init__.py index 5fbe05bf0..3c646d1c8 100644 --- a/PythonAPI/test/smoke/__init__.py +++ b/PythonAPI/test/smoke/__init__.py @@ -7,6 +7,7 @@ import glob import os import sys +import unittest try: sys.path.append(glob.glob('../../dist/carla-*%d.%d-%s.egg' % ( @@ -16,4 +17,16 @@ try: except IndexError: pass +import carla + + TESTING_ADDRESS=('localhost', 3654) + + +class SmokeTest(unittest.TestCase): + def setUp(self): + self.client = carla.Client(*TESTING_ADDRESS) + self.client.set_timeout(2.0) + + def tearDown(self): + self.client = None diff --git a/PythonAPI/test/smoke/test_blueprint.py b/PythonAPI/test/smoke/test_blueprint.py new file mode 100644 index 000000000..eeb9181eb --- /dev/null +++ b/PythonAPI/test/smoke/test_blueprint.py @@ -0,0 +1,25 @@ +# Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma de +# Barcelona (UAB). +# +# This work is licensed under the terms of the MIT license. +# For a copy, see . + +import re + +from . import SmokeTest + + +class TestBlueprintLibrary(SmokeTest): + def test_blueprint_ids(self): + library = self.client.get_world().get_blueprint_library() + self.assertTrue([x for x in library]) + self.assertTrue([x for x in library.filter('sensor.*')]) + self.assertTrue([x for x in library.filter('static.*')]) + self.assertTrue([x for x in library.filter('vehicle.*')]) + self.assertTrue([x for x in library.filter('walker.*')]) + rgx = re.compile(r'\S+\.\S+\.\S+') + for bp in library: + self.assertTrue(rgx.match(bp.id)) + rgx = re.compile(r'(vehicle)\.\S+\.\S+') + for bp in library.filter('vehicle.*'): + self.assertTrue(rgx.match(bp.id)) diff --git a/PythonAPI/test/smoke/test_client.py b/PythonAPI/test/smoke/test_client.py index ead6d02e7..bc76afc7d 100644 --- a/PythonAPI/test/smoke/test_client.py +++ b/PythonAPI/test/smoke/test_client.py @@ -4,15 +4,23 @@ # This work is licensed under the terms of the MIT license. # For a copy, see . -import carla +import random -import unittest +from . import SmokeTest -from . import TESTING_ADDRESS - - -class TestClient(unittest.TestCase): +class TestClient(SmokeTest): def test_version(self): - c = carla.Client(*TESTING_ADDRESS) - self.assertEqual(c.get_client_version(), c.get_server_version()) + self.assertEqual(self.client.get_client_version(), self.client.get_server_version()) + + def test_reload_world(self): + map_name = self.client.get_world().get_map().name + world = self.client.reload_world() + self.assertEqual(map_name, world.get_map().name) + + def test_load_all_maps(self): + map_names = list(self.client.get_available_maps()) + random.shuffle(map_names) + for map_name in map_names: + world = self.client.load_world(map_name) + self.assertEqual(map_name.split('/')[-1], world.get_map().name) diff --git a/PythonAPI/test/smoke/test_sync.py b/PythonAPI/test/smoke/test_sync.py new file mode 100644 index 000000000..65eb14f84 --- /dev/null +++ b/PythonAPI/test/smoke/test_sync.py @@ -0,0 +1,58 @@ +# Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma de +# Barcelona (UAB). +# +# This work is licensed under the terms of the MIT license. +# For a copy, see . + +from . import SmokeTest + +import carla + +try: + import queue +except ImportError: + import Queue as queue + + +class TestSynchronousMode(SmokeTest): + def setUp(self): + super(TestSynchronousMode, self).setUp() + self.world = self.client.get_world() + self.settings = self.world.get_settings() + settings = carla.WorldSettings( + no_rendering_mode=False, + synchronous_mode=True) + self.world.apply_settings(settings) + + def tearDown(self): + self.world.apply_settings(self.settings) + self.settings = None + self.world = None + super(TestSynchronousMode, self).tearDown() + + + def test_camera_on_synchronous_mode(self): + cam_bp = self.world.get_blueprint_library().find('sensor.camera.rgb') + t = carla.Transform(carla.Location(z=10)) + camera = self.world.spawn_actor(cam_bp, t) + try: + + image_queue = queue.Queue() + camera.listen(image_queue.put) + + frame = None + + for _ in range(0, 100): + self.world.tick() + ts = self.world.wait_for_tick() + + if frame is not None: + self.assertEqual(ts.frame_count, frame + 1) + + frame = ts.frame_count + + image = image_queue.get() + self.assertEqual(image.frame_number, ts.frame_count) + + finally: + camera.destroy()