Skip to content

Commit

Permalink
[CAPI] fix some CI test issues (openvinotoolkit#21834)
Browse files Browse the repository at this point in the history
* [CAPI] fix some CI test issue

    1. Fix failure in case of gpu plugin is not available cases
    2. Solve incorrect test behavior of ov_core_set_and_get_property_bool_invalid
    3. Remove legacy structure from CAPI 2.0 code

* Fix clang format issue

---------

Co-authored-by: Pavel Durandin <[email protected]>
  • Loading branch information
riverlijunjie and p-durandin authored Dec 26, 2023
1 parent c59fc5f commit 77157d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 41 deletions.
32 changes: 6 additions & 26 deletions src/bindings/c/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,21 @@
#include <streambuf>
#include <string>

#include "details/ie_exception.hpp"
#include "openvino/core/except.hpp"
#include "openvino/openvino.hpp"

#define CATCH_IE_EXCEPTION(StatusCode, ExceptionType) \
catch (const InferenceEngine::ExceptionType& ex) { \
dup_last_err_msg(ex.what()); \
return ov_status_e::StatusCode; \
}

#define CATCH_OV_EXCEPTION(StatusCode, ExceptionType) \
catch (const ov::ExceptionType& ex) { \
dup_last_err_msg(ex.what()); \
return ov_status_e::StatusCode; \
}

#define CATCH_OV_EXCEPTIONS \
CATCH_OV_EXCEPTION(NOT_IMPLEMENTED, NotImplemented) \
CATCH_OV_EXCEPTION(GENERAL_ERROR, Exception) \
CATCH_IE_EXCEPTION(GENERAL_ERROR, GeneralError) \
CATCH_IE_EXCEPTION(NOT_IMPLEMENTED, NotImplemented) \
CATCH_IE_EXCEPTION(NETWORK_NOT_LOADED, NetworkNotLoaded) \
CATCH_IE_EXCEPTION(PARAMETER_MISMATCH, ParameterMismatch) \
CATCH_IE_EXCEPTION(NOT_FOUND, NotFound) \
CATCH_IE_EXCEPTION(OUT_OF_BOUNDS, OutOfBounds) \
CATCH_IE_EXCEPTION(UNEXPECTED, Unexpected) \
CATCH_IE_EXCEPTION(REQUEST_BUSY, RequestBusy) \
CATCH_IE_EXCEPTION(RESULT_NOT_READY, ResultNotReady) \
CATCH_IE_EXCEPTION(NOT_ALLOCATED, NotAllocated) \
CATCH_IE_EXCEPTION(INFER_NOT_STARTED, InferNotStarted) \
CATCH_IE_EXCEPTION(NETWORK_NOT_READ, NetworkNotRead) \
CATCH_IE_EXCEPTION(INFER_CANCELLED, InferCancelled) \
catch (...) { \
dup_last_err_msg("An unknown exception occurred"); \
return ov_status_e::UNKNOW_EXCEPTION; \
#define CATCH_OV_EXCEPTIONS \
CATCH_OV_EXCEPTION(NOT_IMPLEMENTED, NotImplemented) \
CATCH_OV_EXCEPTION(GENERAL_ERROR, Exception) \
catch (...) { \
dup_last_err_msg("An unknown exception occurred"); \
return ov_status_e::UNKNOW_EXCEPTION; \
}

#define GET_PROPERTY_FROM_ARGS_LIST \
Expand Down
10 changes: 4 additions & 6 deletions src/bindings/c/tests/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,16 @@ TEST_F(ov_core_test, ov_core_set_and_get_property_no_device) {
TEST_P(ov_core_test, ov_core_set_and_get_property_bool_invalid) {
auto device_name = GetParam();
ov_core_t* core = nullptr;
char* ret = nullptr;
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);

const char* key = ov_property_key_enable_profiling;
const char* enable = "TEST";
OV_EXPECT_OK(ov_core_set_property(core, device_name.c_str(), key, enable));

char* ret = nullptr;
OV_EXPECT_NOT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
EXPECT_STRNE(enable, ret);
OV_EXPECT_OK(ov_core_get_property(core, device_name.c_str(), key, &ret));
ov_free(ret);

const char* enable = "TEST";
OV_EXPECT_NOT_OK(ov_core_set_property(core, device_name.c_str(), key, enable));
ov_core_free(core);
}

Expand Down
21 changes: 12 additions & 9 deletions src/bindings/c/tests/ov_remote_context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ class ov_remote_context_ocl : public ov_capi_test_base {
OV_EXPECT_OK(ov_core_create(&core));
EXPECT_NE(nullptr, core);

OV_EXPECT_OK(ov_core_read_model(core, xml_file_name.c_str(), bin_file_name.c_str(), &model));
EXPECT_NE(nullptr, model);

// Check gpu plugin and hardware available.
bool gpu_device_available = false;
char* info = nullptr;
const char* key = ov_property_key_available_devices;
EXPECT_EQ(ov_core_get_property(core, "GPU", key, &info), ov_status_e::OK);
ASSERT_STRNE(info, nullptr);

if (strlen(info) == 0) {
ov_free(info);
GTEST_SKIP();
if (ov_core_get_property(core, "GPU", key, &info) == ov_status_e::OK) {
if (strlen(info) > 0) {
gpu_device_available = true;
}
}
ov_free(info);
if (!gpu_device_available) {
GTEST_SKIP();
}

OV_EXPECT_OK(ov_core_read_model(core, xml_file_name.c_str(), bin_file_name.c_str(), &model));
EXPECT_NE(nullptr, model);

const unsigned int refVendorID = 0x8086;
cl_uint n = 0;
Expand Down

0 comments on commit 77157d5

Please sign in to comment.