Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Test Xdevice
提交
327d1b91
T
Test Xdevice
项目概览
OpenHarmony
/
Test Xdevice
11 个月 前同步成功
通知
6
Star
23
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Test Xdevice
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
327d1b91
编写于
9月 16, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 16, 2021
浏览文件
操作
浏览文件
下载
差异文件
!38 解决xdevice支持标准设备运行c++ js用例问题
Merge pull request !38 from alex_hold/master
上级
9a949f93
d7ab156c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
100 addition
and
66 deletion
+100
-66
extension/src/xdevice_extension/_core/driver/drivers.py
extension/src/xdevice_extension/_core/driver/drivers.py
+100
-66
未找到文件。
extension/src/xdevice_extension/_core/driver/drivers.py
浏览文件 @
327d1b91
...
...
@@ -17,7 +17,6 @@
#
import
os
import
re
import
time
import
json
import
shutil
...
...
@@ -55,8 +54,11 @@ from xdevice_extension._core.testkit.kit import junit_para_parse
from
xdevice_extension._core.testkit.kit
import
junit_dex_para_parse
from
xdevice_extension._core.testkit.kit
import
reset_junit_para
from
xdevice_extension._core.utils
import
get_filename_extension
from
xdevice_extension._core.utils
import
start_standing_subprocess
from
xdevice_extension._core.executor.listener
import
CollectingTestListener
from
xdevice_extension._core.testkit.kit
import
gtest_para_parse
from
xdevice_extension._core.environment.dmlib
import
process_command_ret
__all__
=
[
"CppTestDriver"
,
"DexTestDriver"
,
"HapTestDriver"
,
"JSUnitTestDriver"
,
"JUnitTestDriver"
,
"RemoteTestRunner"
,
...
...
@@ -339,10 +341,12 @@ class CppTestDriver(IDriver):
hilog_open
=
os
.
open
(
hilog
,
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_APPEND
,
0o755
)
self
.
config
.
device
.
hdc_command
(
"shell hilog -r"
)
self
.
_run_cpp_test
(
config_file
,
listeners
=
request
.
listeners
,
request
=
request
)
with
os
.
fdopen
(
hilog_open
,
"a"
)
as
hilog_file_pipe
:
self
.
config
.
device
.
start_catch_device_log
(
hilog_file_pipe
)
self
.
_run_cpp_test
(
config_file
,
listeners
=
request
.
listeners
,
request
=
request
)
time
.
sleep
(
30
)
hilog_file_pipe
.
flush
()
except
Exception
as
exception
:
...
...
@@ -506,23 +510,39 @@ class RemoteCppTestRunner:
parser_instance
=
parser
.
__class__
()
parser_instances
.
append
(
parser_instance
)
handler
=
ShellHandler
(
parser_instances
)
command
=
"cd %s; chmod +x *; ./%s %s"
\
%
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
self
.
config
.
device
.
execute_shell_command
(
command
,
timeout
=
self
.
config
.
timeout
,
receiver
=
handler
,
retry
=
0
)
# apply execute right
chmod_cmd
=
"shell chmod 777 {}/{}"
.
format
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
)
LOG
.
info
(
"The apply execute command is {}"
.
format
(
chmod_cmd
))
self
.
config
.
device
.
hdc_command
(
chmod_cmd
,
timeout
=
30
*
1000
)
# dry run command
dry_command
=
".{}/{} {}"
.
format
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
pre_cmd
=
"hdc_std -t %s shell "
%
self
.
config
.
device
.
device_sn
command
=
"%s %s"
%
(
pre_cmd
,
dry_command
)
LOG
.
info
(
"The dry_command execute command is {}"
.
format
(
command
))
output
=
start_standing_subprocess
(
command
.
split
(),
return_result
=
True
)
LOG
.
debug
(
"dryrun output ---"
)
output
=
output
.
replace
(
"
\r
"
,
""
)
handler
.
__read__
(
output
)
handler
.
__done__
()
return
parser_instances
[
0
].
tests
def
run
(
self
,
listener
):
handler
=
self
.
_get_shell_handler
(
listener
)
command
=
"cd %s; chmod +x *; ./%s %s"
\
%
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
self
.
config
.
device
.
execute_shell_command
(
command
,
timeout
=
self
.
config
.
timeout
,
receiver
=
handler
,
retry
=
0
)
pre_cmd
=
"hdc_std -t %s shell "
%
self
.
config
.
device
.
device_sn
command
=
".{}/{} {}"
.
format
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
command
=
"%s %s"
%
(
pre_cmd
,
command
)
LOG
.
debug
(
"run command is: %s"
%
command
)
output
=
start_standing_subprocess
(
command
.
split
(),
return_result
=
True
)
LOG
.
debug
(
"run output ---"
)
output
=
output
.
replace
(
"
\r
"
,
""
)
handler
.
__read__
(
output
)
handler
.
__done__
()
def
rerun
(
self
,
listener
,
test
):
if
self
.
rerun_attempt
:
...
...
@@ -531,14 +551,18 @@ class RemoteCppTestRunner:
listener_copy
.
append
(
test_tracker
)
handler
=
self
.
_get_shell_handler
(
listener_copy
)
try
:
command
=
"cd %s; chmod +x *; ./%s %s"
\
%
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
self
.
config
.
device
.
execute_shell_command
(
command
,
timeout
=
self
.
config
.
timeout
,
receiver
=
handler
,
retry
=
0
)
pre_cmd
=
"hdc_std -t %s shell "
%
self
.
config
.
device
.
device_sn
command
=
".{}/{} {}"
.
format
(
self
.
config
.
target_test_path
,
self
.
config
.
module_name
,
self
.
get_args_command
())
command
=
"%s %s"
%
(
pre_cmd
,
command
)
LOG
.
debug
(
"rerun command is: %s"
%
command
)
output
=
start_standing_subprocess
(
command
.
split
(),
return_result
=
True
)
LOG
.
debug
(
"run output ---"
)
output
=
output
.
replace
(
"
\r
"
,
""
)
handler
.
__read__
(
output
)
handler
.
__done__
()
except
ShellCommandUnresponsiveException
:
LOG
.
debug
(
"Exception: ShellCommandUnresponsiveException"
)
...
...
@@ -1743,7 +1767,7 @@ class HapTestDriver(IDriver):
filename
,
junit_test_para
,
suitefile_target_test_path
)
self
.
result
=
result
.
get_test_results
(
return_message
)
self
.
_unistall_hap
(
self
.
package_name
)
self
.
_uni
n
stall_hap
(
self
.
package_name
)
else
:
self
.
result
=
result
.
get_test_results
(
"Error: install hap failed."
)
LOG
.
error
(
"Error: install hap failed."
,
error_no
=
"03204"
)
...
...
@@ -1906,7 +1930,7 @@ class HapTestDriver(IDriver):
LOG
.
info
(
"HAP Testcase executed finished"
)
return
return_code
def
_unistall_hap
(
self
,
package_name
):
def
_uni
n
stall_hap
(
self
,
package_name
):
return_message
=
self
.
config
.
device
.
execute_shell_command
(
"pm uninstall %s"
%
package_name
)
_sleep_according_to_result
(
return_message
)
...
...
@@ -1998,10 +2022,9 @@ class JSUnitTestDriver(IDriver):
def
__execute__
(
self
,
request
):
try
:
LOG
.
debug
(
"Start execute xdevice extension JSUnit Test"
)
self
.
result
=
os
.
path
.
join
(
request
.
config
.
report_path
,
"result"
,
'.'
.
join
((
request
.
get_module_name
(),
"xml"
)))
self
.
result
=
os
.
path
.
join
(
request
.
config
.
report_path
,
"result"
,
'.'
.
join
((
request
.
get_module_name
(),
"xml"
)))
self
.
config
=
request
.
config
self
.
config
.
device
=
request
.
config
.
environment
.
devices
[
0
]
...
...
@@ -2014,8 +2037,8 @@ class JSUnitTestDriver(IDriver):
request
.
root
.
source
.
source_string
,
error_no
=
"00110"
)
LOG
.
debug
(
"Test case file path: %s"
%
suite_file
)
self
.
config
.
device
.
hdc_command
(
"shell hilog -r"
)
self
.
_run_jsunit
(
config_file
,
request
)
self
.
generate_console_output
(
request
)
except
Exception
as
exception
:
self
.
error_message
=
exception
if
not
getattr
(
exception
,
"error_no"
,
""
):
...
...
@@ -2027,7 +2050,10 @@ class JSUnitTestDriver(IDriver):
self
.
result
=
check_result_report
(
request
.
config
.
report_path
,
self
.
result
,
self
.
error_message
)
def
generate_console_output
(
self
,
request
):
def
generate_console_output
(
self
,
device_log_file
,
request
):
LOG
.
info
(
"prepare to read device log, may wait some time"
)
result_message
=
self
.
read_device_log
(
device_log_file
,
""
)
report_name
=
request
.
get_module_name
()
parsers
=
get_plugin
(
Plugin
.
PARSER
,
CommonParserType
.
jsunit
)
...
...
@@ -2039,37 +2065,29 @@ class JSUnitTestDriver(IDriver):
for
parser
in
parsers
:
parser_instance
=
parser
.
__class__
()
parser_instance
.
suites_name
=
"{}_suites"
.
format
(
report_name
)
parser_instance
.
suites_name
=
report_name
parser_instance
.
suite_name
=
report_name
parser_instance
.
listeners
=
request
.
listeners
parser_instances
.
append
(
parser_instance
)
handler
=
ShellHandler
(
parser_instances
)
from
xdevice_extension._core
import
utils
command
=
"hdc_std -t %s shell hilog -x "
%
self
.
config
.
device
.
\
device_sn
output
=
utils
.
start_standing_subprocess
(
command
,
return_result
=
True
)
LOG
.
debug
(
"start to parsing hilog"
)
handler
.
__read__
(
output
)
handler
.
__done__
()
process_command_ret
(
result_message
,
handler
)
def
read_device_log
(
self
,
device_log_file
,
result_message
):
device_log_file_open
=
os
.
open
(
device_log_file
,
os
.
O_RDONLY
,
stat
.
S_IWUSR
|
stat
.
S_IRUSR
)
with
os
.
fdopen
(
device_log_file_open
,
"r"
)
as
file_read_pipe
:
with
os
.
fdopen
(
device_log_file_open
,
"r"
,
encoding
=
'utf-8'
)
\
as
file_read_pipe
:
while
True
:
data
=
file_read_pipe
.
readline
()
result_message
+=
data
report_name
=
""
if
re
.
match
(
r
'.*\[create report\]*'
,
data
):
_
,
index
=
re
.
match
(
r
'.*\[create report\]*'
,
data
).
span
()
report_name
=
data
[
index
:].
split
(
"."
)[
0
]
if
result_message
.
find
(
"[create report]"
)
!=
-
1
or
\
int
(
time
.
time
())
-
int
(
self
.
start_time
)
>
\
self
.
timeout
:
if
not
data
or
not
data
.
strip
():
break
return
result_message
,
report_name
# only filter JSApp log
if
data
.
find
(
"JSApp:"
)
!=
-
1
:
result_message
+=
data
if
data
.
find
(
"[end] run suites end"
)
!=
-
1
:
break
return
result_message
def
_run_jsunit
(
self
,
config_file
,
request
):
try
:
...
...
@@ -2088,22 +2106,38 @@ class JSUnitTestDriver(IDriver):
self
.
config
.
device
.
hdc_command
(
"target mount"
)
do_module_kit_setup
(
request
,
self
.
kits
)
# execute test case
self
.
config
.
device
.
hdc_command
(
"shell hilog -r"
)
hilog
=
get_device_log_file
(
request
.
config
.
report_path
,
request
.
config
.
device
.
__get_serial__
()
+
"_"
+
request
.
get_module_name
(),
"device_hilog"
)
command
=
"aa start -d 123 -a %s -b %s"
\
%
(
ability_name
,
package
)
self
.
start_time
=
time
.
time
()
result_value
=
self
.
config
.
device
.
execute_shell_command
(
command
,
timeout
=
self
.
timeout
)
if
"success"
in
str
(
result_value
).
lower
():
LOG
.
info
(
"execute %s's testcase success. result value=%s"
%
(
package
,
result_value
))
time
.
sleep
(
60
)
else
:
LOG
.
info
(
"execute %s's testcase failed. result value=%s"
%
(
package
,
result_value
))
hilog_open
=
os
.
open
(
hilog
,
os
.
O_WRONLY
|
os
.
O_CREAT
|
os
.
O_APPEND
,
0o755
)
with
os
.
fdopen
(
hilog_open
,
"a"
)
as
hilog_file_pipe
:
self
.
config
.
device
.
start_catch_device_log
(
hilog_file_pipe
)
# execute test case
command
=
"shell aa start -d 123 -a %s -b %s"
\
%
(
ability_name
,
package
)
result_value
=
self
.
config
.
device
.
hdc_command
(
command
)
if
"success"
in
str
(
result_value
).
lower
():
setattr
(
self
,
"start_success"
,
True
)
LOG
.
info
(
"execute %s's testcase success. result value=%s"
%
(
package
,
result_value
))
else
:
LOG
.
info
(
"execute %s's testcase failed. result value=%s"
%
(
package
,
result_value
))
self
.
start_time
=
time
.
time
()
timeout_config
=
get_config_value
(
'test-timeout'
,
json_config
.
get_driver
(),
False
,
60000
)
timeout
=
int
(
timeout_config
)
/
1000
LOG
.
info
(
"wait {}s to keep app log"
.
format
(
timeout
))
time
.
sleep
(
timeout
)
hilog_file_pipe
.
flush
()
self
.
generate_console_output
(
hilog
,
request
)
finally
:
do_module_kit_teardown
(
request
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录