Skip to content

Commit 04dcd1e

Browse files
committed
test:Added OVEP unittest for ep_context feature
1 parent e354009 commit 04dcd1e

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

cmake/onnxruntime_unittests.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,13 @@ if(onnxruntime_USE_AZURE)
769769
list(APPEND onnxruntime_test_providers_libs onnxruntime_providers_azure)
770770
endif()
771771

772+
if (onnxruntime_USE_OPENVINO)
773+
list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/openvino/*)
774+
list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_openvino)
775+
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_openvino)
776+
list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_shared)
777+
endif()
778+
772779
file(GLOB onnxruntime_test_framework_src CONFIGURE_DEPENDS
773780
${onnxruntime_test_framework_src_patterns}
774781
)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
#include <filesystem>
5+
#include <string>
6+
7+
#include "core/framework/provider_options.h"
8+
#include "core/framework/tensor_shape.h"
9+
#include "core/framework/float16.h"
10+
11+
#include "test/util/include/test_utils.h"
12+
#include "test/util/include/test/test_environment.h"
13+
#include "test/util/include/default_providers.h"
14+
15+
#include "core/session/onnxruntime_cxx_api.h"
16+
#include "core/session/onnxruntime_session_options_config_keys.h"
17+
#include "core/session/inference_session.h"
18+
#include "core/graph/model_saving_options.h"
19+
20+
#include "test/optimizer/qdq_test_utils.h"
21+
22+
#include "gtest/gtest.h"
23+
#include "gmock/gmock.h"
24+
25+
using namespace ONNX_NAMESPACE;
26+
using namespace onnxruntime::logging;
27+
28+
29+
extern std::unique_ptr<Ort::Env> ort_env;
30+
31+
class OVEPEPContextTests : public ::testing::Test {
32+
33+
34+
};
35+
36+
namespace onnxruntime {
37+
namespace test {
38+
39+
40+
// Test if folder path given to ep_context_file_path throws an error
41+
TEST_F(OVEPEPContextTests, OVEPEPContextFolderPath) {
42+
43+
Ort::SessionOptions sessionOptions;
44+
std::unordered_map<std::string, std::string> ov_options;
45+
ov_options["device_type"] = "NPU";
46+
47+
48+
const std::unordered_map<std::string, int> domain_to_version = {{"", 13}, {kMSDomain, 1}};
49+
50+
auto& logging_manager = DefaultLoggingManager();
51+
logging_manager.SetDefaultLoggerSeverity(logging::Severity::kERROR);
52+
53+
onnxruntime::Model model("OVEP_Test_Model", false, ModelMetaData(), PathString(),
54+
IOnnxRuntimeOpSchemaRegistryList(), domain_to_version, {},
55+
logging_manager.DefaultLogger());
56+
57+
ASSERT_STATUS_OK(model.MainGraph().Resolve());
58+
59+
// Serialize the model to a string.
60+
std::string model_data;
61+
model.ToProto().SerializeToString(&model_data);
62+
63+
const auto model_data_span = AsByteSpan(model_data.data(), model_data.size());
64+
65+
const std::string ep_context_file_path = "./ep_context_folder_path/";
66+
67+
68+
sessionOptions.AddConfigEntry(kOrtSessionOptionEpContextEnable, "1");
69+
sessionOptions.AddConfigEntry(kOrtSessionOptionEpContextFilePath,ep_context_file_path.c_str());
70+
sessionOptions.AppendExecutionProvider_OpenVINO_V2(ov_options);
71+
72+
73+
try {
74+
Ort::Session session(*ort_env, model_data_span.data(), model_data_span.size(), sessionOptions);
75+
FAIL(); // Should not get here!
76+
} catch (const Ort::Exception& excpt) {
77+
ASSERT_EQ(excpt.GetOrtErrorCode(), ORT_INVALID_ARGUMENT);
78+
ASSERT_THAT(excpt.what(), testing::HasSubstr("context_file_path should not point to a folder."));
79+
}
80+
81+
}
82+
83+
84+
} // namespace test
85+
} // namespace onnxruntime

0 commit comments

Comments
 (0)