blob: b36dbcec2f95a68141bb69b8af210b8ebbbb81f5 [file] [log] [blame]
Craig Tiller0bda0b32016-03-03 12:51:53 -08001/*
2 *
3 * Copyright 2015-2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <memory>
35#include <sstream>
36#include <string>
37
38#include <grpc/support/log.h>
39
40#include "src/core/lib/support/env.h"
41#include "test/core/util/port.h"
42#include "test/cpp/util/subprocess.h"
43
44using grpc::SubProcess;
45
46template <class T>
47std::string as_string(const T& val) {
48 std::ostringstream out;
49 out << val;
50 return out.str();
51}
52
Mark D. Roth37d5f9b2016-11-28 10:45:00 -080053static void LogStatus(int status) {
54 if (WIFEXITED(status)) {
55 gpr_log(GPR_INFO, "subprocess exited with status %d",
56 WEXITSTATUS(status));
57 } else if (WIFSIGNALED(status)) {
58 gpr_log(GPR_INFO, "subprocess terminated with signal %d",
59 WTERMSIG(status));
60 } else {
61 gpr_log(GPR_INFO, "unknown subprocess status: %d", status);
62 }
63}
64
Craig Tiller0bda0b32016-03-03 12:51:53 -080065int main(int argc, char** argv) {
66 typedef std::unique_ptr<SubProcess> SubProcessPtr;
67 std::vector<SubProcessPtr> jobs;
68
69 std::string my_bin = argv[0];
70 std::string bin_dir = my_bin.substr(0, my_bin.rfind('/'));
71
72 std::ostringstream env;
73 bool first = true;
74
75 for (int i = 0; i < 2; i++) {
76 auto port = grpc_pick_unused_port_or_die();
77 std::vector<std::string> args = {bin_dir + "/qps_worker", "-driver_port",
78 as_string(port)};
79 jobs.emplace_back(new SubProcess(args));
80 if (!first) env << ",";
81 env << "localhost:" << port;
82 first = false;
83 }
84
85 gpr_setenv("QPS_WORKERS", env.str().c_str());
86 std::vector<std::string> args = {bin_dir + "/qps_json_driver"};
87 for (int i = 1; i < argc; i++) {
88 args.push_back(argv[i]);
89 }
Mark D. Roth37d5f9b2016-11-28 10:45:00 -080090gpr_log(GPR_INFO, "calling Join() on driver");
91 int status = SubProcess(args).Join();
92 if (status != 0) {
93 LogStatus(status);
94 GPR_ASSERT(status == 0);
95 }
Craig Tiller0bda0b32016-03-03 12:51:53 -080096
97 for (auto it = jobs.begin(); it != jobs.end(); ++it) {
98 (*it)->Interrupt();
99 }
100 for (auto it = jobs.begin(); it != jobs.end(); ++it) {
Mark D. Roth37d5f9b2016-11-28 10:45:00 -0800101gpr_log(GPR_INFO, "calling Join() on job");
102 status = (*it)->Join();
103 if (status != 0) {
104 LogStatus(status);
105 }
Craig Tiller0bda0b32016-03-03 12:51:53 -0800106 }
107}