Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
5657491a
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
7
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5657491a
编写于
5月 25, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 25, 2020
浏览文件
操作
浏览文件
下载
差异文件
!165 Add more profiler ut
Merge pull request !165 from yuximiao/master
上级
4bdf80be
71866d28
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
160 addition
and
71 deletion
+160
-71
mindinsight/profiler/common/validator/validate.py
mindinsight/profiler/common/validator/validate.py
+119
-71
tests/ut/backend/profiler/test_profiler_restful_api.py
tests/ut/backend/profiler/test_profiler_restful_api.py
+41
-0
未找到文件。
mindinsight/profiler/common/validator/validate.py
浏览文件 @
5657491a
...
...
@@ -14,7 +14,7 @@
# ============================================================================
"""Validate the profiler parameters."""
from
mindinsight.profiler.common.exceptions.exceptions
import
ProfilerParamTypeErrorException
,
\
Profiler
ParamValueErrorException
,
Profiler
DeviceIdException
,
ProfilerOpTypeException
,
\
ProfilerDeviceIdException
,
ProfilerOpTypeException
,
\
ProfilerSortConditionException
,
ProfilerFilterConditionException
,
ProfilerGroupConditionException
from
mindinsight.profiler.common.log
import
logger
as
log
...
...
@@ -63,77 +63,125 @@ def validate_condition(search_condition):
raise
ProfilerOpTypeException
(
"The op_type must in ['aicpu', 'aicore_type', 'aicore_detail']"
)
if
"group_condition"
in
search_condition
:
group_condition
=
search_condition
.
get
(
"group_condition"
)
if
not
isinstance
(
group_condition
,
dict
):
raise
ProfilerGroupConditionException
(
"The group condition must be dict."
)
if
"limit"
in
group_condition
:
limit
=
group_condition
.
get
(
"limit"
,
0
)
if
isinstance
(
limit
,
bool
)
\
or
not
isinstance
(
group_condition
.
get
(
"limit"
),
int
):
log
.
error
(
"The limit must be int."
)
raise
ProfilerGroupConditionException
(
"The limit must be int."
)
if
limit
<
1
or
limit
>
100
:
raise
ProfilerGroupConditionException
(
"The limit must in [1, 100]."
)
if
"offset"
in
group_condition
:
offset
=
group_condition
.
get
(
"offset"
,
0
)
if
isinstance
(
offset
,
bool
)
\
or
not
isinstance
(
group_condition
.
get
(
"offset"
),
int
):
log
.
error
(
"The offset must be int."
)
raise
ProfilerGroupConditionException
(
"The offset must be int."
)
if
offset
<
0
:
raise
ProfilerGroupConditionException
(
"The offset must ge 0."
)
if
offset
>
1000000
:
raise
ProfilerGroupConditionException
(
"The offset must le 1000000."
)
validata_group_condition
(
search_condition
)
if
"sort_condition"
in
search_condition
:
sort_condition
=
search_condition
.
get
(
"sort_condition"
)
if
not
isinstance
(
sort_condition
,
dict
):
raise
ProfilerSortConditionException
(
"The sort condition must be dict."
)
if
"name"
in
sort_condition
:
sorted_name
=
sort_condition
.
get
(
"name"
,
""
)
err_msg
=
"The sorted_name must be in {}"
.
format
(
search_scope
)
if
not
isinstance
(
sorted_name
,
str
):
log
.
error
(
"Wrong sorted name type."
)
raise
ProfilerSortConditionException
(
"Wrong sorted name type."
)
if
sorted_name
not
in
search_scope
:
log
.
error
(
err_msg
)
raise
ProfilerSortConditionException
(
err_msg
)
if
"type"
in
sort_condition
:
sorted_type_param
=
[
'ascending'
,
'descending'
]
sorted_type
=
sort_condition
.
get
(
"type"
)
if
sorted_type
not
in
sorted_type_param
:
err_msg
=
"The sorted type must be ascending or descending."
log
.
error
(
err_msg
)
raise
ProfilerParamValueErrorException
(
err_msg
)
validate_sort_condition
(
search_condition
,
search_scope
)
if
"filter_condition"
in
search_condition
:
def
validate_op_filter_condition
(
op_condition
):
if
not
isinstance
(
op_condition
,
dict
):
raise
ProfilerFilterConditionException
(
"Wrong op_type filter condition."
)
for
key
,
value
in
op_condition
.
items
():
if
not
isinstance
(
key
,
str
):
raise
ProfilerFilterConditionException
(
"The filter key must be str"
)
if
not
isinstance
(
value
,
list
):
raise
ProfilerFilterConditionException
(
"The filter value must be list"
)
if
key
not
in
filter_key
:
raise
ProfilerFilterConditionException
(
"The filter key must in {}."
.
format
(
filter_key
))
for
item
in
value
:
if
not
isinstance
(
item
,
str
):
raise
ProfilerFilterConditionException
(
"The item in filter value must be str"
)
filter_condition
=
search_condition
.
get
(
"filter_condition"
)
if
not
isinstance
(
filter_condition
,
dict
):
raise
ProfilerFilterConditionException
(
"The filter condition must be dict."
)
filter_key
=
[
"in"
,
"not_in"
,
"partial_match_str_in"
]
if
filter_condition
:
if
"op_type"
in
filter_condition
:
op_type_condition
=
filter_condition
.
get
(
"op_type"
)
validate_op_filter_condition
(
op_type_condition
)
if
"op_name"
in
filter_condition
:
op_name_condition
=
filter_condition
.
get
(
"op_name"
)
validate_op_filter_condition
(
op_name_condition
)
if
"op_type"
not
in
filter_condition
and
"op_name"
not
in
filter_condition
:
raise
ProfilerFilterConditionException
(
"The key of filter_condition is not support"
)
validate_filter_condition
(
search_condition
)
def
validata_group_condition
(
search_condition
):
"""
Verify the group_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
Raises:
ProfilerGroupConditionException: If the group_condition param in search_condition is invalid.
"""
group_condition
=
search_condition
.
get
(
"group_condition"
)
if
not
isinstance
(
group_condition
,
dict
):
raise
ProfilerGroupConditionException
(
"The group condition must be dict."
)
if
"limit"
in
group_condition
:
limit
=
group_condition
.
get
(
"limit"
,
0
)
if
isinstance
(
limit
,
bool
)
\
or
not
isinstance
(
group_condition
.
get
(
"limit"
),
int
):
log
.
error
(
"The limit must be int."
)
raise
ProfilerGroupConditionException
(
"The limit must be int."
)
if
limit
<
1
or
limit
>
100
:
raise
ProfilerGroupConditionException
(
"The limit must in [1, 100]."
)
if
"offset"
in
group_condition
:
offset
=
group_condition
.
get
(
"offset"
,
0
)
if
isinstance
(
offset
,
bool
)
\
or
not
isinstance
(
group_condition
.
get
(
"offset"
),
int
):
log
.
error
(
"The offset must be int."
)
raise
ProfilerGroupConditionException
(
"The offset must be int."
)
if
offset
<
0
:
raise
ProfilerGroupConditionException
(
"The offset must ge 0."
)
if
offset
>
1000000
:
raise
ProfilerGroupConditionException
(
"The offset must le 1000000."
)
def
validate_sort_condition
(
search_condition
,
search_scope
):
"""
Verify the sort_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
search_scope (list): The search scope.
Raises:
ProfilerSortConditionException: If the sort_condition param in search_condition is invalid.
"""
sort_condition
=
search_condition
.
get
(
"sort_condition"
)
if
not
isinstance
(
sort_condition
,
dict
):
raise
ProfilerSortConditionException
(
"The sort condition must be dict."
)
if
"name"
in
sort_condition
:
sorted_name
=
sort_condition
.
get
(
"name"
,
""
)
err_msg
=
"The sorted_name must be in {}"
.
format
(
search_scope
)
if
not
isinstance
(
sorted_name
,
str
):
log
.
error
(
"Wrong sorted name type."
)
raise
ProfilerSortConditionException
(
"Wrong sorted name type."
)
if
sorted_name
not
in
search_scope
:
log
.
error
(
err_msg
)
raise
ProfilerSortConditionException
(
err_msg
)
if
"type"
in
sort_condition
:
sorted_type_param
=
[
'ascending'
,
'descending'
]
sorted_type
=
sort_condition
.
get
(
"type"
)
if
sorted_type
not
in
sorted_type_param
:
err_msg
=
"The sorted type must be ascending or descending."
log
.
error
(
err_msg
)
raise
ProfilerSortConditionException
(
err_msg
)
def
validate_filter_condition
(
search_condition
):
"""
Verify the filter_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
Raises:
ProfilerFilterConditionException: If the filter_condition param in search_condition is invalid.
"""
def
validate_op_filter_condition
(
op_condition
):
"""
Verify the op_condition in filter_condition is valid or not.
Args:
op_condition (dict): The op_condition in search_condition.
Raises:
ProfilerFilterConditionException: If the filter_condition param in search_condition is invalid.
"""
if
not
isinstance
(
op_condition
,
dict
):
raise
ProfilerFilterConditionException
(
"Wrong op_type filter condition."
)
for
key
,
value
in
op_condition
.
items
():
if
not
isinstance
(
key
,
str
):
raise
ProfilerFilterConditionException
(
"The filter key must be str"
)
if
not
isinstance
(
value
,
list
):
raise
ProfilerFilterConditionException
(
"The filter value must be list"
)
if
key
not
in
filter_key
:
raise
ProfilerFilterConditionException
(
"The filter key must in {}."
.
format
(
filter_key
))
for
item
in
value
:
if
not
isinstance
(
item
,
str
):
raise
ProfilerFilterConditionException
(
"The item in filter value must be str"
)
filter_condition
=
search_condition
.
get
(
"filter_condition"
)
if
not
isinstance
(
filter_condition
,
dict
):
raise
ProfilerFilterConditionException
(
"The filter condition must be dict."
)
filter_key
=
[
"in"
,
"not_in"
,
"partial_match_str_in"
]
if
filter_condition
:
if
"op_type"
in
filter_condition
:
op_type_condition
=
filter_condition
.
get
(
"op_type"
)
validate_op_filter_condition
(
op_type_condition
)
if
"op_name"
in
filter_condition
:
op_name_condition
=
filter_condition
.
get
(
"op_name"
)
validate_op_filter_condition
(
op_name_condition
)
if
"op_type"
not
in
filter_condition
and
"op_name"
not
in
filter_condition
:
raise
ProfilerFilterConditionException
(
"The key of filter_condition is not support"
)
tests/ut/backend/profiler/test_profiler_restful_api.py
浏览文件 @
5657491a
...
...
@@ -78,3 +78,44 @@ class TestProfilerRestfulApi(TestCase):
result
=
response
.
get_json
()
del
result
[
"error_msg"
]
self
.
assertDictEqual
(
expect_result
,
result
)
body_data
=
{
"op_type"
:
"aicore_type"
,
"device_id"
:
1
}
response
=
self
.
app_client
.
post
(
self
.
url
,
data
=
json
.
dumps
(
body_data
))
self
.
assertEqual
(
400
,
response
.
status_code
)
expect_result
=
{
'error_code'
:
'50546182'
,
}
result
=
response
.
get_json
()
del
result
[
"error_msg"
]
self
.
assertDictEqual
(
expect_result
,
result
)
body_data
=
{
"op_type"
:
"aicore_type"
,
"device_id"
:
"1"
,
"group_condition"
:
1
}
response
=
self
.
app_client
.
post
(
self
.
url
,
data
=
json
.
dumps
(
body_data
))
self
.
assertEqual
(
400
,
response
.
status_code
)
expect_result
=
{
'error_code'
:
'50546184'
,
}
result
=
response
.
get_json
()
del
result
[
"error_msg"
]
self
.
assertDictEqual
(
expect_result
,
result
)
body_data
=
{
"op_type"
:
"aicore_type"
,
"device_id"
:
"1"
,
"sort_condition"
:
{
"type"
:
1
}}
response
=
self
.
app_client
.
post
(
self
.
url
,
data
=
json
.
dumps
(
body_data
))
self
.
assertEqual
(
400
,
response
.
status_code
)
expect_result
=
{
'error_code'
:
'50546185'
,
}
result
=
response
.
get_json
()
del
result
[
"error_msg"
]
self
.
assertDictEqual
(
expect_result
,
result
)
body_data
=
{
"op_type"
:
"aicore_type"
,
"device_id"
:
"1"
,
"filter_condition"
:
{
"op_type"
:
{
"in"
:
[
"1"
,
2
]}}}
response
=
self
.
app_client
.
post
(
self
.
url
,
data
=
json
.
dumps
(
body_data
))
self
.
assertEqual
(
400
,
response
.
status_code
)
expect_result
=
{
'error_code'
:
'50546186'
,
}
result
=
response
.
get_json
()
del
result
[
"error_msg"
]
self
.
assertDictEqual
(
expect_result
,
result
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录