Skip to content

Commit d3441ad

Browse files
committed
update file type and add comment
1 parent 585be9b commit d3441ad

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

src/core/tests/pass/serialization/serialize.cpp

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,10 @@ class UndefinedTypeDynamicTypeSerializationTests : public ::testing::Test {
789789
</net>
790790
)V0G0N";
791791

792-
std::string m_dynamic_type_out_xml_path;
793-
std::string m_dynamic_type_out_bin_path;
794-
std::string m_undefined_type_out_xml_path;
795-
std::string m_undefined_type_out_bin_path;
792+
std::filesystem::path m_dynamic_type_out_xml_path;
793+
std::filesystem::path m_dynamic_type_out_bin_path;
794+
std::filesystem::path m_undefined_type_out_xml_path;
795+
std::filesystem::path m_undefined_type_out_bin_path;
796796

797797
void SetUp() override {
798798
std::string filePrefix = ov::test::utils::generateTestFilePrefix();
@@ -803,15 +803,26 @@ class UndefinedTypeDynamicTypeSerializationTests : public ::testing::Test {
803803
}
804804

805805
void TearDown() override {
806-
std::remove(m_undefined_type_out_xml_path.c_str());
807-
std::remove(m_undefined_type_out_bin_path.c_str());
808-
std::remove(m_dynamic_type_out_xml_path.c_str());
809-
std::remove(m_dynamic_type_out_bin_path.c_str());
806+
if (std::filesystem::exists(m_undefined_type_out_xml_path)) {
807+
std::filesystem::remove(m_undefined_type_out_xml_path);
808+
}
809+
810+
if (std::filesystem::exists(m_undefined_type_out_bin_path)) {
811+
std::filesystem::remove(m_undefined_type_out_bin_path);
812+
}
813+
814+
if (std::filesystem::exists(m_dynamic_type_out_xml_path)) {
815+
std::filesystem::remove(m_dynamic_type_out_xml_path);
816+
}
817+
818+
if (std::filesystem::exists(m_dynamic_type_out_bin_path)) {
819+
std::filesystem::remove(m_dynamic_type_out_bin_path);
820+
}
810821
}
811822

812-
bool files_equal(const std::string& file_path1, const std::string& file_path2) {
813-
std::ifstream xml_dynamic(file_path1, std::ios::binary);
814-
std::ifstream xml_undefined(file_path2, std::ios::binary);
823+
bool files_equal(const std::filesystem::path& file_path1, const std::filesystem::path& file_path2) {
824+
std::ifstream xml_dynamic(file_path1.string(), std::ios::binary);
825+
std::ifstream xml_undefined(file_path2.string(), std::ios::binary);
815826

816827
if (!xml_dynamic.good() || !xml_undefined.good()) {
817828
return false;
@@ -825,18 +836,18 @@ class UndefinedTypeDynamicTypeSerializationTests : public ::testing::Test {
825836

826837
// check stringstream serialize
827838
TEST_F(UndefinedTypeDynamicTypeSerializationTests, compare_dynamic_type_undefined_type_serialization_stringstream) {
828-
std::stringstream dynamicTypeModelXmlStream, undefinedTypeModelXmlStream, dynamicTypeModelBinStream,
829-
undefinedTypeModelBinStream;
839+
std::stringstream dynamicXmlStream, undefinedXmlStream, dynamicBinStream,
840+
undefinedBinStream;
830841

831842
// Test whether the serialization results of the two models are the same
832843
auto dynamicTypeModel = ov::test::readModel(dynamic_type_ir);
833844
auto undefinedTypeModel = ov::test::readModel(undefined_type_ir);
834845

835846
// compile the serialized models with stringstream type
836-
ov::pass::Serialize(dynamicTypeModelXmlStream, dynamicTypeModelBinStream).run_on_model(dynamicTypeModel);
837-
ov::pass::Serialize(undefinedTypeModelXmlStream, undefinedTypeModelBinStream).run_on_model(undefinedTypeModel);
847+
ov::pass::Serialize(dynamicXmlStream, dynamicBinStream).run_on_model(dynamicTypeModel);
848+
ov::pass::Serialize(undefinedXmlStream, undefinedBinStream).run_on_model(undefinedTypeModel);
838849

839-
ASSERT_EQ(dynamicTypeModelXmlStream.str(), undefinedTypeModelXmlStream.str())
850+
ASSERT_EQ(dynamicXmlStream.str(), undefinedXmlStream.str())
840851
<< "Serialized XML streams are different: dynamic type vs undefined type";
841852
}
842853

src/plugins/intel_npu/tests/functional/behavior/compile_and_infer_different_element_type.hpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//
44

5-
#include <string>
5+
#include <common_test_utils/ov_tensor_utils.hpp>
66
#include <sstream>
7+
#include <string>
78
#include <vector>
89

9-
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
10-
#include <common_test_utils/ov_tensor_utils.hpp>
10+
#include "openvino/opsets/opset6.hpp"
1111
#include "openvino/pass/manager.hpp"
1212
#include "openvino/pass/serialize.hpp"
13-
#include "openvino/opsets/opset6.hpp"
13+
#include "shared_test_classes/base/ov_behavior_test_utils.hpp"
1414
namespace ov {
1515
namespace test {
1616
namespace behavior {
1717

18-
using InferRequestElementTypeParams = std::tuple<
19-
std::string, // Device name
20-
ov::AnyMap // Config
21-
>;
18+
using InferRequestElementTypeParams = std::tuple<std::string, // Device name
19+
ov::AnyMap // Config
20+
>;
2221

22+
// These tests are required by the NPU plugin to verify the compatibility of undefined type and dynamic type during
23+
// compilation and inference on different NPU drivers, hence they are kept here. Compared to test in serialize it
24+
// includes an additional comparison of inference results.
2325
class InferRequestElementTypeTests : public testing::WithParamInterface<InferRequestElementTypeParams>,
24-
public OVInferRequestTestBase {
25-
26+
public OVInferRequestTestBase {
2627
public:
2728
static std::string getTestCaseName(testing::TestParamInfo<InferRequestElementTypeParams> obj) {
2829
std::string target_device;
@@ -56,8 +57,8 @@ class InferRequestElementTypeTests : public testing::WithParamInterface<InferReq
5657
ov::AnyMap configuration;
5758
};
5859

59-
60-
bool InferRequestElementTypeTests::compareTensorOutputs(const ov::Tensor& dynamicInferenceOutput, const ov::Tensor& undefinedInferenceOutput) {
60+
bool InferRequestElementTypeTests::compareTensorOutputs(const ov::Tensor& dynamicInferenceOutput,
61+
const ov::Tensor& undefinedInferenceOutput) {
6162
const auto dynamicShape = dynamicInferenceOutput.get_shape();
6263
const auto undefinedShape = undefinedInferenceOutput.get_shape();
6364

@@ -83,7 +84,8 @@ bool InferRequestElementTypeTests::compareTensorOutputs(const ov::Tensor& dynami
8384
return true;
8485
}
8586

86-
// Test whether the serialization and inference results of the dynamic type model and the undefined type model are the same
87+
// Test whether the serialization and inference results of the dynamic type model and the undefined type model are the
88+
// same
8789
TEST_P(InferRequestElementTypeTests, CompareDynamicAndUndefinedTypeNetwork) {
8890
// Skip test according to plugin specific disabledTestPatterns() (if any)
8991
SKIP_IF_CURRENT_TEST_IS_DISABLED()
@@ -282,7 +284,8 @@ TEST_P(InferRequestElementTypeTests, CompareDynamicAndUndefinedTypeNetwork) {
282284
</net>
283285
)V0G0N";
284286

285-
std::stringstream dynamicTypeModelXmlStream, undefinedTypeModelXmlStream, dynamicTypeModelBinStream, undefinedTypeModelBinStream;
287+
std::stringstream dynamicTypeModelXmlStream, undefinedTypeModelXmlStream, dynamicTypeModelBinStream,
288+
undefinedTypeModelBinStream;
286289

287290
// Test whether the serialization results of the two models are the same
288291
auto dynamicTypeModel = ie->read_model(dynamicTypeModelXmlString, ov::Tensor());

0 commit comments

Comments
 (0)