Repository navigation
Expand file tree
/
Copy pathov_util_test.cpp
More file actions
91 lines (80 loc) · 3.03 KB
/
Copy pathov_util_test.cpp
File metadata and controls
91 lines (80 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (C) 2018-2026 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <cstring>
#include "openvino/c/openvino.h"
#include "openvino/util/log.hpp"
namespace {
void test_log_msg(const char* msg) {
ov::util::LogHelper{ov::util::LOG_TYPE::_LOG_TYPE_INFO, "1664804", 101}.stream() << msg;
}
std::string got_message;
void callback_func(const char* msg) {
got_message = msg;
}
bool compare_msg(const char* msg) {
const auto msg_size = std::strlen(msg);
if (got_message.size() < msg_size) {
return false;
}
return std::strncmp(msg, got_message.data() + got_message.size() - msg_size, msg_size) == 0;
}
} // namespace
TEST(ov_util, set_log_callback) {
got_message.clear();
test_log_msg("default");
EXPECT_TRUE(got_message.empty());
ov_util_set_log_callback(&callback_func);
const char test_msg[] = "callback";
test_log_msg(test_msg);
EXPECT_TRUE(compare_msg(test_msg));
}
TEST(ov_util, reset_log_callback) {
got_message.clear();
ov_util_set_log_callback(&callback_func);
ov_util_reset_log_callback();
test_log_msg("default");
EXPECT_TRUE(got_message.empty());
}
TEST(ov_util, no_log_callback) {
got_message.clear();
ov_util_set_log_callback(NULL);
EXPECT_NO_THROW(test_log_msg("default"));
EXPECT_TRUE(got_message.empty());
}
TEST(ov_util, ov_get_error_info_returns_static_pointer) {
const char* p1 = ov_get_error_info(GENERAL_ERROR);
const char* p2 = ov_get_error_info(GENERAL_ERROR);
EXPECT_EQ(p1, p2) << "ov_get_error_info must return a pointer to static storage, not a newly allocated string";
// Every known status code must return a non-null, non-empty string.
const auto all_codes = {OK,
GENERAL_ERROR,
NOT_IMPLEMENTED,
NETWORK_NOT_LOADED,
PARAMETER_MISMATCH,
NOT_FOUND,
OUT_OF_BOUNDS,
UNEXPECTED,
REQUEST_BUSY,
RESULT_NOT_READY,
NOT_ALLOCATED,
INFER_NOT_STARTED,
NETWORK_NOT_READ,
INFER_CANCELLED,
INVALID_C_PARAM,
UNKNOWN_C_ERROR,
NOT_IMPLEMENT_C_METHOD,
UNKNOW_EXCEPTION};
for (auto code : all_codes) {
const char* msg = ov_get_error_info(code);
EXPECT_NE(nullptr, msg) << "ov_get_error_info returned NULL for status " << code;
EXPECT_GT(std::strlen(msg), 0u) << "ov_get_error_info returned empty string for status " << code;
// Intentionally NOT calling ov_free(msg): the pointer is borrowed static storage.
}
}
TEST(ov_util, ov_get_error_info_out_of_range) {
const char* msg = ov_get_error_info(static_cast<ov_status_e>(-9999));
EXPECT_NE(nullptr, msg);
EXPECT_GT(std::strlen(msg), 0u);
}