22
33#include < gtest/gtest.h>
44
5- #include < tbb/tick_count.h>
6-
75#include < concepts>
86#include < cstddef>
97#include < functional>
1513#include < utility>
1614
1715#include " task/include/task.hpp"
16+ #include " util/include/task_descriptor_util.hpp"
1817#include " util/include/util.hpp"
1918
2019namespace ppc ::util {
2120
2221template <typename InType, typename OutType, typename TestType = void >
23- using FuncTestParam = std::tuple<std::function<ppc::task::TaskPtr<InType, OutType>(InType)>, std::string, TestType>;
22+ using FuncTestParam = std::tuple<std::function<ppc::task::TaskPtr<InType, OutType>(InType)>, std::string, TestType,
23+ ppc::task::TaskDescriptor>;
2424
2525template <typename InType, typename OutType, typename TestType = void >
2626using GTestFuncParam = ::testing::TestParamInfo<FuncTestParam<InType, OutType, TestType>>;
@@ -50,8 +50,7 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
5050 static std::string PrintFuncTestName (const GTestFuncParam<InType, OutType, TestType> &info) {
5151 RequireStaticInterface<Derived>();
5252 TestType test_param = std::get<static_cast <std::size_t >(ppc::util::GTestParamIndex::kTestParams )>(info.param );
53- return std::get<static_cast <std::size_t >(GTestParamIndex::kNameTest )>(info.param ) + " _" +
54- Derived::PrintTestParam (test_param);
53+ return GetTaskDescriptor (info.param ).display_name + " _" + Derived::PrintTestParam (test_param);
5554 }
5655
5756 protected:
@@ -71,36 +70,39 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
7170 }
7271
7372 void ExecuteTest (FuncTestParam<InType, OutType, TestType> test_param) {
74- const std::string &test_name = std::get< static_cast <std:: size_t >(GTestParamIndex:: kNameTest )> (test_param);
73+ const auto &descriptor = GetTaskDescriptor (test_param);
7574
76- ValidateTestName (test_name );
75+ ValidateTaskDescriptor (descriptor );
7776
78- const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest (test_name );
77+ const auto test_env_scope = ppc::util::test::MakePerTestEnvForCurrentGTest (descriptor. display_name );
7978
80- if (IsTestDisabled (test_name )) {
79+ if (IsTestDisabled (descriptor )) {
8180 GTEST_SKIP ();
8281 }
8382
84- if (ShouldSkipNonMpiTask (test_name )) {
83+ if (ShouldSkipNonMpiTask (descriptor )) {
8584 std::cerr << " kALL and kMPI tasks are not under mpirun\n " ;
8685 GTEST_SKIP ();
8786 }
8887
8988 InitializeAndRunTask (test_param);
9089 }
9190
92- void ValidateTestName (const std::string &test_name ) {
93- EXPECT_FALSE (test_name. contains ( " unknown " ) );
91+ void ValidateTaskDescriptor (const ppc::task::TaskDescriptor &descriptor ) {
92+ EXPECT_NE (descriptor. type , ppc::task::TypeOfTask:: kUnknown );
9493 }
9594
96- bool IsTestDisabled (const std::string &test_name ) {
97- return test_name. contains ( " disabled " ) ;
95+ bool IsTestDisabled (const ppc::task::TaskDescriptor &descriptor ) {
96+ return descriptor. status == ppc::task::StatusOfTask:: kDisabled ;
9897 }
9998
100- bool ShouldSkipNonMpiTask (const std::string &test_name) {
101- auto contains_substring = [&](const std::string &substring) { return test_name.contains (substring); };
99+ bool ShouldSkipNonMpiTask (const ppc::task::TaskDescriptor &descriptor) {
100+ return !ppc::util::IsUnderMpirun () && IsMpiTaskType (descriptor.type );
101+ }
102102
103- return !ppc::util::IsUnderMpirun () && (contains_substring (" _all" ) || contains_substring (" _mpi" ));
103+ bool ShouldSkipTestCase (const FuncTestParam<InType, OutType, TestType> &test_param) {
104+ const auto &descriptor = GetTaskDescriptor (test_param);
105+ return IsTestDisabled (descriptor) || ShouldSkipNonMpiTask (descriptor);
104106 }
105107
106108 // / @brief Initializes task instance and runs it through the full pipeline.
@@ -136,15 +138,14 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
136138
137139namespace detail {
138140
139- [[nodiscard]] inline std::string MakeFuncTestTaskTagPattern (std::string_view task_tag) {
140- std::string tag_pattern{task_tag};
141- if (!tag_pattern.starts_with (' _' )) {
142- tag_pattern.insert (0 , 1 , ' _' );
141+ [[nodiscard]] inline ppc::task::TypeOfTask TaskTypeFromFuncTestTag (std::string_view task_tag) {
142+ while (task_tag.starts_with (' _' )) {
143+ task_tag.remove_prefix (1 );
143144 }
144- if (!tag_pattern .ends_with (' _' )) {
145- tag_pattern. push_back ( ' _ ' );
145+ while (task_tag .ends_with (' _' )) {
146+ task_tag. remove_suffix ( 1 );
146147 }
147- return tag_pattern ;
148+ return ppc::task::TypeOfTaskFromString (task_tag) ;
148149}
149150
150151} // namespace detail
@@ -156,12 +157,12 @@ void RunTestCasesWithTag(const TestTasksList &test_tasks_list, std::string_view
156157 return ;
157158 }
158159
159- const std::string task_tag_pattern = detail::MakeFuncTestTaskTagPattern (task_tag);
160+ const ppc::task::TypeOfTask task_type = detail::TaskTypeFromFuncTestTag (task_tag);
160161 bool has_matching_task = false ;
161162 std::apply ([&](const auto &...test_params ) {
162163 auto run_if_tagged = [&](const auto &test_param) {
163- const std::string &test_name = std::get< static_cast <std:: size_t >(GTestParamIndex:: kNameTest )> (test_param);
164- if (test_name. contains (task_tag_pattern) ) {
164+ const auto &descriptor = GetTaskDescriptor (test_param);
165+ if (descriptor. type == task_type ) {
165166 has_matching_task = true ;
166167 std::invoke (run_test_case, test_param);
167168 }
@@ -185,11 +186,10 @@ auto ExpandToValues(const Tuple &t) {
185186template <typename Task, typename InType, typename SizesContainer, std::size_t ... Is>
186187auto GenTaskTuplesImpl (const SizesContainer &sizes, const std::string &settings_path,
187188 std::string_view settings_task_path, std::index_sequence<Is...> /* unused*/ ) {
188- return std::make_tuple (
189- std::make_tuple (ppc::task::TaskGetter<Task, InType>,
190- std::string (GetNamespace<Task>()) + " _" +
191- ppc::task::GetStringTaskType (Task::GetStaticTypeOfTask (), settings_path, settings_task_path),
192- std::get<Is>(sizes))...);
189+ const auto descriptor =
190+ MakeTaskDescriptor (GetNamespace<Task>(), Task::GetStaticTypeOfTask (), settings_path, settings_task_path);
191+ return std::make_tuple (std::make_tuple (ppc::task::TaskGetter<Task, InType>, descriptor.display_name ,
192+ std::get<Is>(sizes), descriptor)...);
193193}
194194
195195template <typename Task, typename InType, typename SizesContainer>
0 commit comments