CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
test
client
test_rpc.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#include "
test.h
"
8
9
#include <
carla/MsgPackAdaptors.h
>
10
#include <
carla/ThreadGroup.h
>
11
#include <
carla/rpc/Actor.h
>
12
#include <
carla/rpc/Client.h
>
13
#include <
carla/rpc/Response.h
>
14
#include <
carla/rpc/Server.h
>
15
16
#include <thread>
17
18
using namespace
carla::rpc
;
19
using namespace
std::chrono_literals;
20
21
TEST
(
rpc
, compilation_tests) {
22
Server
server(
TESTING_PORT
);
23
server.BindSync(
"bind00"
, []() {
return
2.0f; });
24
server.BindSync(
"bind01"
, [](
int
x) {
return
x; });
25
server.BindSync(
"bind02"
, [](
int
,
float
) {
return
0.0; });
26
server.BindSync(
"bind03"
, [](
int
,
float
,
double
,
char
) {});
27
}
28
29
TEST
(
rpc
, server_bind_sync_run_on_game_thread) {
30
const
auto
main_thread_id = std::this_thread::get_id();
31
32
const
uint16_t port = (
TESTING_PORT
!= 0u ?
TESTING_PORT
: 2017u);
33
34
Server
server(port);
35
36
server.BindSync(
"do_the_thing"
, [=](
int
x,
int
y) ->
int
{
37
EXPECT_EQ(std::this_thread::get_id(), main_thread_id);
38
return
x + y;
39
});
40
41
server.AsyncRun(1u);
42
43
std::atomic_bool done{
false
};
44
45
carla::ThreadGroup
threads;
46
threads.
CreateThread
([&]() {
47
Client
client(
"127.0.0.1"
, port);
48
for
(
auto
i = 0; i < 300; ++i) {
49
auto
result = client.call(
"do_the_thing"
, i, 1).as<
int
>();
50
EXPECT_EQ(result, i + 1);
51
}
52
done =
true
;
53
});
54
55
auto
i = 0u;
56
for
(; i < 1'000'000u; ++i) {
57
server.SyncRunFor(2ms);
58
if
(done) {
59
break
;
60
}
61
}
62
std::cout <<
"game thread: run "
<< i <<
" slices.\n"
;
63
ASSERT_TRUE(done);
64
}
MsgPackAdaptors.h
Response.h
ThreadGroup.h
carla::ThreadGroup
Definition
ThreadGroup.h:17
carla::ThreadGroup::CreateThread
void CreateThread(F &&functor)
Definition
ThreadGroup.h:27
carla::rpc::Client
Definition
rpc/Client.h:16
carla::rpc::Server
An RPC server in which functions can be bind to run synchronously or asynchronously.
Definition
rpc/Server.h:40
carla::rpc
Definition
DebugShapeDrawer.h:11
Actor.h
Client.h
Server.h
test.h
TESTING_PORT
constexpr uint16_t TESTING_PORT
Definition
test.h:24
TEST
TEST(agents_types, road_option_values_match_python)
Definition
test_agents.cpp:40
Generated by
1.18.0