[C API][Unite Test] Add more tests to achieve code coverage target (#13885)
* [C API][Unite Test] Add more unite test case for C API (functional level) Signed-off-by: xuejun <Xuejun.Zhai@intel.com> * [C API][Unite Test] remove unused function Signed-off-by: xuejun <Xuejun.Zhai@intel.com> * [C API][Unite Test] fix function code coverage issue Signed-off-by: xuejun <Xuejun.Zhai@intel.com> * [C API][TEST CASE] fix error Signed-off-by: xuejun <Xuejun.Zhai@intel.com> Signed-off-by: xuejun <Xuejun.Zhai@intel.com>
This commit is contained in:
1 parent
71c23489c6
commit
5f1ce082ea
5 files changed
+199
-3
No files matched your search
@@ -173,7 +173,7 @@ struct mem_stringbuf : std::streambuf {
|
||||
char* bptr(const_cast<char*>(buffer));
|
||||
setg(bptr, bptr, bptr + sz);
|
||||
}
|
||||
|
||||
|
||||
pos_type seekoff(off_type off,
|
||||
std::ios_base::seekdir dir,
|
||||
std::ios_base::openmode which = std::ios_base::in) override {
|
||||
@@ -209,5 +209,4 @@ struct mem_istream : virtual mem_stringbuf, std::istream {
|
||||
};
|
||||
|
||||
char* str_to_char_array(const std::string& str);
|
||||
ov_element_type_e find_ov_element_type_e(ov::element::Type type);
|
||||
ov::element::Type get_element_type(ov_element_type_e type);
|
||||
@@ -25,7 +25,7 @@ const std::map<ov_element_type_e, ov::element::Type> element_type_map = {
|
||||
{ov_element_type_e::U32, ov::element::u32},
|
||||
{ov_element_type_e::U64, ov::element::u64}};
|
||||
|
||||
ov_element_type_e find_ov_element_type_e(ov::element::Type type) {
|
||||
inline ov_element_type_e find_ov_element_type_e(ov::element::Type type) {
|
||||
for (auto iter = element_type_map.begin(); iter != element_type_map.end(); iter++) {
|
||||
if (iter->second == type) {
|
||||
return iter->first;
|
||||
|
||||
@@ -39,6 +39,8 @@ protected:
|
||||
output_tensor = nullptr;
|
||||
compiled_model = nullptr;
|
||||
infer_request = nullptr;
|
||||
input_const_port = nullptr;
|
||||
input_port = nullptr;
|
||||
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
EXPECT_NE(nullptr, core);
|
||||
@@ -46,6 +48,12 @@ protected:
|
||||
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
|
||||
EXPECT_NE(nullptr, model);
|
||||
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_const_port));
|
||||
EXPECT_NE(nullptr, input_const_port);
|
||||
|
||||
OV_EXPECT_OK(ov_model_input(model, &input_port));
|
||||
EXPECT_NE(nullptr, input_port);
|
||||
|
||||
ov_shape_t tensor_shape = {0, nullptr};
|
||||
ov_element_type_e tensor_type;
|
||||
get_tensor_info(model, true, &in_tensor_name, &tensor_shape, &tensor_type);
|
||||
@@ -64,6 +72,8 @@ protected:
|
||||
void TearDown() override {
|
||||
ov_tensor_free(input_tensor);
|
||||
ov_tensor_free(output_tensor);
|
||||
ov_output_const_port_free(input_const_port);
|
||||
ov_output_port_free(input_port);
|
||||
ov_free(in_tensor_name);
|
||||
ov_infer_request_free(infer_request);
|
||||
ov_compiled_model_free(compiled_model);
|
||||
@@ -79,6 +89,8 @@ public:
|
||||
char* in_tensor_name;
|
||||
ov_tensor_t* input_tensor;
|
||||
ov_tensor_t* output_tensor;
|
||||
ov_output_const_port_t* input_const_port;
|
||||
ov_output_port_t* input_port;
|
||||
static std::mutex m;
|
||||
static bool ready;
|
||||
static std::condition_variable condVar;
|
||||
@@ -195,6 +207,14 @@ TEST_P(ov_infer_request, set_input_tensor_by_index) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_input_tensor_by_index(infer_request, 0, input_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, set_tensor_by_port) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_tensor_by_port(infer_request, input_port, input_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, set_tensor_by_const_port) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_tensor_by_const_port(infer_request, input_const_port, input_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, set_input_tensor) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_input_tensor(infer_request, input_tensor));
|
||||
}
|
||||
@@ -226,6 +246,14 @@ TEST_P(ov_infer_request, get_input_tensor_by_index) {
|
||||
OV_EXPECT_OK(ov_infer_request_get_input_tensor_by_index(infer_request, 0, &output_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, get_tensor_by_const_port) {
|
||||
OV_EXPECT_OK(ov_infer_request_get_tensor_by_const_port(infer_request, input_const_port, &output_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, get_tensor_by_port) {
|
||||
OV_EXPECT_OK(ov_infer_request_get_tensor_by_port(infer_request, input_port, &output_tensor));
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, get_input_tensor) {
|
||||
OV_EXPECT_OK(ov_infer_request_get_input_tensor(infer_request, &output_tensor));
|
||||
}
|
||||
@@ -293,6 +321,19 @@ TEST_P(ov_infer_request, infer_async) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request, infer_async_wait_for) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_input_tensor_by_index(infer_request, 0, input_tensor));
|
||||
|
||||
OV_ASSERT_OK(ov_infer_request_start_async(infer_request));
|
||||
|
||||
if (!HasFatalFailure()) {
|
||||
OV_EXPECT_OK(ov_infer_request_wait_for(infer_request, 10));
|
||||
|
||||
OV_EXPECT_OK(ov_infer_request_get_output_tensor_by_index(infer_request, 0, &output_tensor));
|
||||
EXPECT_NE(nullptr, output_tensor);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(ov_infer_request_ppp, infer_async_ppp) {
|
||||
OV_EXPECT_OK(ov_infer_request_set_input_tensor_by_index(infer_request, 0, input_tensor));
|
||||
|
||||
|
||||
@@ -339,6 +339,138 @@ TEST(ov_model, ov_model_reshape_input_by_name) {
|
||||
ov_core_free(core);
|
||||
}
|
||||
|
||||
TEST(ov_model, ov_model_reshape) {
|
||||
ov_core_t* core = nullptr;
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
EXPECT_NE(nullptr, core);
|
||||
|
||||
ov_model_t* model = nullptr;
|
||||
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
|
||||
EXPECT_NE(nullptr, model);
|
||||
|
||||
ov_output_const_port_t* input_port_1 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_port_1));
|
||||
EXPECT_NE(nullptr, input_port_1);
|
||||
|
||||
char* tensor_name = nullptr;
|
||||
OV_EXPECT_OK(ov_port_get_any_name(input_port_1, &tensor_name));
|
||||
const char* const_tensor_name = tensor_name;
|
||||
|
||||
ov_shape_t shape = {0, nullptr};
|
||||
int64_t dims[4] = {1, 3, 896, 896};
|
||||
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
|
||||
|
||||
ov_partial_shape_t partial_shape;
|
||||
OV_EXPECT_OK(ov_shape_to_partial_shape(shape, &partial_shape));
|
||||
OV_EXPECT_OK(ov_model_reshape(model, &const_tensor_name, &partial_shape, 1));
|
||||
|
||||
ov_output_const_port_t* input_port_2 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_port_2));
|
||||
EXPECT_NE(nullptr, input_port_2);
|
||||
|
||||
EXPECT_NE(input_port_1, input_port_2);
|
||||
|
||||
ov_shape_free(&shape);
|
||||
ov_partial_shape_free(&partial_shape);
|
||||
ov_free(tensor_name);
|
||||
ov_output_const_port_free(input_port_1);
|
||||
ov_output_const_port_free(input_port_2);
|
||||
ov_model_free(model);
|
||||
ov_core_free(core);
|
||||
}
|
||||
|
||||
TEST(ov_model, ov_model_reshape_by_port_indexes) {
|
||||
ov_core_t* core = nullptr;
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
EXPECT_NE(nullptr, core);
|
||||
|
||||
ov_model_t* model = nullptr;
|
||||
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
|
||||
EXPECT_NE(nullptr, model);
|
||||
|
||||
size_t port_indexs[] = {0};
|
||||
|
||||
ov_shape_t shape = {0, nullptr};
|
||||
int64_t dims[4] = {1, 3, 896, 896};
|
||||
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
|
||||
|
||||
ov_partial_shape_t partial_shape;
|
||||
OV_EXPECT_OK(ov_shape_to_partial_shape(shape, &partial_shape));
|
||||
OV_EXPECT_OK(ov_model_reshape_by_port_indexes(model, port_indexs, &partial_shape, 1));
|
||||
|
||||
ov_output_const_port_t* input_port_2 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_port_2));
|
||||
EXPECT_NE(nullptr, input_port_2);
|
||||
|
||||
ov_shape_free(&shape);
|
||||
ov_partial_shape_free(&partial_shape);
|
||||
ov_output_const_port_free(input_port_2);
|
||||
ov_model_free(model);
|
||||
ov_core_free(core);
|
||||
}
|
||||
|
||||
TEST(ov_model, ov_model_reshape_single_input) {
|
||||
ov_core_t* core = nullptr;
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
EXPECT_NE(nullptr, core);
|
||||
|
||||
ov_model_t* model = nullptr;
|
||||
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
|
||||
EXPECT_NE(nullptr, model);
|
||||
|
||||
ov_shape_t shape = {0, nullptr};
|
||||
int64_t dims[4] = {1, 3, 896, 896};
|
||||
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
|
||||
|
||||
ov_partial_shape_t partial_shape;
|
||||
OV_EXPECT_OK(ov_shape_to_partial_shape(shape, &partial_shape));
|
||||
OV_EXPECT_OK(ov_model_reshape_single_input(model, partial_shape));
|
||||
|
||||
ov_output_const_port_t* input_port_2 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_port_2));
|
||||
EXPECT_NE(nullptr, input_port_2);
|
||||
|
||||
ov_shape_free(&shape);
|
||||
ov_partial_shape_free(&partial_shape);
|
||||
ov_output_const_port_free(input_port_2);
|
||||
ov_model_free(model);
|
||||
ov_core_free(core);
|
||||
}
|
||||
|
||||
TEST(ov_model, ov_model_reshape_by_ports) {
|
||||
ov_core_t* core = nullptr;
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
EXPECT_NE(nullptr, core);
|
||||
|
||||
ov_model_t* model = nullptr;
|
||||
OV_EXPECT_OK(ov_core_read_model(core, xml, bin, &model));
|
||||
EXPECT_NE(nullptr, model);
|
||||
|
||||
ov_output_port_t* input_port_1 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_input(model, &input_port_1));
|
||||
EXPECT_NE(nullptr, input_port_1);
|
||||
const ov_output_port_t* input_ports = input_port_1;
|
||||
|
||||
ov_shape_t shape = {0, nullptr};
|
||||
int64_t dims[4] = {1, 3, 896, 896};
|
||||
OV_EXPECT_OK(ov_shape_create(4, dims, &shape));
|
||||
|
||||
ov_partial_shape_t partial_shape;
|
||||
OV_EXPECT_OK(ov_shape_to_partial_shape(shape, &partial_shape));
|
||||
OV_EXPECT_OK(ov_model_reshape_by_ports(model, &input_ports, &partial_shape, 1));
|
||||
|
||||
ov_output_const_port_t* input_port_2 = nullptr;
|
||||
OV_EXPECT_OK(ov_model_const_input(model, &input_port_2));
|
||||
EXPECT_NE(nullptr, input_port_2);
|
||||
|
||||
ov_shape_free(&shape);
|
||||
ov_partial_shape_free(&partial_shape);
|
||||
ov_output_port_free(input_port_1);
|
||||
ov_output_const_port_free(input_port_2);
|
||||
ov_model_free(model);
|
||||
ov_core_free(core);
|
||||
}
|
||||
|
||||
TEST(ov_model, ov_model_get_friendly_name) {
|
||||
ov_core_t* core = nullptr;
|
||||
OV_EXPECT_OK(ov_core_create(&core));
|
||||
|
||||
@@ -135,3 +135,27 @@ TEST(ov_partial_shape, ov_shape_to_partial_shape) {
|
||||
ov_shape_free(&shape);
|
||||
ov_free(tmp);
|
||||
}
|
||||
|
||||
TEST(ov_partial_shape, ov_partial_shape_is_dynamic) {
|
||||
ov_partial_shape_t partial_shape;
|
||||
|
||||
int64_t rank = 5;
|
||||
ov_dimension_t dims[5] = {{10, 10}, {-1, -1}, {30, 30}, {40, 40}, {50, 50}};
|
||||
OV_ASSERT_OK(ov_partial_shape_create(rank, dims, &partial_shape));
|
||||
ASSERT_TRUE(ov_partial_shape_is_dynamic(partial_shape));
|
||||
|
||||
ov_partial_shape_t partial_shape_rank_dynamic;
|
||||
ov_rank_t rank_dynamic = {-1, -1};
|
||||
OV_ASSERT_OK(ov_partial_shape_create_dynamic(rank_dynamic, nullptr, &partial_shape_rank_dynamic));
|
||||
ASSERT_TRUE(ov_partial_shape_is_dynamic(partial_shape_rank_dynamic));
|
||||
|
||||
ov_partial_shape_t partial_shape_static;
|
||||
int64_t rank_static = 5;
|
||||
ov_dimension_t dims_static[5] = {{10, 10}, {20, 20}, {30, 30}, {40, 40}, {50, 50}};
|
||||
OV_ASSERT_OK(ov_partial_shape_create(rank_static, dims_static, &partial_shape_static));
|
||||
ASSERT_FALSE(ov_partial_shape_is_dynamic(partial_shape_static));
|
||||
|
||||
ov_partial_shape_free(&partial_shape);
|
||||
ov_partial_shape_free(&partial_shape_rank_dynamic);
|
||||
ov_partial_shape_free(&partial_shape_static);
|
||||
}
|
||||
Reference in new issue
Block a user