From 77157d559ece1d21381d5f5e0da145e898c0cb65 Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 26 Dec 2023 12:17:39 +0800 Subject: [PATCH] [CAPI] fix some CI test issues (#21834) * [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 --- src/bindings/c/src/common.h | 32 ++++--------------- src/bindings/c/tests/ov_core_test.cpp | 10 +++--- .../c/tests/ov_remote_context_test.cpp | 21 ++++++------ 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/bindings/c/src/common.h b/src/bindings/c/src/common.h index 50784981d1c430..2a338d0f0d6da0 100644 --- a/src/bindings/c/src/common.h +++ b/src/bindings/c/src/common.h @@ -10,41 +10,21 @@ #include #include -#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 \ diff --git a/src/bindings/c/tests/ov_core_test.cpp b/src/bindings/c/tests/ov_core_test.cpp index 6579c9268418fe..6d4dbcd28773d4 100644 --- a/src/bindings/c/tests/ov_core_test.cpp +++ b/src/bindings/c/tests/ov_core_test.cpp @@ -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); } diff --git a/src/bindings/c/tests/ov_remote_context_test.cpp b/src/bindings/c/tests/ov_remote_context_test.cpp index 95795aa2464dba..d0d278acef94aa 100644 --- a/src/bindings/c/tests/ov_remote_context_test.cpp +++ b/src/bindings/c/tests/ov_remote_context_test.cpp @@ -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;