1 //
2 //
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18
19 #include <grpc/grpc.h>
20 #include <grpc/support/time.h>
21 #include <signal.h>
22
23 #include <chrono>
24 #include <thread>
25 #include <vector>
26
27 #include "absl/flags/flag.h"
28 #include "src/core/telemetry/stats.h"
29 #include "test/core/test_util/test_config.h"
30 #include "test/cpp/qps/qps_worker.h"
31 #include "test/cpp/util/test_config.h"
32 #include "test/cpp/util/test_credentials_provider.h"
33
34 ABSL_FLAG(int32_t, driver_port, 0, "Port for communication with driver");
35 ABSL_FLAG(int32_t, server_port, 0,
36 "Port for operation as a server, if not specified by the server "
37 "config message");
38 ABSL_FLAG(std::string, credential_type, grpc::testing::kInsecureCredentialsType,
39 "Credential type for communication with driver");
40
41 static bool got_sigint = false;
42
sigint_handler(int)43 static void sigint_handler(int /*x*/) { got_sigint = true; }
44
45 namespace grpc {
46 namespace testing {
47
48 std::vector<grpc::testing::Server*>* g_inproc_servers = nullptr;
49
RunServer()50 static void RunServer() {
51 QpsWorker worker(absl::GetFlag(FLAGS_driver_port),
52 absl::GetFlag(FLAGS_server_port),
53 absl::GetFlag(FLAGS_credential_type));
54
55 while (!got_sigint && !worker.Done()) {
56 gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
57 gpr_time_from_millis(500, GPR_TIMESPAN)));
58 }
59 }
60
61 } // namespace testing
62 } // namespace grpc
63
main(int argc,char ** argv)64 int main(int argc, char** argv) {
65 grpc::testing::TestEnvironment env(&argc, argv);
66 grpc::testing::InitTest(&argc, &argv, true);
67
68 signal(SIGINT, sigint_handler);
69
70 grpc::testing::RunServer();
71 LOG(ERROR) << "Global Stats:\n"
72 << StatsAsJson(grpc_core::global_stats().Collect().get());
73 return 0;
74 }
75