Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
M
mbedtls
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
Wiki
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
esp-mirror
Mbed-TLS
mbedtls
提交
7a0d84fc
提交
7a0d84fc
编辑于
7 years ago
作者:
Mohammad Azim Khan
提交者:
Mohammad Azim Khan
6 years ago
浏览文件
操作
下载
补丁
差异文件
On target test host test script
上级
fff4904e
No related branches found
No related tags found
无相关合并请求
变更
1
隐藏空白变更内容
行内
左右并排
显示
1 个更改的文件
tests/scripts/mbedtls_test.py
+243
-0
243 个添加, 0 个删除
tests/scripts/mbedtls_test.py
有
243 个添加
和
0 个删除
tests/scripts/mbedtls_test.py
0 → 100644
+
243
−
0
浏览文件 @
7a0d84fc
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited
Licensed under the Apache License, Version 2.0 (the
"
License
"
);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an
"
AS IS
"
BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import
re
import
os
import
time
from
mbed_host_tests
import
BaseHostTest
,
event_callback
class
TestDataParser
(
object
):
"""
parser for mbedtls test data files.
"""
def
__init__
(
self
):
"""
Constructor
"""
self
.
tests
=
[]
def
parse
(
self
,
data_file
):
"""
"""
with
open
(
data_file
,
'
r
'
)
as
f
:
self
.
__parse
(
f
)
@staticmethod
def
__escaped_split
(
str
,
ch
):
"""
"""
if
len
(
ch
)
>
1
:
raise
ValueError
(
'
Expected split character. Found string!
'
)
out
=
[]
part
=
''
escape
=
False
for
i
in
range
(
len
(
str
)):
if
not
escape
and
str
[
i
]
==
ch
:
out
.
append
(
part
)
part
=
''
else
:
part
+=
str
[
i
]
escape
=
not
escape
and
str
[
i
]
==
'
\\
'
if
len
(
part
):
out
.
append
(
part
)
return
out
def
__parse
(
self
,
file
):
"""
"""
line
=
file
.
readline
().
strip
()
while
line
:
line
=
line
.
strip
()
if
len
(
line
)
==
0
:
line
=
file
.
readline
()
continue
# Read test name
name
=
line
# Check dependencies
deps
=
[]
line
=
file
.
readline
().
strip
()
m
=
re
.
search
(
'
depends_on\:(.*)
'
,
line
)
if
m
:
deps
=
[
int
(
x
)
for
x
in
m
.
group
(
1
).
split
(
'
:
'
)]
line
=
file
.
readline
().
strip
()
# Read test vectors
line
=
line
.
replace
(
'
\\
n
'
,
'
\n
#
'
)
parts
=
self
.
__escaped_split
(
line
,
'
:
'
)
function
=
int
(
parts
[
0
])
x
=
parts
[
1
:]
l
=
len
(
x
)
assert
l
%
2
==
0
,
"
Number of test arguments should be even: %s
"
%
line
args
=
[(
x
[
i
*
2
],
x
[(
i
*
2
)
+
1
])
for
i
in
range
(
len
(
x
)
/
2
)]
self
.
tests
.
append
((
name
,
function
,
deps
,
args
))
line
=
file
.
readline
()
def
get_test_data
(
self
):
"""
"""
return
self
.
tests
class
MbedTlsTest
(
BaseHostTest
):
"""
Host test for mbed-tls target tests.
"""
# From suites/helpers.function
DEPENDENCY_SUPPORTED
=
0
KEY_VALUE_MAPPING_FOUND
=
DEPENDENCY_SUPPORTED
DISPATCH_TEST_SUCCESS
=
DEPENDENCY_SUPPORTED
KEY_VALUE_MAPPING_NOT_FOUND
=
-
1
DEPENDENCY_NOT_SUPPORTED
=
-
2
DISPATCH_TEST_FN_NOT_FOUND
=
-
3
DISPATCH_INVALID_TEST_DATA
=
-
4
DISPATCH_UNSUPPORTED_SUITE
=
-
5
def
__init__
(
self
):
"""
"""
super
(
MbedTlsTest
,
self
).
__init__
()
self
.
tests
=
[]
self
.
test_index
=
-
1
self
.
dep_index
=
0
self
.
error_str
=
dict
()
self
.
error_str
[
self
.
DEPENDENCY_SUPPORTED
]
=
'
DEPENDENCY_SUPPORTED
'
self
.
error_str
[
self
.
KEY_VALUE_MAPPING_NOT_FOUND
]
=
'
KEY_VALUE_MAPPING_NOT_FOUND
'
self
.
error_str
[
self
.
DEPENDENCY_NOT_SUPPORTED
]
=
'
DEPENDENCY_NOT_SUPPORTED
'
self
.
error_str
[
self
.
DISPATCH_TEST_FN_NOT_FOUND
]
=
'
DISPATCH_TEST_FN_NOT_FOUND
'
self
.
error_str
[
self
.
DISPATCH_INVALID_TEST_DATA
]
=
'
DISPATCH_INVALID_TEST_DATA
'
self
.
error_str
[
self
.
DISPATCH_UNSUPPORTED_SUITE
]
=
'
DISPATCH_UNSUPPORTED_SUITE
'
def
setup
(
self
):
"""
"""
binary_path
=
self
.
get_config_item
(
'
image_path
'
)
script_dir
=
os
.
path
.
split
(
os
.
path
.
abspath
(
__file__
))[
0
]
suite_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
binary_path
))[
0
]
data_file
=
"
.
"
.
join
((
suite_name
,
'
data
'
))
data_file
=
os
.
path
.
join
(
script_dir
,
'
..
'
,
'
mbedtls
'
,
suite_name
,
data_file
)
if
os
.
path
.
exists
(
data_file
):
self
.
log
(
"
Running tests from %s
"
%
data_file
)
parser
=
TestDataParser
()
parser
.
parse
(
data_file
)
self
.
tests
=
parser
.
get_test_data
()
self
.
print_test_info
()
else
:
self
.
log
(
"
Data file not found: %s
"
%
data_file
)
self
.
notify_complete
(
False
)
def
print_test_info
(
self
):
"""
"""
self
.
log
(
'
{{__testcase_count;%d}}
'
%
len
(
self
.
tests
))
for
name
,
_
,
_
,
_
in
self
.
tests
:
self
.
log
(
'
{{__testcase_name;%s}}
'
%
name
)
@staticmethod
def
align_32bit
(
b
):
"""
4 byte aligns byte array.
:return:
"""
b
+=
bytearray
((
4
-
(
len
(
b
)))
%
4
)
def
parameters_to_bytes
(
self
,
b
,
parameters
):
for
typ
,
param
in
parameters
:
if
typ
==
'
int
'
or
typ
==
'
exp
'
:
i
=
int
(
param
)
b
+=
'
I
'
if
typ
==
'
int
'
else
'
E
'
self
.
align_32bit
(
b
)
b
+=
bytearray
([((
i
>>
x
)
&
0xff
)
for
x
in
[
24
,
16
,
8
,
0
]])
elif
typ
==
'
char*
'
:
param
=
param
.
strip
(
'"'
)
i
=
len
(
param
)
+
1
# + 1 for null termination
b
+=
'
S
'
self
.
align_32bit
(
b
)
b
+=
bytearray
([((
i
>>
x
)
&
0xff
)
for
x
in
[
24
,
16
,
8
,
0
]])
b
+=
bytearray
(
list
(
param
))
b
+=
'
\0
'
# Null terminate
return
b
def
run_next_test
(
self
):
"""
Send next test function to the target.
"""
self
.
test_index
+=
1
self
.
dep_index
=
0
if
self
.
test_index
<
len
(
self
.
tests
):
name
,
function
,
deps
,
args
=
self
.
tests
[
self
.
test_index
]
self
.
log
(
"
Running: %s
"
%
name
)
bytes
=
bytearray
([
len
(
deps
)])
if
len
(
deps
):
bytes
+=
bytearray
(
deps
)
bytes
+=
bytearray
([
function
,
len
(
args
)])
self
.
parameters_to_bytes
(
bytes
,
args
)
key
=
bytearray
([((
len
(
bytes
)
>>
x
)
&
0xff
)
for
x
in
[
24
,
16
,
8
,
0
]])
#self.log("Bytes: " + " ".join(["%x '%c'" % (x, x) for x in bytes]))
self
.
send_kv
(
key
,
bytes
)
else
:
self
.
notify_complete
(
True
)
@staticmethod
def
get_result
(
value
):
try
:
return
int
(
value
)
except
ValueError
:
ValueError
(
"
Result should return error number. Instead received %s
"
%
value
)
return
0
@event_callback
(
'
GO
'
)
def
on_go
(
self
,
key
,
value
,
timestamp
):
self
.
run_next_test
()
@event_callback
(
"
R
"
)
def
on_result
(
self
,
key
,
value
,
timestamp
):
"""
Handle result.
"""
int_val
=
self
.
get_result
(
value
)
name
,
function
,
deps
,
args
=
self
.
tests
[
self
.
test_index
]
self
.
log
(
'
{{__testcase_finish;%s;%d;%d}}
'
%
(
name
,
int_val
==
0
,
int_val
!=
0
))
self
.
run_next_test
()
@event_callback
(
"
F
"
)
def
on_failure
(
self
,
key
,
value
,
timestamp
):
"""
Handles test execution failure. Hence marking test as skipped.
:param key:
:param value:
:param timestamp:
:return:
"""
int_val
=
self
.
get_result
(
value
)
name
,
function
,
deps
,
args
=
self
.
tests
[
self
.
test_index
]
if
int_val
in
self
.
error_str
:
err
=
self
.
error_str
[
int_val
]
else
:
err
=
'
Unknown error
'
# For skip status, do not write {{__testcase_finish;...}}
self
.
log
(
"
Error: %s
"
%
err
)
self
.
run_next_test
()
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录