|
34 | 34 | #include "openvino/runtime/iremote_context.hpp" |
35 | 35 | #include "openvino/runtime/properties.hpp" |
36 | 36 | #include "openvino/runtime/shared_buffer.hpp" |
| 37 | +#include "openvino/util/ov_version.hpp" |
37 | 38 | #include "unit_test_utils/mocks/openvino/runtime/mock_iasync_infer_request.hpp" |
38 | 39 | #include "unit_test_utils/mocks/openvino/runtime/mock_icompiled_model.hpp" |
39 | 40 | #include "unit_test_utils/mocks/openvino/runtime/mock_iplugin.hpp" |
@@ -1806,7 +1807,7 @@ TEST_P(CachingTest, TestCacheFileCorrupted) { |
1806 | 1807 | } |
1807 | 1808 | } |
1808 | 1809 |
|
1809 | | -TEST_P(CachingTest, TestCacheFileOldVersion) { |
| 1810 | +TEST_P(CachingTest, TestCacheFileIncompartible) { |
1810 | 1811 | EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber()); |
1811 | 1812 | EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber()); |
1812 | 1813 | EXPECT_CALL(*mockPlugin, get_property(ov::device::architecture.name(), _)).Times(AnyNumber()); |
@@ -1841,10 +1842,12 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { |
1841 | 1842 | content = ostr.str(); |
1842 | 1843 | } |
1843 | 1844 | std::string buildNum = ov::get_openvino_version().buildNumber; |
1844 | | - std::string zeroBuild(buildNum.size(), '0'); |
| 1845 | + auto build_version = ov::util::Version(buildNum); |
| 1846 | + // Update build number to make it incompatible, e.g. if it was 2026.0.0.123, make it 2026.0.0.124 |
| 1847 | + build_version.build += 1; |
1845 | 1848 | auto index = content.find(buildNum); |
1846 | 1849 | if (index != std::string::npos) { |
1847 | | - content.replace(index, buildNum.size(), zeroBuild); |
| 1850 | + content.replace(index, buildNum.size(), build_version.to_string()); |
1848 | 1851 | } else { |
1849 | 1852 | return; // skip test |
1850 | 1853 | } |
@@ -1895,6 +1898,80 @@ TEST_P(CachingTest, TestCacheFileOldVersion) { |
1895 | 1898 | } |
1896 | 1899 | } |
1897 | 1900 |
|
| 1901 | +TEST_P(CachingTest, TestCacheFileOldVersion) { |
| 1902 | + EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber()); |
| 1903 | + EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber()); |
| 1904 | + EXPECT_CALL(*mockPlugin, get_property(ov::device::architecture.name(), _)).Times(AnyNumber()); |
| 1905 | + EXPECT_CALL(*mockPlugin, get_property(ov::internal::supported_properties.name(), _)).Times(AnyNumber()); |
| 1906 | + EXPECT_CALL(*mockPlugin, get_property(ov::internal::caching_properties.name(), _)).Times(AnyNumber()); |
| 1907 | + EXPECT_CALL(*mockPlugin, get_property(ov::device::capabilities.name(), _)).Times(AnyNumber()); |
| 1908 | + |
| 1909 | + { |
| 1910 | + EXPECT_CALL(*mockPlugin, compile_model(_, _, _)).Times(m_remoteContext ? 1 : 0); |
| 1911 | + EXPECT_CALL(*mockPlugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)) |
| 1912 | + .Times(!m_remoteContext ? 1 : 0); |
| 1913 | + EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _, _)).Times(0); |
| 1914 | + EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _)).Times(0); |
| 1915 | + EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _, _)).Times(0); |
| 1916 | + EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _)).Times(0); |
| 1917 | + m_post_mock_net_callbacks.emplace_back([&](MockICompiledModelImpl& net) { |
| 1918 | + EXPECT_CALL(net, export_model(_)).Times(1); |
| 1919 | + }); |
| 1920 | + testLoad([&](ov::Core& core) { |
| 1921 | + EXPECT_NO_THROW(core.set_property(ov::cache_dir(m_cacheDir))); |
| 1922 | + EXPECT_NO_THROW(m_testFunction(core)); |
| 1923 | + }); |
| 1924 | + } |
| 1925 | + { |
| 1926 | + auto blobs = ov::test::utils::listFilesWithExt(m_cacheDir, "blob"); |
| 1927 | + for (const auto& fileName : blobs) { |
| 1928 | + std::string content; |
| 1929 | + { |
| 1930 | + std::ifstream inp(fileName, std::ios_base::binary); |
| 1931 | + std::ostringstream ostr; |
| 1932 | + ostr << inp.rdbuf(); |
| 1933 | + content = ostr.str(); |
| 1934 | + } |
| 1935 | + std::string buildNum = ov::get_openvino_version().buildNumber; |
| 1936 | + auto build_version = ov::util::Version(buildNum); |
| 1937 | + build_version.build -= 1; |
| 1938 | + auto index = content.find(buildNum); |
| 1939 | + if (index != std::string::npos) { |
| 1940 | + content.replace(index, buildNum.size(), build_version.to_string()); |
| 1941 | + } else { |
| 1942 | + return; // skip test |
| 1943 | + } |
| 1944 | + |
| 1945 | + std::filesystem::permissions(fileName, |
| 1946 | + std::filesystem::perms::owner_write, |
| 1947 | + std::filesystem::perm_options::add); |
| 1948 | + std::ofstream out(fileName, std::ios_base::binary); |
| 1949 | + out.write(content.c_str(), static_cast<std::streamsize>(content.size())); |
| 1950 | + out.close(); |
| 1951 | + std::filesystem::permissions(fileName, |
| 1952 | + std::filesystem::perms::owner_write, |
| 1953 | + std::filesystem::perm_options::remove); |
| 1954 | + } |
| 1955 | + } |
| 1956 | + m_post_mock_net_callbacks.pop_back(); |
| 1957 | + { // Step 2. Cache file version is older. So cache is valid from Core perspective. |
| 1958 | + EXPECT_CALL(*mockPlugin, compile_model(_, _, _)).Times(0); |
| 1959 | + EXPECT_CALL(*mockPlugin, compile_model(A<const std::shared_ptr<const ov::Model>&>(), _)).Times(0); |
| 1960 | + EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _, _)).Times(m_remoteContext ? 1 : 0); |
| 1961 | + EXPECT_CALL(*mockPlugin, import_model(A<std::istream&>(), _)).Times(!m_remoteContext ? 1 : 0); |
| 1962 | + EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _, _)).Times(0); |
| 1963 | + EXPECT_CALL(*mockPlugin, import_model(A<const ov::Tensor&>(), _)).Times(0); |
| 1964 | + m_post_mock_net_callbacks.emplace_back([&](MockICompiledModelImpl& net) { |
| 1965 | + EXPECT_CALL(net, export_model(_)).Times(1); |
| 1966 | + }); |
| 1967 | + testLoad([&](ov::Core& core) { |
| 1968 | + EXPECT_NO_THROW(core.set_property(ov::cache_dir(m_cacheDir))); |
| 1969 | + EXPECT_NO_THROW(m_testFunction(core)); |
| 1970 | + }); |
| 1971 | + } |
| 1972 | + m_post_mock_net_callbacks.pop_back(); |
| 1973 | +} |
| 1974 | + |
1898 | 1975 | TEST_P(CachingTest, TestCacheFileWithCompiledModelRuntimeProperties) { |
1899 | 1976 | EXPECT_CALL(*mockPlugin, get_property(ov::supported_properties.name(), _)).Times(AnyNumber()); |
1900 | 1977 | EXPECT_CALL(*mockPlugin, get_property(ov::device::capability::EXPORT_IMPORT, _)).Times(AnyNumber()); |
|
0 commit comments