1 // Copyright 2023 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "absl/flags/flag.h"
16 #include "absl/log/log.h"
17 #include "src/core/lib/slice/slice_internal.h"
18 #include "src/core/telemetry/stats.h"
19 #include "src/core/telemetry/stats_data.h"
20 #include "src/proto/grpc/testing/control.pb.h"
21 #include "test/core/test_util/test_config.h"
22 #include "test/core/test_util/tls_utils.h"
23 #include "test/cpp/qps/benchmark_config.h"
24 #include "test/cpp/qps/driver.h"
25 #include "test/cpp/qps/parse_json.h"
26 #include "test/cpp/util/test_config.h"
27 #include "test/cpp/util/test_credentials_provider.h"
28
29 ABSL_FLAG(std::string, loadtest_config, "",
30 "Path to a gRPC benchmark loadtest scenario JSON file. See "
31 "scenario_runner.py");
32
33 namespace grpc {
34 namespace testing {
35
RunScenario()36 static void RunScenario() {
37 std::string json_str =
38 grpc_core::testing::GetFileContents(absl::GetFlag(FLAGS_loadtest_config));
39 Scenarios scenarios;
40 ParseJson(json_str, "grpc.testing.Scenarios", &scenarios);
41 LOG(INFO) << "Running " << scenarios.scenarios(0).name();
42 const auto result =
43 RunScenario(scenarios.scenarios(0).client_config(), 1,
44 scenarios.scenarios(0).server_config(), 1,
45 scenarios.scenarios(0).warmup_seconds(),
46 scenarios.scenarios(0).benchmark_seconds(), -2, "",
47 kInsecureCredentialsType, {}, false, 0);
48 GetReporter()->ReportQPS(*result);
49 GetReporter()->ReportLatency(*result);
50 LOG(ERROR) << "Global Stats:\n"
51 << StatsAsJson(grpc_core::global_stats().Collect().get());
52 }
53
54 } // namespace testing
55 } // namespace grpc
56
main(int argc,char ** argv)57 int main(int argc, char** argv) {
58 grpc::testing::TestEnvironment env(&argc, argv);
59 grpc::testing::InitTest(&argc, &argv, true);
60 grpc::testing::RunScenario();
61 return 0;
62 }
63