|
5 | 5 | #include <gtest/gtest.h> |
6 | 6 |
|
7 | 7 | #include <fstream> |
| 8 | +#include <regex> |
8 | 9 |
|
9 | 10 | #include "common_test_utils/common_utils.hpp" |
10 | 11 | #include "common_test_utils/file_utils.hpp" |
11 | 12 | #include "common_test_utils/test_common.hpp" |
| 13 | +#include "openvino/op/add.hpp" |
12 | 14 | #include "openvino/pass/serialize.hpp" |
| 15 | +#include "openvino/util/common_util.hpp" |
13 | 16 | #include "openvino/util/file_util.hpp" |
14 | 17 | #include "read_ir.hpp" |
15 | 18 |
|
| 19 | +namespace ov::test { |
| 20 | + |
16 | 21 | class DeterministicityCommon { |
17 | 22 | protected: |
18 | 23 | std::string m_out_xml_path_1{}; |
@@ -350,3 +355,41 @@ TEST_P(SerializationDeterministicityInputOutputTest, FromOvModelBybPath) { |
350 | 355 | INSTANTIATE_TEST_SUITE_P(DeterministicityInputOutput, |
351 | 356 | SerializationDeterministicityInputOutputTest, |
352 | 357 | ::testing::Values(ov::pass::Serialize::Version::IR_V10, ov::pass::Serialize::Version::IR_V11)); |
| 358 | + |
| 359 | +TEST(DeterministicityInputOutput, LayerIdOrder) { |
| 360 | + const auto p1 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1}); |
| 361 | + const auto p2 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1}); |
| 362 | + const auto p3 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1}); |
| 363 | + const auto a1 = std::make_shared<op::v1::Add>(p3, p2); |
| 364 | + const auto a2 = std::make_shared<op::v1::Add>(p2, p1); |
| 365 | + const auto a3 = std::make_shared<op::v1::Add>(p1, p3); |
| 366 | + const auto r1 = std::make_shared<op::v0::Result>(a1); |
| 367 | + const auto r2 = std::make_shared<op::v0::Result>(a2); |
| 368 | + const auto r3 = std::make_shared<op::v0::Result>(a3); |
| 369 | + const auto model = std::make_shared<Model>(ResultVector{r3, r1, r2}, ParameterVector{p2, p3, p1}, "param_order"); |
| 370 | + p2->set_friendly_name("expect id 0"); |
| 371 | + p3->set_friendly_name("expect id 1"); |
| 372 | + p1->set_friendly_name("expect id 2"); |
| 373 | + r3->set_friendly_name("expect id 6"); |
| 374 | + r1->set_friendly_name("expect id 7"); |
| 375 | + r2->set_friendly_name("expect id 8"); |
| 376 | + |
| 377 | + std::stringstream xml, bin; |
| 378 | + ov::pass::Serialize(xml, bin).run_on_model(model); |
| 379 | + |
| 380 | + // order matters |
| 381 | + constexpr auto expected_layer_id = util::make_array(R"(<layer id="0" name="expect id 0" type="Parameter")", |
| 382 | + R"(<layer id="1" name="expect id 1" type="Parameter")", |
| 383 | + R"(<layer id="2" name="expect id 2" type="Parameter")", |
| 384 | + R"(<layer id="6" name="expect id 6" type="Result")", |
| 385 | + R"(<layer id="7" name="expect id 7" type="Result")", |
| 386 | + R"(<layer id="8" name="expect id 8" type="Result")"); |
| 387 | + const std::string xml_str = xml.str(); |
| 388 | + std::string::size_type pos = 0; |
| 389 | + for (const auto& n : expected_layer_id) { |
| 390 | + const auto found = xml_str.find(n, pos); |
| 391 | + ASSERT_NE(found, std::string::npos) << "Not found: " << n; |
| 392 | + pos = found; |
| 393 | + } |
| 394 | +} |
| 395 | +} // namespace ov::test |
0 commit comments