Skip to content

Commit

Permalink
Eliminate reader tests (openvinotoolkit#13409)
Browse files Browse the repository at this point in the history
* remove reader tests #1

* remove reader tests #2

* remove reader tests #3

* remove reader tests #4

* Add clone_with_new_inputs to visitor tests

* fixes
  • Loading branch information
olpipi authored Oct 27, 2022
1 parent ee93ddc commit ad1c824
Show file tree
Hide file tree
Showing 233 changed files with 2,303 additions and 29,501 deletions.
4 changes: 4 additions & 0 deletions src/core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ set(SRC
visitors/dimension.cpp
visitors/user_op.cpp
visitors/value_map.cpp
visitors/op/abs.cpp
visitors/op/acos.cpp
visitors/op/acosh.cpp
visitors/op/adaptive_avg_pool.cpp
Expand All @@ -288,6 +289,7 @@ set(SRC
visitors/op/bucketize.cpp
visitors/op/ceiling.cpp
visitors/op/clamp.cpp
visitors/op/concat.cpp
visitors/op/constant.cpp
visitors/op/convert.cpp
visitors/op/convert_color_i420.cpp
Expand Down Expand Up @@ -380,6 +382,7 @@ set(SRC
visitors/op/proposal.cpp
visitors/op/psroi_pooling.cpp
visitors/op/random_uniform.cpp
visitors/op/range.cpp
visitors/op/rdft.cpp
visitors/op/read_value.cpp
visitors/op/reduce_l1.cpp
Expand Down Expand Up @@ -430,6 +433,7 @@ set(SRC
visitors/op/tan.cpp
visitors/op/tanh.cpp
visitors/op/tensor_iterator.cpp
visitors/op/tile.cpp
visitors/op/topk.cpp
visitors/op/transpose.cpp
visitors/op/unsqueeze.cpp
Expand Down
9 changes: 9 additions & 0 deletions src/core/tests/visitors/op/abs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "unary_ops.hpp"

using Type = ::testing::Types<UnaryOperatorType<ngraph::op::Abs, ngraph::element::f32>>;

INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, UnaryOperatorTypeName);
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/adaptive_avg_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, adaptive_avg_pool_op) {
const auto out_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {4, 3});

const auto adaptive_pool = make_shared<opset8::AdaptiveAvgPool>(A, out_shape);
NodeBuilder builder(adaptive_pool);
NodeBuilder builder(adaptive_pool, {A, out_shape});

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/adaptive_max_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, adaptive_max_pool_op) {
const auto out_shape = op::Constant::create<int64_t>(element::i64, Shape{2}, {4, 3});

const auto adaptive_pool = make_shared<opset8::AdaptiveMaxPool>(A, out_shape);
NodeBuilder builder(adaptive_pool);
NodeBuilder builder(adaptive_pool, {A, out_shape});
auto g_adaptive_pool = ov::as_type_ptr<opset8::AdaptiveMaxPool>(builder.create());

const auto expected_attr_count = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(attributes, assign_v3_op) {
const string variable_id = "v0";
const auto read_value = make_shared<opset3::ReadValue>(in, variable_id);
const auto assign = make_shared<opset3::Assign>(read_value, variable_id);
NodeBuilder builder(assign);
NodeBuilder builder(assign, {read_value});

// attribute count
const auto expected_attr_count = 1;
Expand All @@ -33,7 +33,7 @@ TEST(attributes, assign_v6_op) {
const auto variable = std::make_shared<Variable>(VariableInfo{PartialShape::dynamic(), element::dynamic, "v0"});
const auto read_value = make_shared<opset6::ReadValue>(in, variable);
const auto assign = make_shared<opset6::Assign>(read_value, variable);
NodeBuilder builder(assign);
NodeBuilder builder(assign, {read_value});

// attribute count
const auto expected_attr_count = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/avg_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(attributes, avg_pool_op) {
auto avg_pool =
make_shared<opset1::AvgPool>(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad);

NodeBuilder builder(avg_pool);
NodeBuilder builder(avg_pool, {data});
auto g_avg_pool = ov::as_type_ptr<opset1::AvgPool>(builder.create());

EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides());
Expand All @@ -54,7 +54,7 @@ TEST(attributes, avg_pool_v8_op) {

const auto avg_pool =
make_shared<opset8::AvgPool>(data, strides, pads_begin, pads_end, kernel, exclude_pad, rounding_mode, auto_pad);
NodeBuilder builder(avg_pool);
NodeBuilder builder(avg_pool, {data});
auto g_avg_pool = ov::as_type_ptr<opset8::AvgPool>(builder.create());

EXPECT_EQ(g_avg_pool->get_strides(), avg_pool->get_strides());
Expand Down
36 changes: 23 additions & 13 deletions src/core/tests/visitors/op/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,44 @@ using namespace ngraph;
using ngraph::test::NodeBuilder;
using ngraph::test::ValueMap;

template <class T>
class BatchNormAttrTest : public ::testing::Test {};

TYPED_TEST_SUITE_P(BatchNormAttrTest);

TYPED_TEST_P(BatchNormAttrTest, batch_norm_inference_op) {
TEST(attributes, batch_norm_inference_op_v5) {
PartialShape in_shape{1, 10};
PartialShape ch_shape{in_shape[1]};
element::Type et = element::f32;
double epsilon = 0.001;

NodeBuilder::get_ops().register_factory<TypeParam>();
NodeBuilder::get_ops().register_factory<op::v5::BatchNormInference>();
auto data_batch = make_shared<op::Parameter>(et, in_shape);
auto gamma = make_shared<op::Parameter>(et, ch_shape);
auto beta = make_shared<op::Parameter>(et, ch_shape);
auto mean = make_shared<op::Parameter>(et, ch_shape);
auto var = make_shared<op::Parameter>(et, ch_shape);
auto batch_norm = make_shared<TypeParam>(data_batch, gamma, beta, mean, var, epsilon);
auto batch_norm = make_shared<op::v5::BatchNormInference>(data_batch, gamma, beta, mean, var, epsilon);

const auto expected_attr_count = 1;
NodeBuilder builder(batch_norm);
NodeBuilder builder(batch_norm, {data_batch, gamma, beta, mean, var});
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
auto g_batch_norm = ov::as_type_ptr<TypeParam>(builder.create());
auto g_batch_norm = ov::as_type_ptr<op::v5::BatchNormInference>(builder.create());
EXPECT_EQ(g_batch_norm->get_eps_value(), batch_norm->get_eps_value());
}

REGISTER_TYPED_TEST_SUITE_P(BatchNormAttrTest, batch_norm_inference_op);
TEST(attributes, batch_norm_inference_op_v0) {
PartialShape in_shape{1, 10};
PartialShape ch_shape{in_shape[1]};
element::Type et = element::f32;
double epsilon = 0.001;

using Types = ::testing::Types<op::v0::BatchNormInference, op::v5::BatchNormInference>;
NodeBuilder::get_ops().register_factory<op::v0::BatchNormInference>();
auto data_batch = make_shared<op::Parameter>(et, in_shape);
auto gamma = make_shared<op::Parameter>(et, ch_shape);
auto beta = make_shared<op::Parameter>(et, ch_shape);
auto mean = make_shared<op::Parameter>(et, ch_shape);
auto var = make_shared<op::Parameter>(et, ch_shape);
auto batch_norm = make_shared<op::v0::BatchNormInference>(data_batch, gamma, beta, mean, var, epsilon);

INSTANTIATE_TYPED_TEST_SUITE_P(attributes, BatchNormAttrTest, Types);
const auto expected_attr_count = 1;
NodeBuilder builder(batch_norm, {gamma, beta, data_batch, mean, var});
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
auto g_batch_norm = ov::as_type_ptr<op::v0::BatchNormInference>(builder.create());
EXPECT_EQ(g_batch_norm->get_eps_value(), batch_norm->get_eps_value());
}
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/batch_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TEST(attributes, batch_to_space_op) {
auto crops_end = make_shared<op::Constant>(element::i64, Shape{2}, vector<int64_t>{0, 0});
auto batch2space = make_shared<op::v1::BatchToSpace>(data, block_shape, crops_begin, crops_end);

NodeBuilder builder(batch2space);
NodeBuilder builder(batch2space, {data});
const auto expected_attr_count = 0;

EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/binary_convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(attributes, bin_convolution) {
mode,
pad_value,
auto_pad);
NodeBuilder builder(conv);
NodeBuilder builder(conv, {data_batch, filters});
auto g_convolution = ov::as_type_ptr<op::v1::BinaryConvolution>(builder.create());

// attribute count
Expand Down
24 changes: 22 additions & 2 deletions src/core/tests/visitors/op/binary_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,32 @@ TYPED_TEST_P(BinaryOperatorVisitor, Auto_Broadcast)
auto auto_broadcast = ngraph::op::AutoBroadcastType::NUMPY;

const auto op_func = std::make_shared<OP_Type>(A, B, auto_broadcast);
ngraph::test::NodeBuilder builder(op_func);
ngraph::test::NodeBuilder builder(op_func, {A, B});
const auto g_op_func = ngraph::as_type_ptr<OP_Type>(builder.create());

const auto expected_attr_count = 1;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
EXPECT_EQ(op_func->get_autob(), g_op_func->get_autob());
}

REGISTER_TYPED_TEST_SUITE_P(BinaryOperatorVisitor, Auto_Broadcast);
TYPED_TEST_P(BinaryOperatorVisitor, No_Broadcast)
{
using OP_Type = typename TypeParam::op_type;
const ngraph::element::Type_t element_type = TypeParam::element_type;

ngraph::test::NodeBuilder::get_ops().register_factory<OP_Type>();
const auto A =
std::make_shared<ngraph::op::Parameter>(element_type, ngraph::PartialShape{1, 2, 3});
const auto B =
std::make_shared<ngraph::op::Parameter>(element_type, ngraph::PartialShape{1, 2, 3});

const auto op_func = std::make_shared<OP_Type>(A, B);
ngraph::test::NodeBuilder builder(op_func, {A, B});
const auto g_op_func = ngraph::as_type_ptr<OP_Type>(builder.create());

const auto expected_attr_count = 1;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
EXPECT_EQ(op_func->get_autob(), g_op_func->get_autob());
}

REGISTER_TYPED_TEST_SUITE_P(BinaryOperatorVisitor, Auto_Broadcast, No_Broadcast);
32 changes: 29 additions & 3 deletions src/core/tests/visitors/op/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,49 @@
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/opsets/opset1.hpp"
#include "ngraph/opsets/opset3.hpp"
#include "ngraph/opsets/opset4.hpp"
#include "ngraph/opsets/opset5.hpp"
#include "util/visitor.hpp"

using namespace std;
using namespace ngraph;
using ngraph::test::NodeBuilder;
using ngraph::test::ValueMap;

TEST(attributes, broadcast_v1) {
NodeBuilder::get_ops().register_factory<opset1::Broadcast>();
const auto arg = make_shared<op::Parameter>(element::i64, Shape{1, 3, 1});
const auto shape = make_shared<op::Parameter>(element::i64, Shape{3});
const auto axes_mapping = make_shared<op::Parameter>(element::i64, Shape{3});
const auto broadcast_spec = ov::op::AutoBroadcastType::NONE;

const auto broadcast_v3 = make_shared<op::v1::Broadcast>(arg, shape, axes_mapping, broadcast_spec);
NodeBuilder builder(broadcast_v3, {arg, shape, axes_mapping});
auto g_broadcast_v3 = ov::as_type_ptr<opset1::Broadcast>(builder.create());

EXPECT_EQ(g_broadcast_v3->get_broadcast_spec().m_type, broadcast_spec);
}

TEST(attributes, broadcast_v3) {
NodeBuilder::get_ops().register_factory<opset3::Broadcast>();
const auto arg = make_shared<op::Parameter>(element::i64, Shape{1, 3, 1});
const auto shape = make_shared<op::Parameter>(element::i64, Shape{3});
const auto broadcast_spec = op::BroadcastType::BIDIRECTIONAL;

const auto broadcast_v3 = make_shared<op::v3::Broadcast>(arg, shape, broadcast_spec);
NodeBuilder builder(broadcast_v3);
NodeBuilder builder(broadcast_v3, {arg, shape});
auto g_broadcast_v3 = ov::as_type_ptr<opset3::Broadcast>(builder.create());

EXPECT_EQ(g_broadcast_v3->get_broadcast_spec(), broadcast_spec);
}

TEST(attributes, broadcast_v3_explicit) {
NodeBuilder::get_ops().register_factory<opset3::Broadcast>();
const auto arg = make_shared<op::Parameter>(element::i64, Shape{1, 3, 1});
const auto shape = make_shared<op::Parameter>(element::i64, Shape{3});
const auto axes_mapping = make_shared<op::Parameter>(element::i64, Shape{3});
const auto broadcast_spec = op::BroadcastType::EXPLICIT;

const auto broadcast_v3 = make_shared<op::v3::Broadcast>(arg, shape, axes_mapping, broadcast_spec);
NodeBuilder builder(broadcast_v3, {arg, shape, axes_mapping});
auto g_broadcast_v3 = ov::as_type_ptr<opset3::Broadcast>(builder.create());

EXPECT_EQ(g_broadcast_v3->get_broadcast_spec(), broadcast_spec);
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/visitors/op/bucketize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(attributes, bucketize_v3_op_default_attributes) {
auto data = make_shared<op::Parameter>(element::f32, Shape{2, 3, 4});
auto buckets = make_shared<op::Parameter>(element::f32, Shape{5});
auto bucketize = make_shared<opset3::Bucketize>(data, buckets);
NodeBuilder builder(bucketize);
NodeBuilder builder(bucketize, {data, buckets});

auto g_bucketize = ov::as_type_ptr<opset3::Bucketize>(builder.create());

Expand All @@ -37,7 +37,7 @@ TEST(attributes, bucketize_v3_op_custom_attributes) {
bool with_right_bound = false;

auto bucketize = make_shared<opset3::Bucketize>(data, buckets, output_type, with_right_bound);
NodeBuilder builder(bucketize);
NodeBuilder builder(bucketize, {data, buckets});

auto g_bucketize = ov::as_type_ptr<opset3::Bucketize>(builder.create());

Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST(attributes, clamp_op) {
double max = 5.6;

const auto clamp = make_shared<opset1::Clamp>(data, min, max);
NodeBuilder builder(clamp);
NodeBuilder builder(clamp, {data});
auto g_clamp = ov::as_type_ptr<opset1::Clamp>(builder.create());

const auto expected_attr_count = 2;
Expand Down
28 changes: 28 additions & 0 deletions src/core/tests/visitors/op/concat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2018-2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/opsets/opset1.hpp"
#include "util/visitor.hpp"

using namespace std;
using namespace ngraph;
using ngraph::test::NodeBuilder;
using ngraph::test::ValueMap;

TEST(attributes, concat_op) {
NodeBuilder::get_ops().register_factory<opset1::Concat>();
auto input1 = make_shared<op::Parameter>(element::i64, Shape{1, 2, 3});
auto input2 = make_shared<op::Parameter>(element::i64, Shape{1, 2, 3});
auto input3 = make_shared<op::Parameter>(element::i64, Shape{1, 2, 3});
int64_t axis = 2;

auto concat = make_shared<opset1::Concat>(ov::NodeVector{input1, input2, input3}, axis);
NodeBuilder builder(concat, {input1, input2, input3});
auto g_concat = ov::as_type_ptr<opset1::Concat>(builder.create());

EXPECT_EQ(g_concat->get_axis(), concat->get_axis());
}
2 changes: 1 addition & 1 deletion src/core/tests/visitors/op/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST(attributes, convert_op_v0) {
const element::Type destination_type = element::Type_t::i32;

const auto convert = std::make_shared<Convert>(data, destination_type);
NodeBuilder builder(convert);
NodeBuilder builder(convert, {data});

// attribute count
const auto expected_attr_count = 1;
Expand Down
16 changes: 12 additions & 4 deletions src/core/tests/visitors/op/convert_color_i420.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ TEST(attributes, convert_color_i420_rgb) {
NodeBuilder::get_ops().register_factory<op::v8::I420toRGB>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::I420toRGB>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -26,7 +28,9 @@ TEST(attributes, convert_color_i420_bgr) {
NodeBuilder::get_ops().register_factory<op::v8::I420toBGR>();
auto data = make_shared<op::v0::Parameter>(element::u8, Shape{3, 720, 640, 1});
auto convert_color = make_shared<op::v8::I420toBGR>(data);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -37,7 +41,9 @@ TEST(attributes, convert_color_i420_rgb_3planes) {
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto data3 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto convert_color = make_shared<op::v8::I420toRGB>(data1, data2, data3);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2, data3});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Expand All @@ -48,7 +54,9 @@ TEST(attributes, convert_color_i420_bgr_3planes) {
auto data2 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto data3 = make_shared<op::v0::Parameter>(element::u8, Shape{3, 240, 320, 1});
auto convert_color = make_shared<op::v8::I420toBGR>(data1, data2, data3);
NodeBuilder builder(convert_color);
NodeBuilder builder(convert_color, {data1, data2, data3});
EXPECT_NO_THROW(auto g_concat = ov::as_type_ptr<op::v8::I420toRGB>(builder.create()));

const auto expected_attr_count = 0;
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
}
Loading

0 comments on commit ad1c824

Please sign in to comment.