Skip to content

Commit b7513af

Browse files
committed
Fix inconsistent spacing and formatting in util.hpp and util.cpp
1 parent 76a13a4 commit b7513af

6 files changed

Lines changed: 76 additions & 69 deletions

File tree

cmake/configure.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if (NOT CMAKE_BUILD_TYPE)
1010
set(CMAKE_BUILD_TYPE "Release")
1111
endif(NOT CMAKE_BUILD_TYPE)
1212

13+
if (MSVC)
14+
add_compile_options("/utf-8")
15+
endif()
16+
1317
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/arch" )
1418
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/lib" )
1519
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin" )

modules/core/CMakeLists.txt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,46 @@ set_target_properties(${exec_func_lib} PROPERTIES LINKER_LANGUAGE CXX)
2626
add_dependencies(${exec_func_lib} ppc_libenvpp)
2727
target_link_directories(${exec_func_lib} PUBLIC "${CMAKE_BINARY_DIR}/ppc_libenvpp/install/lib")
2828
target_link_directories(${exec_func_lib} PUBLIC "${CMAKE_BINARY_DIR}/ppc_libenvpp/build")
29-
target_link_libraries(${exec_func_lib} PUBLIC fmt envpp)
29+
if(MSVC)
30+
target_link_libraries(${exec_func_lib} PUBLIC fmt libenvpp)
31+
else()
32+
target_link_libraries(${exec_func_lib} PUBLIC fmt envpp)
33+
endif ()
3034

31-
add_executable(${exec_func_tests} ${FUNC_TESTS_SOURCE_FILES})
35+
add_dependencies(${exec_func_lib} ppc_json)
36+
target_link_directories(${exec_func_lib} INTERFACE "${CMAKE_BINARY_DIR}/ppc_json/install/include")
37+
38+
add_dependencies(${exec_func_lib} ppc_googletest)
39+
target_link_directories(${exec_func_lib} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")
40+
target_link_libraries(${exec_func_lib} PUBLIC gtest gtest_main)
41+
42+
target_link_libraries(${exec_func_lib} PUBLIC Threads::Threads)
43+
44+
find_package(OpenMP REQUIRED)
45+
target_link_libraries(${exec_func_lib} PUBLIC ${OpenMP_libomp_LIBRARY} OpenMP::OpenMP_CXX)
3246

33-
add_dependencies(${exec_func_tests} ppc_googletest)
34-
target_link_directories(${exec_func_tests} PUBLIC ${CMAKE_BINARY_DIR}/ppc_googletest/install/lib)
35-
target_link_libraries(${exec_func_tests} PUBLIC gtest gtest_main)
47+
add_dependencies(${exec_func_lib} ppc_onetbb)
48+
target_link_directories(${exec_func_lib} PUBLIC ${CMAKE_BINARY_DIR}/ppc_onetbb/install/lib)
49+
if(NOT MSVC)
50+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
51+
target_link_libraries(${exec_func_lib} PUBLIC tbb_debug)
52+
else()
53+
target_link_libraries(${exec_func_lib} PUBLIC tbb)
54+
endif()
55+
endif()
3656

3757
if( MPI_COMPILE_FLAGS )
38-
set_target_properties(${exec_func_tests} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
58+
set_target_properties(${exec_func_lib} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
3959
endif( MPI_COMPILE_FLAGS )
4060

4161
if( MPI_LINK_FLAGS )
42-
set_target_properties(${exec_func_tests} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
62+
set_target_properties(${exec_func_lib} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
4363
endif( MPI_LINK_FLAGS )
44-
target_link_libraries(${exec_func_tests} PUBLIC ${MPI_LIBRARIES})
64+
target_link_libraries(${exec_func_lib} PUBLIC ${MPI_LIBRARIES})
65+
66+
target_link_directories(${exec_func_lib} INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
67+
68+
add_executable(${exec_func_tests} ${FUNC_TESTS_SOURCE_FILES})
4569

4670
target_link_libraries(${exec_func_tests} PUBLIC ${exec_func_lib})
4771

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
#include <cstdint>
77
#include <vector>
88

9-
#include "core/task/func_tests/test_task.hpp"
109
#include "omp.h"
1110

12-
TEST(ppc_func_tests_common, threads_control_check_openmp) {
11+
namespace my::nested {
12+
struct Type {};
13+
} // namespace my::nested
14+
15+
TEST(util_tests, extracts_correct_namespace) {
16+
constexpr std::string_view kNs = ppc::util::GetNamespace<my::nested::Type>();
17+
EXPECT_EQ(kNs, "my::nested");
18+
}
19+
20+
TEST(util_tests, threads_control_check_openmp) {
1321
int ppc_num_threads = ppc::util::GetNumThreads();
1422

1523
int omp_num_threads = -1;

modules/core/util/include/util.hpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,47 @@ enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
3333
std::string GetAbsolutePath(const std::string &relative_path);
3434
int GetNumThreads();
3535

36-
#if (defined(__clang__) || defined(__GNUC__)) && !defined(_MSC_VER)
3736
template <typename T>
38-
consteval std::string_view GetNamespace() {
37+
constexpr std::string_view GetNamespace() {
38+
#if defined(__clang__) || defined(__GNUC__)
3939
constexpr std::string_view kFunc = __PRETTY_FUNCTION__;
40-
// example: "consteval std::string_view get_namespace() [with T = my_namespace::MyClass]"
4140
constexpr std::string_view kKey = "T = ";
41+
42+
auto start = kFunc.find(kKey);
43+
if (start == std::string_view::npos) return {};
44+
start += kKey.size();
45+
46+
auto end = kFunc.rfind("::");
47+
if (end == std::string_view::npos || end <= start) return {};
48+
49+
return kFunc.substr(start, end - start);
50+
4251
#elif defined(_MSC_VER)
43-
template <typename T>
44-
constexpr std::string_view GetNamespace() {
4552
constexpr std::string_view kFunc = __FUNCSIG__;
46-
// example: "class std::basic_string_view<char,struct std::char_traits<char> > __cdecl get_namespace<class
47-
// my_namespace::MyClass>(void)"
48-
constexpr std::string_view kKey = "get_namespace<";
49-
#else
50-
static_assert(false, "Unsupported compiler");
51-
#endif
53+
constexpr std::string_view kKey = "GetNamespace<";
5254

5355
auto start = kFunc.find(kKey);
54-
if (start == std::string_view::npos) {
55-
return {};
56-
}
56+
if (start == std::string_view::npos) return {};
5757
start += kKey.size();
5858

59-
auto end = kFunc.find("::", start);
60-
if (end == std::string_view::npos) {
61-
return {};
59+
// Удалим class/struct/enum/union префиксы
60+
constexpr std::string_view prefixes[] = {"class ", "struct ", "enum ", "union "};
61+
for (auto prefix : prefixes) {
62+
if (kFunc.substr(start, prefix.size()) == prefix) {
63+
start += prefix.size();
64+
break;
65+
}
6266
}
6367

68+
auto end = kFunc.rfind("::");
69+
if (end == std::string_view::npos || end <= start) return {};
70+
6471
return kFunc.substr(start, end - start);
72+
73+
#else
74+
static_assert([] { return false; }(), "Unsupported compiler");
75+
return {};
76+
#endif
6577
}
6678

6779
bool IsUnderMpirun();

scripts/run_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ def run_threads(self):
8585
self.__run_exec(f"{self.work_dir / 'ppc_func_tests'} {self.__get_gtest_settings(3, '_' + task_type + '_')}")
8686

8787
def run_core(self):
88-
self.__run_exec(f"{self.work_dir / 'ppc_func_tests'} {self.__get_gtest_settings(1, '_common')}")
89-
9088
if platform.system() == "Linux" and not self.__ppc_env.get("PPC_ASAN_RUN"):
9189
self.__run_exec(f"{self.valgrind_cmd} {self.work_dir / 'core_func_tests'} "
9290
f"{self.__get_gtest_settings(1, '*')} --gtest_filter=*:-*_death_test")

tasks/CMakeLists.txt

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(exec_perf_tests "ppc_perf_tests")
88
set(list_of_exec_tests "")
99
if (USE_FUNC_TESTS)
1010
add_executable(${exec_func_tests} "${CMAKE_CURRENT_SOURCE_DIR}/common/runners/functional.cpp"
11-
"${CMAKE_CURRENT_SOURCE_DIR}/common/tests/util.cpp")
11+
"../modules/core/util/func_tests/util.cpp")
1212
list(APPEND list_of_exec_tests ${exec_func_tests})
1313
endif (USE_FUNC_TESTS)
1414

@@ -34,45 +34,6 @@ endforeach()
3434
add_library(stb_image INTERFACE)
3535
3636
foreach (exec_func ${list_of_exec_tests})
37-
target_link_libraries(${exec_func} PUBLIC Threads::Threads)
38-
39-
find_package(OpenMP REQUIRED)
40-
target_link_libraries(${exec_func} PUBLIC ${OpenMP_libomp_LIBRARY} OpenMP::OpenMP_CXX)
41-
42-
if( MPI_COMPILE_FLAGS )
43-
set_target_properties(${exec_func} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
44-
endif( MPI_COMPILE_FLAGS )
45-
46-
if( MPI_LINK_FLAGS )
47-
set_target_properties(${exec_func} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
48-
endif( MPI_LINK_FLAGS )
49-
target_link_libraries(${exec_func} PUBLIC ${MPI_LIBRARIES})
50-
51-
add_dependencies(${exec_func} ppc_onetbb)
52-
target_link_directories(${exec_func} PUBLIC ${CMAKE_BINARY_DIR}/ppc_onetbb/install/lib)
53-
if(NOT MSVC)
54-
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
55-
target_link_libraries(${exec_func} PUBLIC tbb_debug)
56-
else()
57-
target_link_libraries(${exec_func} PUBLIC tbb)
58-
endif()
59-
endif()
60-
61-
target_link_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
62-
target_link_libraries(${exec_func} PUBLIC stb_image)
63-
64-
add_dependencies(${exec_func} ppc_googletest)
65-
target_link_directories(${exec_func} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")
66-
target_link_libraries(${exec_func} PUBLIC gtest gtest_main)
67-
68-
add_dependencies(${exec_func} ppc_json)
69-
target_link_directories(${exec_func} INTERFACE "${CMAKE_BINARY_DIR}/ppc_json/install/include")
70-
71-
add_dependencies(${exec_func} ppc_libenvpp)
72-
target_link_directories(${exec_func} PUBLIC "${CMAKE_BINARY_DIR}/ppc_libenvpp/install/lib")
73-
target_link_directories(${exec_func} PUBLIC "${CMAKE_BINARY_DIR}/ppc_libenvpp/build")
74-
target_link_libraries(${exec_func} PUBLIC fmt envpp)
75-
7637
enable_testing()
7738
add_test(NAME ${exec_func} COMMAND ${exec_func})
7839

0 commit comments

Comments
 (0)