From d4e3e12bb3378c6e47cfdd1670e6a31ad158c82e Mon Sep 17 00:00:00 2001 From: jinhelin Date: Tue, 16 May 2023 11:14:38 +0800 Subject: [PATCH] Check CPU cores in CPUAffinityManagerTest --- dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp b/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp index af4502ac97a..c9627dcdd3d 100644 --- a/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp +++ b/dbms/src/Common/tests/gtest_cpu_affinity_manager.cpp @@ -24,8 +24,10 @@ #include #include +#include #include #include +#include #include #include @@ -82,6 +84,15 @@ TEST(CPUAffinityManagerTest, CPUAffinityManager) int ret = sched_getaffinity(0, sizeof(cpu_set), &cpu_set); ASSERT_EQ(ret, 0) << strerror(errno); + auto n_cpu = std::thread::hardware_concurrency(); + auto cpu_cores = cpu_affinity.cpuSetToVec(cpu_set); + if (n_cpu != cpu_cores.size()) + { + LOG_INFO(Logger::get(), "n_cpu = {}, cpu_cores = {}, CPU number and CPU cores not match, don't not check CPUAffinityManager", n_cpu, cpu_cores); + return; + } + LOG_DEBUG(Logger::get(), "n_cpu = {}, cpu_cores = {}", n_cpu, cpu_cores); + cpu_affinity.bindSelfQueryThread(); cpu_set_t cpu_set0; ret = sched_getaffinity(0, sizeof(cpu_set0), &cpu_set0);