Skip to content

Commit 025a2d1

Browse files
committed
refactor(UT): add a logging benchmark LoggingTest.SimpleBenchmark
1 parent 5cd6065 commit 025a2d1

4 files changed

Lines changed: 54 additions & 7 deletions

File tree

src/utils/test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ set(MY_PROJ_LIBS
4242

4343
set(MY_BOOST_LIBS Boost::system Boost::filesystem)
4444

45-
# Extra files that will be installed
46-
set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
45+
set(MY_BINPLACES
46+
"${CMAKE_CURRENT_SOURCE_DIR}/config.ini"
47+
"${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
4748
"${CMAKE_CURRENT_SOURCE_DIR}/config-dup-key.ini"
4849
"${CMAKE_CURRENT_SOURCE_DIR}/config-dup-section.ini"
4950
"${CMAKE_CURRENT_SOURCE_DIR}/config-empty.ini"
@@ -53,8 +54,7 @@ set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
5354
"${CMAKE_CURRENT_SOURCE_DIR}/config-sample.ini"
5455
"${CMAKE_CURRENT_SOURCE_DIR}/config-unmatch-section.ini"
5556
"${CMAKE_CURRENT_SOURCE_DIR}/run.sh"
56-
"${CMAKE_CURRENT_SOURCE_DIR}/clear.sh"
57-
)
57+
"${CMAKE_CURRENT_SOURCE_DIR}/clear.sh")
5858
add_subdirectory(nth_element_bench)
5959
add_definitions(-Wno-dangling-else)
6060
dsn_add_test()

src/utils/test/config.ini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; Licensed to the Apache Software Foundation (ASF) under one
2+
; or more contributor license agreements. See the NOTICE file
3+
; distributed with this work for additional information
4+
; regarding copyright ownership. The ASF licenses this file
5+
; to you under the Apache License, Version 2.0 (the
6+
; "License"); you may not use this file except in compliance
7+
; with the License. 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,
12+
; software distributed under the License is distributed on an
13+
; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
; KIND, either express or implied. See the License for the
15+
; specific language governing permissions and limitations
16+
; under the License.
17+
18+
[apps.mimic]
19+
type = dsn.app.mimic
20+
pools = THREAD_POOL_TEST_SERVER
21+
22+
[core]
23+
enable_default_app_mimic = true
24+
tool = nativerun
25+
26+
[test]
27+
logging_test_simple_benchmark_loops = 10

src/utils/test/logging.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@
2929

3030
#include "gtest/gtest.h"
3131
#include "spdlog/common.h"
32+
#include "utils/flags.h"
3233
#include "utils/fmt_logging.h"
3334
#include "utils/timer.h"
3435

3536
TEST(LoggingTest, LOG) { LOG(spdlog::level::info, "in TEST(LoggingTest, GlobalLog)"); }
3637

38+
DSN_DEFINE_int32(test,
39+
logging_test_simple_benchmark_loops,
40+
10,
41+
"The loop times for LoggingTest.SimpleBenchmark test case");
42+
3743
TEST(LoggingTest, LOGWithBigString)
3844
{
3945
std::string big_str(128000, 'x');
@@ -80,3 +86,18 @@ TEST(LoggingTest, TestLogTiming)
8086

8187
ASSERT_EQ("hello", s2);
8288
}
89+
90+
TEST(LoggingTest, SimpleBenchmark)
91+
{
92+
g_stderr_logger->set_level(spdlog::level::critical);
93+
g_file_logger->set_level(spdlog::level::debug);
94+
SCOPED_LOG_TIMING(info,
95+
"LoggingTest.SimpleBenchmark loop {} times",
96+
FLAGS_logging_test_simple_benchmark_loops);
97+
for (int i = 0; i < FLAGS_logging_test_simple_benchmark_loops; i++) {
98+
LOG_DEBUG("abc {}, {}, {}", i, 1.0, "hello 1");
99+
LOG_INFO("abc {}, {}, {}", i + 1, 2.0, "hello 2");
100+
LOG_WARNING("abc {}, {}, {}", i + 2, 3.0, "hello 3");
101+
LOG_ERROR("abc {}, {}, {}", i + 3, 4.0, "hello 4");
102+
}
103+
}

src/utils/test/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818
#include <gtest/gtest.h>
1919
#include <memory>
2020

21+
#include "runtime/app_model.h"
2122
#include "utils/flags.h"
2223
#include "utils/logging.h"
2324

2425
GTEST_API_ int main(int argc, char **argv)
2526
{
2627
testing::InitGoogleTest(&argc, argv);
27-
2828
dsn_log_init("./", "test");
29-
29+
dsn_run_config("config.ini", false);
3030
dsn::flags_initialize();
31-
3231
return RUN_ALL_TESTS();
3332
}

0 commit comments

Comments
 (0)