mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.0 KiB
100 lines
3.0 KiB
2 years ago
|
//
|
||
|
//
|
||
|
// Copyright 2015 gRPC authors.
|
||
|
//
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
//
|
||
|
//
|
||
10 years ago
|
|
||
10 years ago
|
#include <string.h>
|
||
|
|
||
1 year ago
|
#include <memory>
|
||
|
|
||
4 years ago
|
#include <gtest/gtest.h>
|
||
|
|
||
8 months ago
|
#include "absl/log/check.h"
|
||
|
|
||
4 years ago
|
#include <grpc/support/log.h>
|
||
|
|
||
2 years ago
|
#include "src/core/lib/gprpp/crash.h"
|
||
8 months ago
|
#include "test/core/test_util/test_config.h"
|
||
10 years ago
|
|
||
9 years ago
|
static bool log_func_reached = false;
|
||
|
|
||
7 years ago
|
static void test_callback(gpr_log_func_args* args) {
|
||
8 months ago
|
CHECK_EQ(strcmp(__FILE__, args->file), 0);
|
||
|
CHECK(args->severity == GPR_LOG_SEVERITY_INFO);
|
||
|
CHECK_EQ(strcmp(args->message, "hello 1 2 3"), 0);
|
||
10 years ago
|
}
|
||
|
|
||
5 years ago
|
static void test_should_log(gpr_log_func_args* /*args*/) {
|
||
9 years ago
|
log_func_reached = true;
|
||
|
}
|
||
|
|
||
5 years ago
|
static void test_should_not_log(gpr_log_func_args* /*args*/) {
|
||
2 years ago
|
grpc_core::Crash("unreachable");
|
||
5 years ago
|
}
|
||
9 years ago
|
|
||
|
#define test_log_function_reached(SEVERITY) \
|
||
|
gpr_set_log_function(test_should_log); \
|
||
|
log_func_reached = false; \
|
||
|
gpr_log_message(SEVERITY, "hello 1 2 3"); \
|
||
8 months ago
|
CHECK(log_func_reached); \
|
||
9 years ago
|
log_func_reached = false; \
|
||
|
gpr_log(SEVERITY, "hello %d %d %d", 1, 2, 3); \
|
||
8 months ago
|
CHECK(log_func_reached); \
|
||
4 years ago
|
gpr_set_log_function(nullptr);
|
||
9 years ago
|
|
||
4 years ago
|
#define test_log_function_unreached(SEVERITY) \
|
||
|
gpr_set_log_function(test_should_not_log); \
|
||
|
gpr_log_message(SEVERITY, "hello 1 2 3"); \
|
||
|
gpr_log(SEVERITY, "hello %d %d %d", 1, 2, 3); \
|
||
|
gpr_set_log_function(nullptr);
|
||
9 years ago
|
|
||
4 years ago
|
TEST(LogTest, Basic) {
|
||
2 years ago
|
// test logging at various verbosity levels
|
||
10 years ago
|
gpr_log(GPR_DEBUG, "%s", "hello world");
|
||
|
gpr_log(GPR_INFO, "%s", "hello world");
|
||
|
gpr_log(GPR_ERROR, "%s", "hello world");
|
||
2 years ago
|
// should succeed
|
||
8 months ago
|
CHECK(1);
|
||
10 years ago
|
gpr_set_log_function(test_callback);
|
||
|
gpr_log_message(GPR_INFO, "hello 1 2 3");
|
||
|
gpr_log(GPR_INFO, "hello %d %d %d", 1, 2, 3);
|
||
7 years ago
|
gpr_set_log_function(nullptr);
|
||
4 years ago
|
}
|
||
9 years ago
|
|
||
4 years ago
|
TEST(LogTest, LogVerbosity) {
|
||
9 years ago
|
gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
|
||
|
test_log_function_reached(GPR_ERROR);
|
||
|
test_log_function_reached(GPR_INFO);
|
||
|
test_log_function_reached(GPR_DEBUG);
|
||
|
|
||
|
gpr_set_log_verbosity(GPR_LOG_SEVERITY_INFO);
|
||
|
test_log_function_reached(GPR_ERROR);
|
||
|
test_log_function_reached(GPR_INFO);
|
||
|
test_log_function_unreached(GPR_DEBUG);
|
||
|
|
||
|
gpr_set_log_verbosity(GPR_LOG_SEVERITY_ERROR);
|
||
|
test_log_function_reached(GPR_ERROR);
|
||
|
test_log_function_unreached(GPR_INFO);
|
||
|
test_log_function_unreached(GPR_DEBUG);
|
||
4 years ago
|
}
|
||
9 years ago
|
|
||
4 years ago
|
int main(int argc, char** argv) {
|
||
3 years ago
|
grpc::testing::TestEnvironment env(&argc, argv);
|
||
4 years ago
|
::testing::InitGoogleTest(&argc, argv);
|
||
|
int ret = RUN_ALL_TESTS();
|
||
|
return ret;
|
||
10 years ago
|
}
|