Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
d863c0da
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,发现更多精彩内容 >>
提交
d863c0da
编写于
1月 28, 2016
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #991 from clebergnu/avoid_fork_bomb_v4
avocado.main(): avoid an infinite fork loop bomb [v4]
上级
457cb58c
08103fb4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
1 deletion
+100
-1
avocado/core/job.py
avocado/core/job.py
+10
-0
selftests/functional/test_loader.py
selftests/functional/test_loader.py
+90
-1
未找到文件。
avocado/core/job.py
浏览文件 @
d863c0da
...
...
@@ -540,6 +540,16 @@ class TestProgram(object):
"""
def
__init__
(
self
):
# Avoid fork loop/bomb when running a test via avocado.main() that
# calls avocado.main() itself
if
os
.
environ
.
get
(
'AVOCADO_STANDALONE_IN_MAIN'
,
False
):
sys
.
stderr
.
write
(
'AVOCADO_STANDALONE_IN_MAIN environment variable '
'found. This means that this code is being '
'called recursively. Exiting to avoid an infinite'
' fork loop.
\n
'
)
sys
.
exit
(
exit_codes
.
AVOCADO_FAIL
)
os
.
environ
[
'AVOCADO_STANDALONE_IN_MAIN'
]
=
'True'
self
.
defaultTest
=
sys
.
argv
[
0
]
self
.
progName
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
self
.
parseArgs
(
sys
.
argv
[
1
:])
...
...
selftests/functional/test_loader.py
浏览文件 @
d863c0da
import
os
import
sys
import
subprocess
import
time
import
tempfile
import
shutil
import
signal
if
sys
.
version_info
[:
2
]
==
(
2
,
6
):
import
unittest2
as
unittest
else
:
import
unittest
from
avocado.core
import
exit_codes
from
avocado.utils
import
script
from
avocado.utils
import
process
...
...
@@ -82,7 +85,6 @@ if __name__ == "__main__":
main()
"""
NOT_A_TEST
=
"""
def hello():
print('Hello World!')
...
...
@@ -100,6 +102,40 @@ SIMPLE_TEST = """#!/bin/sh
true
"""
AVOCADO_SIMPLE_PYTHON_LIKE_MULTIPLE_FILES
=
"""#!/usr/bin/env python
# A simple test (executable bit set when saved to file) that looks like
# an Avocado instrumented test, with base class on separate file
from avocado import Test
from avocado import main
from test2 import *
class BasicTestSuite(SuperTest):
def test1(self):
self.xxx()
self.assertTrue(True)
if __name__ == '__main__':
main()
"""
AVOCADO_SIMPLE_PYTHON_LIKE_MULTIPLE_FILES_LIB
=
"""
#!/usr/bin/python
from avocado import Test
class SuperTest(Test):
def xxx(self):
print "ahoj"
"""
AVOCADO_TEST_SIMPLE_USING_MAIN
=
"""#!/usr/bin/env python
from avocado import main
if __name__ == "__main__":
main()
"""
class
LoaderTestFunctional
(
unittest
.
TestCase
):
...
...
@@ -117,6 +153,18 @@ class LoaderTestFunctional(unittest.TestCase):
self
.
assertIn
(
'%s: %s'
%
(
exp_str
,
count
),
result
.
stdout
)
test_script
.
remove
()
def
_run_with_timeout
(
self
,
cmd_line
,
timeout
):
current_time
=
time
.
time
()
deadline
=
current_time
+
timeout
test_process
=
subprocess
.
Popen
(
cmd_line
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
preexec_fn
=
os
.
setsid
)
while
not
test_process
.
poll
():
if
time
.
time
()
>
deadline
:
os
.
killpg
(
os
.
getpgid
(
test_process
.
pid
),
signal
.
SIGKILL
)
self
.
fail
(
"Failed to run test under %s seconds"
%
timeout
)
time
.
sleep
(
0.05
)
self
.
assertEquals
(
test_process
.
returncode
,
exit_codes
.
AVOCADO_TESTS_FAIL
)
def
test_simple
(
self
):
self
.
_test
(
'simpletest.sh'
,
SIMPLE_TEST
,
'SIMPLE'
,
0775
)
...
...
@@ -161,6 +209,47 @@ class LoaderTestFunctional(unittest.TestCase):
def
test_load_not_a_test_not_exec
(
self
):
self
.
_test
(
'notatest.py'
,
NOT_A_TEST
,
'NOT_A_TEST'
)
def
test_runner_simple_python_like_multiple_files
(
self
):
mylib
=
script
.
TemporaryScript
(
'test2.py'
,
AVOCADO_SIMPLE_PYTHON_LIKE_MULTIPLE_FILES_LIB
,
'avocado_simpletest_functional'
,
0644
)
mylib
.
save
()
mytest
=
script
.
Script
(
os
.
path
.
join
(
os
.
path
.
dirname
(
mylib
.
path
),
'test.py'
),
AVOCADO_SIMPLE_PYTHON_LIKE_MULTIPLE_FILES
)
os
.
chdir
(
basedir
)
mytest
.
save
()
cmd_line
=
"./scripts/avocado list -V %s"
%
mytest
result
=
process
.
run
(
cmd_line
)
self
.
assertIn
(
'SIMPLE: 1'
,
result
.
stdout
)
# job should be able to finish under 5 seconds. If this fails, it's
# possible that we hit the "simple test fork bomb" bug
cmd_line
=
[
'./scripts/avocado'
,
'run'
,
'--sysinfo=off'
,
'--job-results-dir'
,
"%s"
%
self
.
tmpdir
,
"%s"
%
mytest
]
self
.
_run_with_timeout
(
cmd_line
,
5
)
def
test_simple_using_main
(
self
):
mytest
=
script
.
TemporaryScript
(
"simple_using_main.py"
,
AVOCADO_TEST_SIMPLE_USING_MAIN
,
'avocado_simpletest_functional'
)
mytest
.
save
()
os
.
chdir
(
basedir
)
# job should be able to finish under 5 seconds. If this fails, it's
# possible that we hit the "simple test fork bomb" bug
cmd_line
=
[
'./scripts/avocado'
,
'run'
,
'--sysinfo=off'
,
'--job-results-dir'
,
"%s"
%
self
.
tmpdir
,
"%s"
%
mytest
]
self
.
_run_with_timeout
(
cmd_line
,
5
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录