Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Test Xdevice
提交
9a949f93
T
Test Xdevice
项目概览
OpenHarmony
/
Test Xdevice
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
9a949f93
编写于
9月 16, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 16, 2021
浏览文件
操作
浏览文件
下载
差异文件
!31 解决xdevice支持标准设备运行socket稳定性问题
Merge pull request !31 from alex_hold/master
上级
bb55bc86
0bc3f839
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
67 deletion
+79
-67
extension/src/xdevice_extension/_core/driver/parser.py
extension/src/xdevice_extension/_core/driver/parser.py
+8
-2
extension/src/xdevice_extension/_core/environment/device.py
extension/src/xdevice_extension/_core/environment/device.py
+17
-13
extension/src/xdevice_extension/_core/environment/dmlib.py
extension/src/xdevice_extension/_core/environment/dmlib.py
+39
-26
extension/src/xdevice_extension/_core/testkit/kit.py
extension/src/xdevice_extension/_core/testkit/kit.py
+8
-23
src/xdevice/_core/executor/scheduler.py
src/xdevice/_core/executor/scheduler.py
+1
-1
src/xdevice/_core/utils.py
src/xdevice/_core/utils.py
+6
-2
未找到文件。
extension/src/xdevice_extension/_core/driver/parser.py
浏览文件 @
9a949f93
...
...
@@ -615,6 +615,7 @@ class JSUnitParser(IParser):
self
.
state_machine
=
StateRecorder
()
self
.
suites_name
=
""
self
.
listeners
=
[]
self
.
suite_name
=
""
def
get_listeners
(
self
):
return
self
.
listeners
...
...
@@ -630,11 +631,12 @@ class JSUnitParser(IParser):
suite_result
.
is_completed
=
True
for
listener
in
self
.
get_listeners
():
suite
=
copy
.
copy
(
suite_result
)
listener
.
__ended__
(
LifeCycle
.
TestSuite
,
suite
,
listener
.
__ended__
(
LifeCycle
.
TestSuite
s
,
suite
,
suite_report
=
True
)
self
.
state_machine
.
current_suite
=
None
def
parse
(
self
,
line
):
line
=
line
.
strip
()
if
(
self
.
state_machine
.
suites_is_started
()
or
line
.
find
(
_START_JSUNIT_RUN_MARKER
)
!=
-
1
)
and
line
.
find
(
_ACE_LOG_MARKER
)
!=
-
1
:
...
...
@@ -669,7 +671,11 @@ class JSUnitParser(IParser):
run_time
=
end_timestamp
-
start_timestamp
_
,
status_end_index
=
re
.
match
(
pattern
,
filter_message
).
span
()
status
=
filter_message
[:
status_end_index
]
test_name
=
filter_message
[
status_end_index
:]
if
" ;"
in
filter_message
:
test_name
=
filter_message
[
status_end_index
:
str
(
filter_message
).
find
(
" ;"
)]
else
:
test_name
=
filter_message
[
status_end_index
:]
status_dict
=
{
"pass"
:
ResultCode
.
PASSED
,
"fail"
:
ResultCode
.
FAILED
,
"ignore"
:
ResultCode
.
SKIPPED
}
status
=
status_dict
.
get
(
status
[
1
:
-
1
])
...
...
extension/src/xdevice_extension/_core/environment/device.py
浏览文件 @
9a949f93
...
...
@@ -27,6 +27,7 @@ from xdevice import Plugin
from
xdevice
import
exec_cmd
from
xdevice
import
ConfigConst
from
xdevice_extension._core
import
utils
from
xdevice_extension._core.environment.dmlib
import
HdcHelper
from
xdevice_extension._core.exception
import
HdcError
from
xdevice_extension._core.environment.dmlib
import
CollectingOutputReceiver
...
...
@@ -72,7 +73,7 @@ def perform_device_action(func):
if
self
.
usb_type
==
DeviceConnectorType
.
hdc
:
cmd
=
"hdc reset"
self
.
log
.
info
(
"re-execute hdc reset"
)
exec_cmd
(
cmd
)
exec_cmd
(
cmd
)
if
not
self
.
recover_device
():
LOG
.
debug
(
"set device %s %s false"
%
(
self
.
device_sn
,
ConfigConst
.
recover_state
))
...
...
@@ -166,9 +167,7 @@ class Device(IDevice):
return
self
.
device_state_monitor
.
wait_for_device_available
()
def
get_device_type
(
self
):
model
=
self
.
get_property
(
"ro.build.characteristics"
,
abort_on_exception
=
True
)
self
.
label
=
self
.
model_dict
.
get
(
model
.
lower
(),
None
)
self
.
label
=
self
.
model_dict
.
get
(
"default"
,
None
)
def
get_property
(
self
,
prop_name
,
retry
=
RETRY_ATTEMPTS
,
abort_on_exception
=
False
):
...
...
@@ -193,7 +192,7 @@ class Device(IDevice):
if
self
.
usb_type
==
DeviceConnectorType
.
hdc
:
LOG
.
debug
(
"%s execute command hdc %s%s"
%
(
convert_serial
(
self
.
device_sn
),
command
,
timeout_msg
))
cmd
=
[
"hdc_std"
,
"-t"
,
self
.
device_sn
]
cmd
=
[
"hdc_std"
,
"-t"
,
self
.
device_sn
]
if
isinstance
(
command
,
list
):
cmd
.
extend
(
command
)
else
:
...
...
@@ -292,9 +291,6 @@ class Device(IDevice):
timeout
=
kwargs
.
get
(
"timeout"
,
TIMEOUT
)
HdcHelper
.
push_file
(
self
,
local
,
remote
,
is_create
=
is_create
,
timeout
=
timeout
)
if
not
self
.
is_file_exist
(
remote
):
LOG
.
error
(
"push %s to %s failed"
%
(
local
,
remote
))
raise
HdcError
(
"push %s to %s failed"
%
(
local
,
remote
))
@
perform_device_action
def
pull_file
(
self
,
remote
,
local
,
**
kwargs
):
...
...
@@ -337,9 +333,7 @@ class Device(IDevice):
def
is_file_exist
(
self
,
file_path
):
file_path
=
check_path_legal
(
file_path
)
command
=
[
"hdc_std"
,
"shell"
,
"ls"
,
file_path
]
output
=
exec_cmd
(
command
)
output
=
self
.
execute_shell_command
(
"ls {}"
.
format
(
file_path
))
if
output
and
"No such file or directory"
not
in
output
:
return
True
return
False
...
...
@@ -360,10 +354,20 @@ class Device(IDevice):
self
.
_stop_catch_device_log
()
def
_start_catch_device_log
(
self
):
pass
if
self
.
hilog_file_pipe
:
command
=
"hilog"
if
self
.
usb_type
==
DeviceConnectorType
.
hdc
:
cmd
=
[
'hdc_std'
,
"-t"
,
self
.
device_sn
,
"shell"
,
command
]
LOG
.
info
(
"execute command: %s"
%
" "
.
join
(
cmd
).
replace
(
self
.
device_sn
,
convert_serial
(
self
.
device_sn
)))
self
.
device_hilog_proc
=
utils
.
start_standing_subprocess
(
cmd
,
self
.
hilog_file_pipe
)
def
_stop_catch_device_log
(
self
):
pass
if
self
.
device_hilog_proc
:
utils
.
stop_standing_subprocess
(
self
.
device_hilog_proc
)
self
.
device_hilog_proc
=
None
self
.
hilog_file_pipe
=
None
def
get_recover_result
(
self
,
retry
=
RETRY_ATTEMPTS
):
command
=
"getparam ro.product.model"
...
...
extension/src/xdevice_extension/_core/environment/dmlib.py
浏览文件 @
9a949f93
...
...
@@ -217,14 +217,17 @@ class HdcMonitor:
self
.
main_hdc_connection
)
if
self
.
main_hdc_connection
and
not
self
.
monitoring
:
LOG
.
debug
(
"start monitoring list targets"
)
self
.
monitoring_list_targets
()
len_buf
=
HdcHelper
.
read
(
self
.
main_hdc_connection
,
DATA_UNIT_LENGTH
)
length
=
struct
.
unpack
(
"!I"
,
len_buf
)[
0
]
LOG
.
debug
(
"had received length is: %s"
%
length
)
if
length
>=
0
:
self
.
monitoring
=
True
self
.
process_incoming_target_data
(
length
)
except
(
HdcError
,
Exception
)
as
_
:
LOG
.
debug
(
"loop_monitor happened error: %s"
%
_
)
self
.
handle_exception_monitor_loop
()
break
...
...
@@ -273,22 +276,21 @@ class HdcMonitor:
def
process_incoming_target_data
(
self
,
length
):
local_array_list
=
[]
if
length
>
0
:
data_buf
=
HdcHelper
.
read
(
self
.
main_hdc_connection
,
length
)
data_str
=
HdcHelper
.
reply_to_string
(
data_buf
)
if
'Empty'
not
in
data_str
:
lines
=
data_str
.
split
(
'
\n
'
)
for
line
in
lines
:
items
=
line
.
strip
().
split
(
'
\t
'
)
if
not
items
[
0
]
:
continue
items
.
append
(
DeviceState
.
ONLINE
.
value
)
device_instance
=
self
.
_get_device_instance
(
items
,
DeviceOsType
.
default
)
local_array_list
.
append
(
device_instance
)
else
:
LOG
.
debug
(
"please check device actually.[%s]"
%
data_str
)
data_buf
=
HdcHelper
.
read
(
self
.
main_hdc_connection
,
length
)
data_str
=
HdcHelper
.
reply_to_string
(
data_buf
)
if
'Empty'
not
in
data_str
:
lines
=
data_str
.
split
(
'
\n
'
)
for
line
in
lines
:
items
=
line
.
strip
().
split
(
'
\t
'
)
if
not
items
[
0
]
:
continue
items
.
append
(
DeviceState
.
ONLINE
.
value
)
device_instance
=
self
.
_get_device_instance
(
items
,
DeviceOsType
.
default
)
local_array_list
.
append
(
device_instance
)
else
:
LOG
.
debug
(
"please check device actually.[%s]"
%
data_str
)
LOG
.
debug
(
"process target data, local_array_list"
%
local_array_list
)
self
.
update_devices
(
local_array_list
)
def
_get_device_instance
(
self
,
items
,
os_type
):
...
...
@@ -751,7 +753,7 @@ class HdcHelper:
if
not
os
.
path
.
exists
(
local
):
raise
HdcError
(
"Local path doesn't exist."
)
sock
=
HdcHelper
.
socket
(
host
=
device
.
host
,
port
=
device
.
port
,
timeout
=
DEFAULT_TIMEOUT
)
timeout
=
timeout
)
HdcHelper
.
handle_shake
(
sock
,
device
.
device_sn
)
request
=
HdcHelper
.
form_hdc_request
(
"file send %s %s"
%
(
local
,
remote
))
...
...
@@ -760,6 +762,7 @@ class HdcHelper:
length
=
struct
.
unpack
(
"!I"
,
reply
)[
0
]
data_buf
=
HdcHelper
.
read
(
sock
,
length
)
data_str
=
HdcHelper
.
reply_to_string
(
data_buf
)
device
.
log
.
info
(
data_str
)
@
staticmethod
def
pull_file
(
device
,
remote
,
local
,
is_create
=
False
,
...
...
@@ -769,7 +772,7 @@ class HdcHelper:
(
convert_serial
(
device
.
device_sn
),
remote
,
local
))
sock
=
HdcHelper
.
socket
(
host
=
device
.
host
,
port
=
device
.
port
,
timeout
=
DEFAULT_TIMEOUT
)
timeout
=
timeout
)
HdcHelper
.
handle_shake
(
sock
,
device
.
device_sn
)
request
=
HdcHelper
.
form_hdc_request
(
"file recv %s %s"
%
(
local
,
remote
))
...
...
@@ -778,6 +781,7 @@ class HdcHelper:
length
=
struct
.
unpack
(
"!I"
,
reply
)[
0
]
data_buf
=
HdcHelper
.
read
(
sock
,
length
)
data_str
=
HdcHelper
.
reply_to_string
(
data_buf
)
device
.
log
.
info
(
data_str
)
@
staticmethod
def
_install_remote_package
(
device
,
remote_file_path
,
command
):
...
...
@@ -844,6 +848,8 @@ class HdcHelper:
output_flag
=
kwargs
.
get
(
"output_flag"
,
True
)
timeout_msg
=
''
if
(
timeout
/
1000
)
==
300.0
else
\
" with timeout %ss"
%
str
(
timeout
/
1000
)
end_mark
=
kwargs
.
get
(
"end_mark"
,
""
)
read_timeout
=
kwargs
.
get
(
"read_timeout"
,
None
)
if
device
.
usb_type
==
DeviceConnectorType
.
hdc
:
message
=
"%s execute command: hdc shell %s%s"
%
\
(
convert_serial
(
device
.
device_sn
),
command
,
...
...
@@ -856,26 +862,31 @@ class HdcHelper:
HdcHelper
.
handle_shake
(
sock
,
device
.
device_sn
)
request
=
HdcHelper
.
form_hdc_request
(
"shell %s"
%
command
)
HdcHelper
.
write
(
sock
,
request
)
len_buf
=
HdcHelper
.
read
(
sock
,
DATA_UNIT_LENGTH
)
if
len_buf
:
length
=
struct
.
unpack
(
"!I"
,
len_buf
)[
0
]
resp
=
HdcResponse
()
resp
.
okay
=
True
from
xdevice
import
Scheduler
data
=
sock
.
recv
(
SOCK_DATA_MAX
)
while
data
!=
b
''
:
start_time
=
int
(
time
.
time
())
while
True
:
len_buf
=
HdcHelper
.
read
(
sock
,
DATA_UNIT_LENGTH
)
if
len_buf
:
length
=
struct
.
unpack
(
"!I"
,
len_buf
)[
0
]
else
:
break
data
=
sock
.
recv
(
length
)
ret
=
HdcHelper
.
reply_to_string
(
data
)
if
ret
:
if
receiver
:
receiver
.
__read__
(
ret
)
else
:
LOG
.
debug
(
ret
)
if
end_mark
and
end_mark
in
ret
:
break
if
read_timeout
and
\
int
(
time
.
time
())
-
start_time
>
read_timeout
:
break
if
not
Scheduler
.
is_execute
:
raise
ExecuteTerminate
()
data
=
HdcHelper
.
read
(
sock
,
SOCK_DATA_MAX
)
return
resp
except
socket
.
timeout
as
_
:
device
.
log
.
error
(
"%s shell %s timeout[%sS]"
%
(
...
...
@@ -905,6 +916,8 @@ class HdcHelper:
Create an ASCII string preceded by four hex digits.
"""
try
:
if
not
req
.
endswith
(
'
\0
'
):
req
=
"%s
\0
"
%
req
req
=
req
.
encode
(
"utf-8"
)
fmt
=
"!I%ss"
%
len
(
req
)
result
=
struct
.
pack
(
fmt
,
len
(
req
),
req
)
...
...
extension/src/xdevice_extension/_core/testkit/kit.py
浏览文件 @
9a949f93
...
...
@@ -152,15 +152,7 @@ class PushKit(ITestKit):
LOG
.
warning
(
error
,
error_no
=
error
.
error_no
)
continue
remount
(
device
)
device
.
push_file
(
real_src_path
,
dst
)
if
os
.
path
.
isdir
(
real_src_path
):
self
.
add_pushed_dir
(
real_src_path
,
dst
)
else
:
if
device
.
is_directory
(
dst
):
self
.
pushed_file
.
append
(
os
.
path
.
join
(
dst
,
os
.
path
.
basename
(
real_src_path
)))
else
:
self
.
pushed_file
.
append
(
dst
)
device
.
hdc_command
(
"file send {} {}"
.
format
(
real_src_path
,
dst
))
LOG
.
debug
(
"Push file finished from {} to {}"
.
format
(
src
,
dst
))
for
command
in
self
.
post_push
:
run_command
(
device
,
command
)
...
...
@@ -573,12 +565,13 @@ class AppInstallKit(ITestKit):
LOG
.
error
(
"The app file {} does not exist"
.
format
(
app
))
continue
if
app_file
.
endswith
(
".hap"
):
self
.
install_hap
(
device
,
app_file
)
# use app install command directly
device
.
hdc_command
(
"app install {}"
.
format
(
app_file
))
else
:
result
=
device
.
install_package
(
app_file
,
get_install_args
(
device
,
app_file
,
self
.
ex_args
))
if
not
result
.
startswith
(
"Success"
):
if
not
result
or
not
result
.
startswith
(
"Success"
):
raise
AppInstallError
(
"Failed to install %s on %s. Reason:%s"
%
(
app_file
,
device
.
__get_serial__
(),
result
))
...
...
@@ -591,10 +584,9 @@ class AppInstallKit(ITestKit):
app_name
=
get_app_name
(
app
)
if
app_name
:
result
=
device
.
uninstall_package
(
app_name
)
if
not
result
or
not
result
.
startswith
(
"Success"
):
LOG
.
warning
(
"error uninstalling package %s %s"
%
(
device
.
__get_serial__
(),
result
))
device
.
hdc_command
(
"shell bm uninstall -n {}"
.
format
(
app_name
))
time
.
sleep
(
20
)
else
:
LOG
.
warning
(
"Can't find app_name for %s"
%
app
)
if
self
.
is_pri_app
:
...
...
@@ -682,16 +674,9 @@ class AppInstallKit(ITestKit):
def
remount
(
device
):
device
.
enable_hdc_root
()
cmd
=
"target mount"
\
if
device
.
usb_type
==
DeviceConnectorType
.
hdc
else
"remount"
device
.
hdc_command
(
cmd
)
device
.
execute_shell_command
(
"remount"
)
device
.
execute_shell_command
(
"mount -o rw,remount /cust"
)
device
.
execute_shell_command
(
"mount -o rw,remount /product"
)
device
.
execute_shell_command
(
"mount -o rw,remount /hw_product"
)
device
.
execute_shell_command
(
"mount -o rw,remount /version"
)
device
.
execute_shell_command
(
"mount -o rw,remount /%s"
%
"system"
)
def
keep_screen_on
(
device
):
...
...
@@ -735,7 +720,7 @@ def run_command(device, command):
elif
command
.
strip
()
==
"reboot-delay"
:
pass
else
:
stdout
=
device
.
execute_shell_command
(
command
)
stdout
=
device
.
hdc_command
(
"shell {}"
.
format
(
command
)
)
LOG
.
debug
(
"Run command result: %s"
%
(
stdout
if
stdout
else
""
))
return
stdout
...
...
src/xdevice/_core/executor/scheduler.py
浏览文件 @
9a949f93
...
...
@@ -149,7 +149,7 @@ class Scheduler(object):
error_message
=
"%s[%s]"
%
(
str
(
exception
),
error_no
)
\
if
error_no
else
str
(
exception
)
error_no
=
error_no
if
error_no
else
"00000"
LOG
.
exception
(
exception
,
exc_info
=
Fals
e
,
error_no
=
error_no
)
LOG
.
exception
(
exception
,
exc_info
=
Tru
e
,
error_no
=
error_no
)
finally
:
Scheduler
.
_clear_test_dict_source
()
...
...
src/xdevice/_core/utils.py
浏览文件 @
9a949f93
...
...
@@ -137,7 +137,7 @@ def _get_find_proc(find_command, list_command):
return
proc
def
exec_cmd
(
cmd
,
timeout
=
5
*
60
,
error_print
=
True
,
join_result
=
False
):
def
exec_cmd
(
cmd
,
timeout
=
1
*
60
,
error_print
=
True
,
join_result
=
False
):
"""
Executes commands in a new shell. Directing stderr to PIPE.
...
...
@@ -154,6 +154,10 @@ def exec_cmd(cmd, timeout=5 * 60, error_print=True, join_result=False):
"""
sys_type
=
platform
.
system
()
if
isinstance
(
cmd
,
list
):
LOG
.
info
(
"The running command is: {}"
.
format
(
" "
.
join
(
cmd
)))
if
isinstance
(
cmd
,
str
):
LOG
.
info
(
"The running command is: {}"
.
format
(
cmd
))
if
sys_type
==
"Linux"
or
sys_type
==
"Darwin"
:
proc
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
False
,
...
...
@@ -173,7 +177,7 @@ def exec_cmd(cmd, timeout=5 * 60, error_print=True, join_result=False):
return
err
if
err
else
out
except
(
TimeoutError
,
KeyboardInterrupt
,
AttributeError
,
ValueError
,
EOFError
,
IOError
):
EOFError
,
IOError
,
subprocess
.
TimeoutExpired
):
sys_type
=
platform
.
system
()
if
sys_type
==
"Linux"
or
sys_type
==
"Darwin"
:
os
.
killpg
(
proc
.
pid
,
signal
.
SIGTERM
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录