Add some smoke tests

This commit is contained in:
nsubiron 2019-03-10 12:58:56 +01:00
parent 40836a1fd4
commit 2e254528a2
4 changed files with 112 additions and 8 deletions

View File

@ -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

View File

@ -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 <https://opensource.org/licenses/MIT>.
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))

View File

@ -4,15 +4,23 @@
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
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)

View File

@ -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 <https://opensource.org/licenses/MIT>.
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()