Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
9925cc43
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9925cc43
编写于
1月 02, 2018
作者:
A
Amador Pahim
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'clebergnu-fddrainer'
Signed-off-by:
N
Amador Pahim
<
apahim@redhat.com
>
上级
fe8f59c2
4aa62803
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
19 addition
and
24 deletion
+19
-24
avocado/utils/process.py
avocado/utils/process.py
+14
-19
selftests/unit/test_utils_process.py
selftests/unit/test_utils_process.py
+5
-5
未找到文件。
avocado/utils/process.py
浏览文件 @
9925cc43
...
@@ -30,10 +30,7 @@ import subprocess
...
@@ -30,10 +30,7 @@ import subprocess
import
threading
import
threading
import
time
import
time
try
:
from
io
import
BytesIO
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
from
.
import
gdb
from
.
import
gdb
from
.
import
runtime
from
.
import
runtime
...
@@ -326,12 +323,11 @@ class FDDrainer(object):
...
@@ -326,12 +323,11 @@ class FDDrainer(object):
"""
"""
self
.
fd
=
fd
self
.
fd
=
fd
self
.
name
=
name
self
.
name
=
name
self
.
data
=
String
IO
()
self
.
data
=
Bytes
IO
()
# TODO: check if, when the process finishes, the FD doesn't
# TODO: check if, when the process finishes, the FD doesn't
# automatically close. This may be used as the detection
# automatically close. This may be used as the detection
# instead.
# instead.
self
.
_result
=
result
self
.
_result
=
result
self
.
_lock
=
threading
.
Lock
()
self
.
_thread
=
None
self
.
_thread
=
None
self
.
_logger
=
logger
self
.
_logger
=
logger
self
.
_logger_prefix
=
logger_prefix
self
.
_logger_prefix
=
logger_prefix
...
@@ -343,7 +339,7 @@ class FDDrainer(object):
...
@@ -343,7 +339,7 @@ class FDDrainer(object):
"""
"""
Read from fd, storing and optionally logging the output
Read from fd, storing and optionally logging the output
"""
"""
bfr
=
''
bfr
=
b
''
while
True
:
while
True
:
if
self
.
_ignore_bg_processes
:
if
self
.
_ignore_bg_processes
:
has_io
=
select
.
select
([
self
.
fd
],
[],
[],
1
)[
0
]
has_io
=
select
.
select
([
self
.
fd
],
[],
[],
1
)[
0
]
...
@@ -354,19 +350,18 @@ class FDDrainer(object):
...
@@ -354,19 +350,18 @@ class FDDrainer(object):
# Don't read unless there are new data available
# Don't read unless there are new data available
continue
continue
tmp
=
os
.
read
(
self
.
fd
,
8192
)
tmp
=
os
.
read
(
self
.
fd
,
8192
)
if
tmp
==
''
:
if
not
tmp
:
break
break
with
self
.
_lock
:
self
.
data
.
write
(
tmp
)
self
.
data
.
write
(
tmp
)
if
self
.
_verbose
:
if
self
.
_verbose
:
bfr
+=
tmp
bfr
+=
tmp
if
tmp
.
endswith
(
'
\n
'
):
if
tmp
.
endswith
(
b
'
\n
'
):
for
line
in
bfr
.
splitlines
():
for
line
in
bfr
.
splitlines
():
if
self
.
_logger
is
not
None
:
if
self
.
_logger
is
not
None
:
self
.
_logger
.
debug
(
self
.
_logger_prefix
,
line
)
self
.
_logger
.
debug
(
self
.
_logger_prefix
,
line
)
if
self
.
_stream_logger
is
not
None
:
if
self
.
_stream_logger
is
not
None
:
self
.
_stream_logger
.
debug
(
'%s
\n
'
,
line
)
self
.
_stream_logger
.
debug
(
'%s
\n
'
,
line
)
bfr
=
''
bfr
=
b
''
# Write the rest of the bfr unfinished by \n
# Write the rest of the bfr unfinished by \n
if
self
.
_verbose
and
bfr
:
if
self
.
_verbose
and
bfr
:
for
line
in
bfr
.
splitlines
():
for
line
in
bfr
.
splitlines
():
...
...
selftests/unit/test_utils_process.py
浏览文件 @
9925cc43
...
@@ -238,13 +238,13 @@ class FDDrainerTests(unittest.TestCase):
...
@@ -238,13 +238,13 @@ class FDDrainerTests(unittest.TestCase):
result
=
process
.
CmdResult
()
result
=
process
.
CmdResult
()
fd_drainer
=
process
.
FDDrainer
(
read_fd
,
result
,
"test"
)
fd_drainer
=
process
.
FDDrainer
(
read_fd
,
result
,
"test"
)
fd_drainer
.
start
()
fd_drainer
.
start
()
for
content
in
(
"foo"
,
"bar"
,
"baz"
,
"foo
\n
bar
\n
baz
\n\n
"
):
for
content
in
(
b
"foo"
,
b
"bar"
,
b
"baz"
,
b
"foo
\n
bar
\n
baz
\n\n
"
):
os
.
write
(
write_fd
,
content
)
os
.
write
(
write_fd
,
content
)
os
.
write
(
write_fd
,
"finish"
)
os
.
write
(
write_fd
,
b
"finish"
)
os
.
close
(
write_fd
)
os
.
close
(
write_fd
)
fd_drainer
.
flush
()
fd_drainer
.
flush
()
self
.
assertEqual
(
fd_drainer
.
data
.
getvalue
(),
self
.
assertEqual
(
fd_drainer
.
data
.
getvalue
(),
"foobarbazfoo
\n
bar
\n
baz
\n\n
finish"
)
b
"foobarbazfoo
\n
bar
\n
baz
\n\n
finish"
)
def
test_log
(
self
):
def
test_log
(
self
):
class
CatchHandler
(
logging
.
NullHandler
):
class
CatchHandler
(
logging
.
NullHandler
):
...
@@ -268,11 +268,11 @@ class FDDrainerTests(unittest.TestCase):
...
@@ -268,11 +268,11 @@ class FDDrainerTests(unittest.TestCase):
fd_drainer
=
process
.
FDDrainer
(
read_fd
,
result
,
"test"
,
fd_drainer
=
process
.
FDDrainer
(
read_fd
,
result
,
"test"
,
logger
=
logger
,
verbose
=
True
)
logger
=
logger
,
verbose
=
True
)
fd_drainer
.
start
()
fd_drainer
.
start
()
os
.
write
(
write_fd
,
"should go to the log
\n
"
)
os
.
write
(
write_fd
,
b
"should go to the log
\n
"
)
os
.
close
(
write_fd
)
os
.
close
(
write_fd
)
fd_drainer
.
flush
()
fd_drainer
.
flush
()
self
.
assertEqual
(
fd_drainer
.
data
.
getvalue
(),
self
.
assertEqual
(
fd_drainer
.
data
.
getvalue
(),
"should go to the log
\n
"
)
b
"should go to the log
\n
"
)
self
.
assertTrue
(
handler
.
caught_record
)
self
.
assertTrue
(
handler
.
caught_record
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录