1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 #include "pw_rpc/integration_testing.h"
16
17 #include <limits>
18
19 #include "gtest/gtest.h"
20 #include "pw_log/log.h"
21 #include "pw_rpc/integration_test_socket_client.h"
22 #include "pw_unit_test/logging_event_handler.h"
23
24 namespace pw::rpc::integration_test {
25 namespace {
26
27 SocketClientContext<512> context;
28 unit_test::LoggingEventHandler log_test_events;
29
30 } // namespace
31
client()32 Client& client() { return context.client(); }
33
InitializeClient(int argc,char * argv[],const char * usage_args)34 Status InitializeClient(int argc, char* argv[], const char* usage_args) {
35 unit_test::RegisterEventHandler(&log_test_events);
36
37 if (argc < 2) {
38 PW_LOG_INFO("Usage: %s %s", argv[0], usage_args);
39 return Status::InvalidArgument();
40 }
41
42 const int port = std::atoi(argv[1]);
43
44 if (port <= 0 || port > std::numeric_limits<uint16_t>::max()) {
45 PW_LOG_CRITICAL("Port numbers must be between 1 and 65535; %d is invalid",
46 port);
47 return Status::InvalidArgument();
48 }
49
50 PW_LOG_INFO("Connecting to pw_rpc client at localhost:%d", port);
51 return context.Start(port);
52 }
53
54 } // namespace pw::rpc::integration_test
55