Skip to content

Commit 82f47c6

Browse files
committed
gtests: tidy: various fixes
1 parent 31a02a9 commit 82f47c6

9 files changed

+44
-47
lines changed

tests/gtests/dnnl_test_common.hpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ inline memory::dim right_padding(memory::dim i, memory::dim o, memory::dim k,
297297

298298
template <typename data_t>
299299
struct acc_t {
300-
typedef data_t type;
300+
using type = data_t;
301301
};
302302
template <>
303303
struct acc_t<int8_t> {
304-
typedef int type;
304+
using type = int;
305305
};
306306
template <>
307307
struct acc_t<uint8_t> {
308-
typedef int type;
308+
using type = int;
309309
};
310310

311311
// Smart pointer for map/unmap operations with unique_ptr semantics
@@ -314,9 +314,8 @@ struct mapped_ptr_t {
314314
using nonconst_type = typename std::remove_cv<T>::type;
315315

316316
mapped_ptr_t(std::nullptr_t) : mem_(nullptr), ptr_(nullptr) {}
317-
mapped_ptr_t(const memory *mem) : mem_(mem) {
318-
ptr_ = mem->map_data<nonconst_type>();
319-
}
317+
mapped_ptr_t(const memory *mem)
318+
: mem_(mem), ptr_(mem->map_data<nonconst_type>()) {}
320319
mapped_ptr_t(mapped_ptr_t &&other) : mem_(other.mem_), ptr_(other.ptr_) {
321320
other.mem_ = nullptr;
322321
other.ptr_ = nullptr;
@@ -368,12 +367,12 @@ void check_zero_tail(int set_zero_flag, const memory &src) {
368367

369368
for (memory::dim i = 0; i < nelems; ++i) {
370369
memory::dim off = 0;
371-
bool flag = 0;
370+
bool flag = false;
372371
for (int j = 0; j < ndims; ++j) {
373372
off += idx[j] * str[j];
374-
if (idx[j] >= dims[ndims - j - 1]) flag = 1;
373+
if (idx[j] >= dims[ndims - j - 1]) flag = true;
375374
}
376-
if (flag == 1) {
375+
if (flag == true) {
377376
memory::dim blk_off = mdw.off_l(off, true);
378377
if (set_zero_flag) {
379378
src_data[blk_off] = 0.0;
@@ -391,8 +390,8 @@ void check_zero_tail(int set_zero_flag, const memory &src) {
391390
}
392391
}
393392

394-
inline memory::desc create_md(memory::dims dims, memory::data_type data_type,
395-
memory::format_tag fmt_tag) {
393+
inline memory::desc create_md(const memory::dims &dims,
394+
memory::data_type data_type, memory::format_tag fmt_tag) {
396395
return memory::desc(dims, data_type, fmt_tag);
397396
}
398397

@@ -566,7 +565,8 @@ inline dnnl_status_t get_conv_impl_status(
566565
const_dnnl_primitive_desc_t pd, const char *match_str) {
567566
const char *conv_str = query_impl_info(pd);
568567

569-
if (strstr(conv_str, match_str) != NULL) return dnnl_status_t::dnnl_success;
568+
if (strstr(conv_str, match_str) != nullptr)
569+
return dnnl_status_t::dnnl_success;
570570
return dnnl_status_t::dnnl_unimplemented;
571571
};
572572

@@ -608,7 +608,7 @@ struct test_convolution_attr_t {
608608

609609
bool is_def() const { return policy != NONE; }
610610

611-
scale_t(float s, policy_t p = NONE) : scale(s) { policy = p; }
611+
scale_t(float s, policy_t p = NONE) : policy(p), scale(s) {}
612612

613613
policy_t policy;
614614
float scale;
@@ -632,7 +632,7 @@ struct test_convolution_attr_t {
632632

633633
test_convolution_attr_t(
634634
float s, scale_t::policy_t p = scale_t::policy_t::NONE)
635-
: src_scale(s, p), wei_scale(s, p), dst_scale(s, p), dnnl_attr() {}
635+
: src_scale(s, p), wei_scale(s, p), dst_scale(s, p) {}
636636

637637
test_convolution_attr_t() : test_convolution_attr_t(1.f) {}
638638

@@ -785,7 +785,7 @@ static char *test_malloc(size_t size) {
785785
#else
786786
int rc = ::posix_memalign(&ptr, align, padded_size);
787787
#endif /* _WIN32 */
788-
return rc == 0 ? (char *)ptr + TEST_MALLOC_OFFSET : 0;
788+
return rc == 0 ? (char *)ptr + TEST_MALLOC_OFFSET : nullptr;
789789
}
790790

791791
static void test_free(char *ptr) {
@@ -801,11 +801,11 @@ static void test_free(char *ptr) {
801801
//NOLINTNEXTLINE(readability-identifier-naming)
802802
class test_memory {
803803
public:
804-
test_memory(const memory::desc &d, const dnnl::engine &e) {
804+
test_memory(const memory::desc &d, const dnnl::engine &e)
805+
: size_(d.get_size()) {
805806
bool is_cpu_native = (e.get_kind() == dnnl::engine::kind::cpu)
806807
&& DNNL_CPU_RUNTIME != DNNL_RUNTIME_SYCL;
807808

808-
size_ = d.get_size();
809809
if (is_cpu_native) {
810810
data_.reset(test_malloc(size_), test_free);
811811
mem_ = test::make_memory(d, e, data_.get());
@@ -1091,10 +1091,9 @@ void test_bwd_pd_allow_empty(const pd_t &pd, const hint_pd_t &hint,
10911091

10921092
// Note: requires a valid primitive descriptor!
10931093
template <typename pd_t, typename hint_pd_t, typename... prim_params_t>
1094-
void test_bwd_pd_constructors(const pd_t &pd, const hint_pd_t &hint,
1094+
void test_bwd_pd_constructors(const pd_t &pd, const hint_pd_t &hint_pd,
10951095
const allows_attr_t &aa, const prim_params_t &...prim_params) {
10961096
auto test_pd = pd_t();
1097-
auto hint_pd = hint;
10981097
auto eng = pd.get_engine();
10991098
// ctor from C pd, should not throw
11001099
ASSERT_NO_THROW(test_pd = pd_t(pd.get()));
@@ -1112,7 +1111,7 @@ void test_bwd_pd_constructors(const pd_t &pd, const hint_pd_t &hint,
11121111
test_bwd_pd_allow_empty<pd_t>(test_pd, hint_pd, prim_params...);
11131112
}
11141113

1115-
inline dnnl::stream make_stream(dnnl::engine engine,
1114+
inline dnnl::stream make_stream(const dnnl::engine &engine,
11161115
dnnl::stream::flags flags = dnnl::stream::flags::default_flags) {
11171116
#if DNNL_CPU_THREADING_RUNTIME == DNNL_RUNTIME_THREADPOOL
11181117
if (engine.get_kind() == dnnl::engine::kind::cpu)

tests/gtests/dnnl_test_macros.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2019-2023 Intel Corporation
2+
* Copyright 2019-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -124,6 +124,7 @@
124124
} \
125125
void Testing()
126126

127+
//NOLINTBEGIN(bugprone-macro-parentheses)
127128
// Wrapper around TEST from gtest, intended to catch exceptions thrown by a unit
128129
// test.
129130
#define HANDLE_EXCEPTIONS_FOR_TEST(test_fixture, test_name) \
@@ -193,4 +194,6 @@
193194
TEST_P(test_fixture, test_name)
194195
#endif
195196

197+
//NOLINTEND(bugprone-macro-parentheses)
198+
196199
#endif

tests/gtests/test_convolution_backward_data_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ template <typename data_t_diff_dst, typename data_t_wei, typename data_t_acc,
8989
class convolution_backward_data_test_t
9090
: public ::testing::TestWithParam<test_convolution_params_t> {
9191
protected:
92-
virtual void SetUp() {
92+
void SetUp() override {
9393
auto p = ::testing::TestWithParam<
9494
test_convolution_params_t>::GetParam();
9595

tests/gtests/test_convolution_backward_weights_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ template <typename data_t_src, typename data_t_diff_dst,
121121
class convolution_backward_weights_test_t
122122
: public ::testing::TestWithParam<test_convolution_params_t> {
123123
protected:
124-
virtual void SetUp() {
124+
void SetUp() override {
125125
auto p = ::testing::TestWithParam<
126126
test_convolution_params_t>::GetParam();
127127

tests/gtests/test_convolution_eltwise_forward_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ template <typename data_t_src, typename data_t_wei, typename data_t_acc,
114114
class convolution_eltwise_test_t
115115
: public ::testing::TestWithParam<test_convolution_eltwise_params_t> {
116116
protected:
117-
virtual void SetUp() {
117+
void SetUp() override {
118118
memory::data_type data_type_src = data_traits_t<data_t_src>::data_type;
119119
memory::data_type data_type_dst = data_traits_t<data_t_dst>::data_type;
120120
memory::data_type data_type_wei = data_traits_t<data_t_wei>::data_type;

tests/gtests/test_convolution_forward_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ template <typename data_t_src, typename data_t_wei, typename data_t_acc,
115115
class convolution_forward_test_t
116116
: public ::testing::TestWithParam<test_convolution_params_t> {
117117
protected:
118-
virtual void SetUp() {
118+
void SetUp() override {
119119
memory::data_type data_type_src = data_traits_t<data_t_src>::data_type;
120120
memory::data_type data_type_dst = data_traits_t<data_t_dst>::data_type;
121121
memory::data_type data_type_wei = data_traits_t<data_t_wei>::data_type;

tests/gtests/test_gemm_common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ struct run_test_gemm_t {
590590
template <typename a_dt, typename b_dt, typename c_dt>
591591
class gemm_test_common_t : public ::testing::TestWithParam<test_params_t> {
592592
protected:
593-
virtual void SetUp() {
593+
void SetUp() override {
594594
const auto &p = ::testing::TestWithParam<test_params_t>::GetParam();
595595

596596
SKIP_IF(get_test_engine_kind() == engine::kind::gpu,

tests/gtests/test_gemm_data_preparation.hpp

+14-19
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ static constexpr int N_test_max = 53;
5353
* a surjective function from {0, ..., dim-1} onto {0, ..., dim_test-1}.
5454
*/
5555
struct mapper_t {
56-
mapper_t(const mapper_t &other)
57-
: dim_(other.dim_)
58-
, dim_test_(other.dim_test_)
59-
, gen_(other.gen_)
60-
, gen_start_(other.gen_start_)
61-
, mapper_(other.mapper_) {}
56+
mapper_t(const mapper_t &other) = default;
6257

6358
mapper_t(mapper_t &&other) noexcept
6459
: dim_(other.dim_)
@@ -260,19 +255,19 @@ void prepare_data_for_gemm_testing(
260255
size_t sizeA, sizeB, sizeC;
261256
get_matrix_size(p, sizeA, sizeB, sizeC);
262257

263-
gemm_data.a_mem.reset(
264-
new test_memory(get_matrix_md<a_dt>(sizeA, p.off.a), eng));
265-
gemm_data.b_mem.reset(
266-
new test_memory(get_matrix_md<b_dt>(sizeB, p.off.b), eng));
267-
gemm_data.c_mem.reset(
268-
new test_memory(get_matrix_md<c_dt>(sizeC, p.off.c), eng));
269-
gemm_data.c_ref_mem.reset(
270-
new test_memory(get_matrix_md<c_dt>(sizeC, p.off.c), eng));
271-
gemm_data.oc_mem.reset(
272-
new test_memory(get_matrix_md<c_dt>(p.size_oc(), p.off.co), eng));
273-
274-
gemm_data.mapper_m.reset(new mapper_t(p.M, M_test_max));
275-
gemm_data.mapper_n.reset(new mapper_t(p.N, N_test_max));
258+
gemm_data.a_mem = std::make_shared<test_memory>(
259+
get_matrix_md<a_dt>(sizeA, p.off.a), eng);
260+
gemm_data.b_mem = std::make_shared<test_memory>(
261+
get_matrix_md<b_dt>(sizeB, p.off.b), eng);
262+
gemm_data.c_mem = std::make_shared<test_memory>(
263+
get_matrix_md<c_dt>(sizeC, p.off.c), eng);
264+
gemm_data.c_ref_mem = std::make_shared<test_memory>(
265+
get_matrix_md<c_dt>(sizeC, p.off.c), eng);
266+
gemm_data.oc_mem = std::make_shared<test_memory>(
267+
get_matrix_md<c_dt>(p.size_oc(), p.off.co), eng);
268+
269+
gemm_data.mapper_m = std::make_shared<mapper_t>(p.M, M_test_max);
270+
gemm_data.mapper_n = std::make_shared<mapper_t>(p.N, N_test_max);
276271

277272
fill_matrices<a_dt, b_dt, c_dt>(p, *gemm_data.mapper_m, *gemm_data.mapper_n,
278273
*gemm_data.a_mem, *gemm_data.b_mem, *gemm_data.c_mem,

tests/gtests/test_rnn_forward.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class rnn_forward_test_t : public ::testing::TestWithParam<test_rnn_params_t> {
104104
return memory::desc();
105105
}
106106

107-
void testExecArgQueries(typename T::primitive_desc pd) {
107+
void testExecArgQueries(const typename T::primitive_desc &pd) {
108108
ASSERT_TRUE(pd.query_md(query::exec_arg_md, DNNL_ARG_WEIGHTS_LAYER)
109109
== pd.weights_layer_desc());
110110
ASSERT_TRUE(pd.query_md(query::exec_arg_md, DNNL_ARG_WEIGHTS_ITER)
@@ -131,7 +131,7 @@ class rnn_forward_test_t : public ::testing::TestWithParam<test_rnn_params_t> {
131131
== queryDstIterC(pd));
132132
};
133133

134-
void test_primitive_param_queries(typename T::primitive_desc pd) {
134+
void test_primitive_param_queries(const typename T::primitive_desc &pd) {
135135
auto p = ::testing::TestWithParam<test_rnn_params_t>::GetParam();
136136

137137
dnnl::algorithm expected_cell_kind = algorithm::undef;

0 commit comments

Comments
 (0)