Skip to content

Commit 9c67dad

Browse files
authored
Clean up clang-tidy suppressions (#784)
Get rid of many tests (especially, googletest) related diagnostics suppressions, address all newly appeared clang-tidy remarks
1 parent a79f256 commit 9c67dad

16 files changed

Lines changed: 155 additions & 209 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Checks: >
4646
-readability-magic-numbers
4747
4848
HeaderFilterRegex: '.*/(modules|tasks)/.*'
49+
ExcludeHeaderFilterRegex: '.*/3rdparty/.*'
4950

5051
CheckOptions:
5152
- key: readability-identifier-naming.ClassCase
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
InheritParentConfig: true
22

3-
Checks: >
4-
-modernize-loop-convert,
5-
-cppcoreguidelines-avoid-goto,
6-
-cppcoreguidelines-avoid-non-const-global-variables,
7-
-misc-override-with-different-visibility,
8-
-misc-use-anonymous-namespace,
9-
-modernize-use-std-print,
10-
-modernize-type-traits
11-
123
CheckOptions:
134
- key: readability-function-cognitive-complexity.Threshold
145
value: 50 # Relaxed for tests

modules/performance/tests/perf_tests.cpp

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <gtest/gtest.h>
22

3+
#include <array>
34
#include <chrono>
45
#include <cstdint>
56
#include <filesystem>
67
#include <fstream>
78
#include <libenvpp/detail/environment.hpp>
89
#include <memory>
9-
#include <ostream>
1010
#include <stdexcept>
11+
#include <string>
1112
#include <string_view>
1213
#include <thread>
1314
#include <vector>
@@ -29,6 +30,7 @@ class TestPerfTask : public ppc::task::Task<InType, OutType> {
2930
this->GetInput() = in;
3031
}
3132

33+
protected:
3234
bool ValidationImpl() override {
3335
return !this->GetInput().empty();
3436
}
@@ -55,6 +57,7 @@ class FakePerfTask : public TestPerfTask<InType, OutType> {
5557
public:
5658
explicit FakePerfTask(const InType &in) : TestPerfTask<InType, OutType>(in) {}
5759

60+
protected:
5861
bool RunImpl() override {
5962
std::this_thread::sleep_for(std::chrono::seconds(11));
6063
return TestPerfTask<InType, OutType>::RunImpl();
@@ -163,38 +166,31 @@ TEST(PerfTests, CheckPerfTaskFloat) {
163166

164167
struct ParamTestCase {
165168
PerfResults::TypeOfRunning input;
166-
std::string expected_output;
167-
friend void PrintTo(const ParamTestCase &param, std::ostream *os) {
168-
*os << "{ input = " << static_cast<int>(param.input) << ", expected = " << param.expected_output << " }";
169-
}
169+
std::string_view expected_output;
170170
};
171171

172-
class GetStringParamNameParamTest : public ::testing::TestWithParam<ParamTestCase> {};
172+
namespace {
173173

174-
TEST_P(GetStringParamNameParamTest, ReturnsExpectedString) {
175-
const auto &param = GetParam();
176-
EXPECT_EQ(GetStringParamName(param.input), param.expected_output);
177-
}
174+
constexpr std::array<ParamTestCase, 3> kParamTestCases = {
175+
{{.input = PerfResults::TypeOfRunning::kTaskRun, .expected_output = "task_run"},
176+
{.input = PerfResults::TypeOfRunning::kPipeline, .expected_output = "pipeline"},
177+
{.input = PerfResults::TypeOfRunning::kNone, .expected_output = "none"}}};
178+
179+
} // namespace
178180

179-
INSTANTIATE_TEST_SUITE_P(ParamTests, GetStringParamNameParamTest,
180-
::testing::Values(ParamTestCase{PerfResults::TypeOfRunning::kTaskRun, "task_run"},
181-
ParamTestCase{PerfResults::TypeOfRunning::kPipeline, "pipeline"},
182-
ParamTestCase{PerfResults::TypeOfRunning::kNone, "none"}),
183-
[](const ::testing::TestParamInfo<ParamTestCase> &info) {
184-
return info.param.expected_output;
185-
});
181+
TEST(GetStringParamNameParamTest, ReturnsExpectedString) {
182+
for (const auto &param : kParamTestCases) {
183+
EXPECT_EQ(GetStringParamName(param.input), std::string(param.expected_output));
184+
}
185+
}
186186

187187
struct TaskTypeTestCase {
188188
TypeOfTask type;
189-
std::string expected;
190-
std::string label;
191-
friend void PrintTo(const TaskTypeTestCase &param, std::ostream *os) {
192-
*os << "{ type = " << static_cast<int>(param.type) << ", expected = " << param.expected
193-
<< ", label = " << param.label << " }";
194-
}
189+
std::string_view expected;
190+
std::string_view label;
195191
};
196192

197-
class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase> {
193+
class GetStringTaskTypeTest : public ::testing::Test {
198194
protected:
199195
std::string temp_path;
200196

@@ -211,18 +207,23 @@ class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase>
211207
}
212208
};
213209

214-
TEST_P(GetStringTaskTypeTest, ReturnsExpectedString) {
215-
const auto &param = GetParam();
216-
EXPECT_EQ(GetStringTaskType(param.type, temp_path), param.expected) << "Failed on: " << param.label;
217-
}
210+
namespace {
211+
212+
constexpr std::array<TaskTypeTestCase, 6> kTaskTypeTestCases = {
213+
{{.type = TypeOfTask::kALL, .expected = "all_ALL", .label = "kALL"},
214+
{.type = TypeOfTask::kSTL, .expected = "stl_STL", .label = "kSTL"},
215+
{.type = TypeOfTask::kOMP, .expected = "omp_OMP", .label = "kOMP"},
216+
{.type = TypeOfTask::kMPI, .expected = "mpi_MPI", .label = "kMPI"},
217+
{.type = TypeOfTask::kTBB, .expected = "tbb_TBB", .label = "kTBB"},
218+
{.type = TypeOfTask::kSEQ, .expected = "seq_SEQ", .label = "kSEQ"}}};
218219

219-
INSTANTIATE_TEST_SUITE_P(AllTypeCases, GetStringTaskTypeTest,
220-
::testing::Values(TaskTypeTestCase{TypeOfTask::kALL, "all_ALL", "kALL"},
221-
TaskTypeTestCase{TypeOfTask::kSTL, "stl_STL", "kSTL"},
222-
TaskTypeTestCase{TypeOfTask::kOMP, "omp_OMP", "kOMP"},
223-
TaskTypeTestCase{TypeOfTask::kMPI, "mpi_MPI", "kMPI"},
224-
TaskTypeTestCase{TypeOfTask::kTBB, "tbb_TBB", "kTBB"},
225-
TaskTypeTestCase{TypeOfTask::kSEQ, "seq_SEQ", "kSEQ"}));
220+
} // namespace
221+
222+
TEST_F(GetStringTaskTypeTest, ReturnsExpectedString) {
223+
for (const auto &param : kTaskTypeTestCases) {
224+
EXPECT_EQ(GetStringTaskType(param.type, temp_path), std::string(param.expected)) << "Failed on: " << param.label;
225+
}
226+
}
226227

227228
TEST(GetStringTaskTypeStandaloneTest, ThrowsIfFileMissing) {
228229
std::string missing_path = "non_existent_settings.json";
@@ -284,6 +285,8 @@ TEST(GetStringTaskStatusTest, HandlesEnabledAndDisabled) {
284285
class DummyTask : public Task<int, int> {
285286
public:
286287
using Task::Task;
288+
289+
protected:
287290
bool ValidationImpl() override {
288291
return true;
289292
}
@@ -321,25 +324,16 @@ struct Type {};
321324
class Another {};
322325
} // namespace my
323326

324-
template <typename T>
325-
class GetNamespaceTest : public ::testing::Test {};
326-
327-
using TestTypes = ::testing::Types<my::nested::Type, my::Another, int>;
328-
329-
TYPED_TEST_SUITE(GetNamespaceTest, TestTypes);
327+
TEST(GetNamespaceTest, ExtractsNestedNamespaceCorrectly) {
328+
EXPECT_EQ(ppc::util::GetNamespace<my::nested::Type>(), "ppc::performance::my::nested");
329+
}
330330

331-
TYPED_TEST(GetNamespaceTest, ExtractsNamespaceCorrectly) {
332-
std::string k_ns = ppc::util::GetNamespace<TypeParam>();
331+
TEST(GetNamespaceTest, ExtractsParentNamespaceCorrectly) {
332+
EXPECT_EQ(ppc::util::GetNamespace<my::Another>(), "ppc::performance::my");
333+
}
333334

334-
if constexpr (std::is_same_v<TypeParam, my::nested::Type>) {
335-
EXPECT_EQ(k_ns, "ppc::performance::my::nested");
336-
} else if constexpr (std::is_same_v<TypeParam, my::Another>) {
337-
EXPECT_EQ(k_ns, "ppc::performance::my");
338-
} else if constexpr (std::is_same_v<TypeParam, int>) {
339-
EXPECT_EQ(k_ns, "");
340-
} else {
341-
FAIL() << "Unhandled type in test";
342-
}
335+
TEST(GetNamespaceTest, ReturnsEmptyStringForGlobalNamespaceType) {
336+
EXPECT_EQ(ppc::util::GetNamespace<int>(), "");
343337
}
344338

345339
TEST(PerfTest, PipelineRunAndTaskRun) {
@@ -385,6 +379,7 @@ TEST(PerfTest, GetStringParamNameTest) {
385379
TEST(TaskTest, DestructorInvalidPipelineOrderTerminatesPartialPipeline) {
386380
{
387381
struct BadTask : Task<int, int> {
382+
protected:
388383
bool ValidationImpl() override {
389384
return true;
390385
}

modules/task/tests/.clang-tidy

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
InheritParentConfig: true
22

3-
Checks: >
4-
-modernize-loop-convert,
5-
-cppcoreguidelines-avoid-goto,
6-
-cppcoreguidelines-avoid-non-const-global-variables,
7-
-misc-override-with-different-visibility,
8-
-misc-use-anonymous-namespace,
9-
-modernize-use-std-print,
10-
-modernize-type-traits
11-
123
CheckOptions:
134
- key: readability-function-cognitive-complexity.Threshold
145
value: 100 # Relaxed for tests
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
InheritParentConfig: true
22

3-
Checks: >
4-
-modernize-loop-convert,
5-
-cppcoreguidelines-avoid-goto,
6-
-cppcoreguidelines-avoid-non-const-global-variables,
7-
-misc-override-with-different-visibility,
8-
-misc-use-anonymous-namespace,
9-
-modernize-use-std-print,
10-
-modernize-type-traits
11-
123
CheckOptions:
134
- key: readability-function-cognitive-complexity.Threshold
145
value: 50 # Relaxed for tests

tasks/example_processes/tests/functional/main.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ class NesterovARunFuncTestsProcesses : public ppc::util::BaseRunFuncTests<InType
2727
}
2828

2929
protected:
30-
void SetUp() override {
30+
void RunTestCase(const ppc::util::FuncTestParam<InType, OutType, TestType> &test_param) {
31+
const std::string &test_name =
32+
std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kNameTest)>(test_param);
33+
if (IsTestDisabled(test_name) || ShouldSkipNonMpiTask(test_name)) {
34+
return;
35+
}
36+
37+
SetInputData();
38+
ExecuteTest(test_param);
39+
}
40+
41+
void SetInputData() {
3142
int width = -1;
3243
int height = -1;
3344
int channels = -1;
@@ -47,7 +58,6 @@ class NesterovARunFuncTestsProcesses : public ppc::util::BaseRunFuncTests<InType
4758
}
4859
}
4960

50-
TestType params = std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kTestParams)>(GetParam());
5161
input_data_ = width - height + std::min(std::accumulate(img.begin(), img.end(), 0), channels);
5262
}
5363

@@ -65,22 +75,16 @@ class NesterovARunFuncTestsProcesses : public ppc::util::BaseRunFuncTests<InType
6575

6676
namespace {
6777

68-
TEST_P(NesterovARunFuncTestsProcesses, MatmulFromPic) {
69-
ExecuteTest(GetParam());
70-
}
71-
7278
const std::array<TestType, 3> kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")};
7379

7480
const auto kTestTasksList =
7581
std::tuple_cat(ppc::util::AddFuncTask<NesterovATestTaskMPI, InType>(kTestParam, PPC_SETTINGS_example_processes),
7682
ppc::util::AddFuncTask<NesterovATestTaskSEQ, InType>(kTestParam, PPC_SETTINGS_example_processes));
7783

78-
const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
79-
80-
const auto kPerfTestName = NesterovARunFuncTestsProcesses::PrintFuncTestName<NesterovARunFuncTestsProcesses>;
81-
82-
INSTANTIATE_TEST_SUITE_P(PicMatrixTests, NesterovARunFuncTestsProcesses, kGtestValues, kPerfTestName);
83-
8484
} // namespace
8585

86+
TEST_F(NesterovARunFuncTestsProcesses, MatmulFromPic) {
87+
std::apply([this](const auto &...test_params) { (RunTestCase(test_params), ...); }, kTestTasksList);
88+
}
89+
8690
} // namespace nesterov_a_test_task_processes
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <gtest/gtest.h>
22

3+
#include <tuple>
4+
35
#include "example_processes/common/include/common.hpp"
46
#include "example_processes/mpi/include/ops_mpi.hpp"
57
#include "example_processes/seq/include/ops_seq.hpp"
@@ -8,9 +10,7 @@
810
namespace nesterov_a_test_task_processes {
911

1012
class ExampleRunPerfTestProcesses : public ppc::util::BaseRunPerfTests<InType, OutType> {
11-
const int kCount_ = 100;
12-
InType input_data_{};
13-
13+
protected:
1414
void SetUp() override {
1515
input_data_ = kCount_;
1616
}
@@ -22,23 +22,21 @@ class ExampleRunPerfTestProcesses : public ppc::util::BaseRunPerfTests<InType, O
2222
InType GetTestInputData() final {
2323
return input_data_;
2424
}
25-
};
2625

27-
TEST_P(ExampleRunPerfTestProcesses, RunPerfModes) {
28-
ExecuteTest(GetParam());
29-
}
26+
private:
27+
const int kCount_ = 100;
28+
InType input_data_{};
29+
};
3030

3131
namespace {
3232

3333
const auto kAllPerfTasks =
3434
ppc::util::MakeAllPerfTasks<InType, NesterovATestTaskMPI, NesterovATestTaskSEQ>(PPC_SETTINGS_example_processes);
3535

36-
const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks);
37-
38-
const auto kPerfTestName = ExampleRunPerfTestProcesses::CustomPerfTestName;
39-
40-
INSTANTIATE_TEST_SUITE_P(RunModeTests, ExampleRunPerfTestProcesses, kGtestValues, kPerfTestName);
41-
4236
} // namespace
4337

38+
TEST_F(ExampleRunPerfTestProcesses, RunPerfModes) {
39+
std::apply([this](const auto &...test_params) { (ExecuteTest(test_params), ...); }, kAllPerfTasks);
40+
}
41+
4442
} // namespace nesterov_a_test_task_processes
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
InheritParentConfig: true
22

3-
Checks: >
4-
-modernize-loop-convert,
5-
-cppcoreguidelines-avoid-goto,
6-
-cppcoreguidelines-avoid-non-const-global-variables,
7-
-misc-override-with-different-visibility,
8-
-misc-use-anonymous-namespace,
9-
-modernize-use-std-print,
10-
-modernize-type-traits
11-
123
CheckOptions:
134
- key: readability-function-cognitive-complexity.Threshold
145
value: 50 # Relaxed for tests

0 commit comments

Comments
 (0)