Skip to content

Commit

Permalink
refactor(UT): add a logging benchmark LoggingTest.SimpleBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Aug 20, 2024
1 parent 5cd6065 commit 025a2d1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ set(MY_PROJ_LIBS

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

# Extra files that will be installed
set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
set(MY_BINPLACES
"${CMAKE_CURRENT_SOURCE_DIR}/config.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-dup-key.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-dup-section.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-empty.ini"
Expand All @@ -53,8 +54,7 @@ set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-bad-section.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-sample.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/config-unmatch-section.ini"
"${CMAKE_CURRENT_SOURCE_DIR}/run.sh"
"${CMAKE_CURRENT_SOURCE_DIR}/clear.sh"
)
"${CMAKE_CURRENT_SOURCE_DIR}/clear.sh")
add_subdirectory(nth_element_bench)
add_definitions(-Wno-dangling-else)
dsn_add_test()
27 changes: 27 additions & 0 deletions src/utils/test/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; Licensed to the Apache Software Foundation (ASF) under one
; or more contributor license agreements. See the NOTICE file
; distributed with this work for additional information
; regarding copyright ownership. The ASF licenses this file
; to you 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.

[apps.mimic]
type = dsn.app.mimic
pools = THREAD_POOL_TEST_SERVER

[core]
enable_default_app_mimic = true
tool = nativerun

[test]
logging_test_simple_benchmark_loops = 10
21 changes: 21 additions & 0 deletions src/utils/test/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@

#include "gtest/gtest.h"
#include "spdlog/common.h"
#include "utils/flags.h"
#include "utils/fmt_logging.h"
#include "utils/timer.h"

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

DSN_DEFINE_int32(test,
logging_test_simple_benchmark_loops,
10,
"The loop times for LoggingTest.SimpleBenchmark test case");

TEST(LoggingTest, LOGWithBigString)
{
std::string big_str(128000, 'x');
Expand Down Expand Up @@ -80,3 +86,18 @@ TEST(LoggingTest, TestLogTiming)

ASSERT_EQ("hello", s2);
}

TEST(LoggingTest, SimpleBenchmark)
{
g_stderr_logger->set_level(spdlog::level::critical);
g_file_logger->set_level(spdlog::level::debug);
SCOPED_LOG_TIMING(info,
"LoggingTest.SimpleBenchmark loop {} times",
FLAGS_logging_test_simple_benchmark_loops);
for (int i = 0; i < FLAGS_logging_test_simple_benchmark_loops; i++) {
LOG_DEBUG("abc {}, {}, {}", i, 1.0, "hello 1");
LOG_INFO("abc {}, {}, {}", i + 1, 2.0, "hello 2");
LOG_WARNING("abc {}, {}, {}", i + 2, 3.0, "hello 3");
LOG_ERROR("abc {}, {}, {}", i + 3, 4.0, "hello 4");
}
}
5 changes: 2 additions & 3 deletions src/utils/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
#include <gtest/gtest.h>
#include <memory>

#include "runtime/app_model.h"
#include "utils/flags.h"
#include "utils/logging.h"

GTEST_API_ int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);

dsn_log_init("./", "test");

dsn_run_config("config.ini", false);
dsn::flags_initialize();

return RUN_ALL_TESTS();
}

0 comments on commit 025a2d1

Please sign in to comment.