aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/interop/stress_test.cc
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-01-06 07:58:10 -0800
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-01-06 07:58:10 -0800
commit0fa95eab813e0561a9fb998ff0588521e42dba02 (patch)
tree73b7a6c7ef6926015ffc9ca512da6dc9675374a7 /test/cpp/interop/stress_test.cc
parent64f10281b01ac3c472e89f65de2a28eed77c0187 (diff)
Ability to filter log messages based on log level
Diffstat (limited to 'test/cpp/interop/stress_test.cc')
-rw-r--r--test/cpp/interop/stress_test.cc35
1 files changed, 33 insertions, 2 deletions
diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc
index 934f4f5722..22ef5a5491 100644
--- a/test/cpp/interop/stress_test.cc
+++ b/test/cpp/interop/stress_test.cc
@@ -50,6 +50,10 @@
#include "test/proto/metrics.grpc.pb.h"
#include "test/proto/metrics.pb.h"
+extern "C" {
+extern void gpr_default_log(gpr_log_func_args* args);
+}
+
DEFINE_int32(metrics_port, 8081, "The metrics server port.");
DEFINE_int32(metrics_collection_interval_secs, 5,
@@ -94,6 +98,12 @@ DEFINE_string(test_cases, "",
" 'large_unary', 10% of the time and 'empty_stream' the remaining"
" 70% of the time");
+DEFINE_int32(log_level, GPR_LOG_SEVERITY_DEBUG,
+ "Severity level of messages that should be logged. Any messages "
+ "greater than or equal to the level set here will be logged. "
+ "The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 "
+ "(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR.");
+
using grpc::testing::kTestCaseList;
using grpc::testing::MetricsService;
using grpc::testing::MetricsServiceImpl;
@@ -102,6 +112,16 @@ using grpc::testing::TestCaseType;
using grpc::testing::UNKNOWN_TEST;
using grpc::testing::WeightedRandomTestSelector;
+static int log_level = GPR_LOG_SEVERITY_DEBUG;
+
+// A simple wrapper to grp_default_log() function. This only logs messages at or
+// above the current log level (set in 'log_level' variable)
+void TestLogFunction(gpr_log_func_args* args) {
+ if (args->severity >= log_level) {
+ gpr_default_log(args);
+ }
+}
+
TestCaseType GetTestTypeFromName(const grpc::string& test_name) {
TestCaseType test_case = UNKNOWN_TEST;
@@ -190,6 +210,18 @@ void LogParameterInfo(const std::vector<grpc::string>& addresses,
int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true);
+ if (FLAGS_log_level > GPR_LOG_SEVERITY_ERROR ||
+ FLAGS_log_level < GPR_LOG_SEVERITY_DEBUG) {
+ gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d",
+ GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR);
+ return 1;
+ }
+
+ // Change the default log function to TestLogFunction which respects the
+ // log_level setting.
+ log_level = FLAGS_log_level;
+ gpr_set_log_function(TestLogFunction);
+
srand(time(NULL));
// Parse the server addresses
@@ -198,7 +230,7 @@ int main(int argc, char** argv) {
// Parse test cases and weights
if (FLAGS_test_cases.length() == 0) {
- gpr_log(GPR_INFO, "Not running tests. The 'test_cases' string is empty");
+ gpr_log(GPR_ERROR, "Not running tests. The 'test_cases' string is empty");
return 1;
}
@@ -270,6 +302,5 @@ int main(int argc, char** argv) {
it->join();
}
- metrics_server->Wait();
return 0;
}