Skip to content

Commit

Permalink
add C unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
xadupre committed Sep 11, 2023
1 parent bc09e72 commit ed41b1d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions onnxruntime/test/shared_lib/test_inference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,44 @@ TEST(CApiTest, test_custom_op_get_const_input) {
}
#endif

#if (!defined(ORT_MINIMAL_BUILD)) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS)
TEST(CApiTest, test_custom_op_local_function) {
const auto* model_path = TSTR("testdata/custom_op_local_function/custom_ops_type_inference_fails_0.onnx");

Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault);
std::vector<Ort::Value> ort_inputs;
std::vector<const char*> input_names;

// input 0 (float type)
input_names.emplace_back("input1");
std::vector<float> input_0_data = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
std::vector<int64_t> input_0_dims = {2, 2, 2};
ort_inputs.emplace_back(
Ort::Value::CreateTensor<float>(info, const_cast<float*>(input_0_data.data()),
input_0_data.size(), input_0_dims.data(), input_0_dims.size()));
const char* output_name = "Y";

const ORTCHAR_T* lib_name;
#if defined(_WIN32)
lib_name = ORT_TSTR("custom_op_local_library.dll");
#elif defined(__APPLE__)
lib_name = ORT_TSTR("libcustom_op_local_library.dylib");
#else
lib_name = ORT_TSTR("./libcustom_op_local_library.so");
#endif

Ort::SessionOptions session_opts;

session_opts.RegisterCustomOpsLibrary(lib_name);

Ort::Session session(*ort_env, model_path, session_opts);
auto default_allocator = std::make_unique<MockedOrtAllocator>();

session.Run(Ort::RunOptions{}, input_names.data(), ort_inputs.data(), ort_inputs.size(),
&output_name, 1);
}
#endif

#if defined(USE_OPENVINO) && (!defined(ORT_MINIMAL_BUILD) || defined(ORT_MINIMAL_BUILD_CUSTOM_OPS))
TEST(CApiTest, test_custom_op_openvino_wrapper_library) {
// Tests a custom operator that wraps an OpenVINO MNIST model (.xml and .bin files serialized into node attributes).
Expand Down

0 comments on commit ed41b1d

Please sign in to comment.