未验证 提交 f0469ab0 编写于 作者: Q Qianqian Zhu 提交者: GitHub

Merge pull request #1421 from huangyum/balloon_1591189

balloon_stress: improve test steps for background stress test 
import logging
import random
import re
from virttest import utils_misc
from virttest import utils_test
......@@ -22,17 +23,18 @@ def run(test, params, env):
:param env: Dictionary with test environment.
"""
def run_stress(test, params, env, vm):
def check_bg_running():
"""
Run stress in background
Check the background test status in guest.
:return: return True if find the process name; otherwise False
"""
while True:
if params['os_type'] == 'windows':
utils_test.run_virt_sub_test(test, params, env,
params.get("stress_test"))
else:
stress_bg = utils_test.VMStress(vm, "stress", params)
stress_bg.load_stress_tool()
if params['os_type'] == 'windows':
list_cmd = params.get("list_cmd", "wmic process get name")
output = session.cmd_output_safe(list_cmd, timeout=60)
process = re.findall("mplayer", output, re.M | re.I)
return bool(process)
else:
return stress_bg.app_running()
error_context.context("Boot guest with balloon device", logging.info)
vm = env.get_vm(params["main_vm"])
......@@ -51,8 +53,16 @@ def run(test, params, env):
balloon_test = BallooningTestLinux(test, params, env)
error_context.context("Run stress background", logging.info)
bg = utils_misc.InterruptedThread(run_stress, (test, params, env, vm))
bg.start()
stress_test = params.get("stress_test")
if params['os_type'] == 'windows':
utils_test.run_virt_sub_test(test, params, env, stress_test)
if not utils_misc.wait_for(check_bg_running, first=2.0,
text="wait for stress app to start",
step=1.0, timeout=60):
test.error("Run stress background failed")
else:
stress_bg = utils_test.VMStress(vm, "stress", params)
stress_bg.load_stress_tool()
repeat_times = int(params.get("repeat_times", 1000))
min_sz, max_sz = balloon_test.get_memory_boundary()
......@@ -62,7 +72,7 @@ def run(test, params, env):
for i in range(1, int(repeat_times+1)):
logging.info("repeat times: %d" % i)
balloon_test.balloon_memory(int(random.uniform(min_sz, max_sz)))
if not bg.is_alive():
if not check_bg_running():
test.error("Background stress process is not alive")
finally:
if session:
......
......@@ -14,22 +14,12 @@
balloon_timeout = 240
check_setup_events = balloon_test_setup_ready
Windows:
x86_64:
program_files = "%ProgramFiles(x86)%"
i386:
program_files = "%ProgramFiles%"
stress_test = win_video_play
#Disable first startup guide for windows media player
wmplayer_reg_cmd = "reg add HKLM\SOFTWARE\Policies\Microsoft\WindowsMediaPlayer /v GroupPrivacyAcceptance /t REG_DWORD /f /d 00000001"
wmplayer_path = "${program_files}\Windows Media Player\wmplayer.exe"
#Install kmplayer if wmplayer is not installed default
kmplayer_install_cmd = "start /wait WIN_UTILS:\kmplayer\%s\KMPlayer-setup.exe /SP- /VERYSILENT"
kmplayer_path = "${program_files}\KMPlayer\kmplayer.exe"
mplayer_path = "WIN_UTILS:\mplayer.exe"
play_video_cmd = "start /MIN %s %s -loop 0 -fs"
target_process = mplayer.exe
video_url = http://fileshare.com/Peppa_Pig_39_The_Tree_House.avi
play_video_cmd = '"%s" "%s" /play /fullscreen'
guest_alias = "Win2008-sp2-32:2k8\x86,Win2008-sp2-64:2k8\amd64,Win2008-r2-64:2k8\amd64,Win2012-64:2k12\amd64,Win2012-64r2:2k12\amd64"
driver_name = "balloon"
time_for_video = 600
free_mem_cmd = wmic os get FreePhysicalMemory
default_memory = ${mem}
check_guest_bsod = yes
......
......@@ -8,22 +8,11 @@
balloon_dev_devid = balloon0
balloon_dev_add_bus = yes
Windows:
driver_name = "balloon"
stress_test = win_video_play
mplayer_path = "WIN_UTILS:\mplayer.exe"
play_video_cmd = "start /MIN %s %s -loop 0 -fs"
video_url = http://FILESHARE.COM/pub/section2/kvmauto/video/big_buck_bunny_480p_stereo.avi
x86_64:
program_files = "%ProgramFiles(x86)%"
i386:
program_files = "%ProgramFiles%"
driver_name = "balloon"
#Disable first startup guide for windows media player
wmplayer_reg_cmd = "reg add HKLM\SOFTWARE\Policies\Microsoft\WindowsMediaPlayer /v GroupPrivacyAcceptance /t REG_DWORD /f /d 00000001"
wmplayer_path = "${program_files}\Windows Media Player\wmplayer.exe"
#Install kmplayer if wmplayer is not installed default
kmplayer_install_cmd = "start /wait WIN_UTILS:\kmplayer\%s\KMPlayer-setup.exe /SP- /VERYSILENT"
kmplayer_path = "${program_files}\KMPlayer\kmplayer.exe"
play_video_cmd = '"%s" "%s" /play /fullscreen'
time_for_video = 1200
guest_alias = "Win2008-sp2-32:2k8\x86,Win2008-sp2-64:2k8\amd64,Win2008-r2-64:2k8\amd64,Win2012-64:2k12\amd64,Win2012-64r2:2k12\amd64"
Linux:
# Use a low stress to make sure guest can response during stress
stress_args = "--cpu 4 --io 4 --vm 2 --vm-bytes 256M"
......@@ -107,20 +107,10 @@
free_mem_cmd = wmic os get FreePhysicalMemory
session_cmd_timeout = 240
stress_test = win_video_play
x86_64:
program_files = "%ProgramFiles(x86)%"
i386:
program_files = "%ProgramFiles%"
#Disable first startup guide for windows media player
wmplayer_reg_cmd = "reg add HKLM\SOFTWARE\Policies\Microsoft\WindowsMediaPlayer /v GroupPrivacyAcceptance /t REG_DWORD /f /d 00000001"
wmplayer_path = "${program_files}\Windows Media Player\wmplayer.exe"
#Install kmplayer if wmplayer is not installed default
kmplayer_install_cmd = "start /wait WIN_UTILS:\kmplayer\%s\KMPlayer-setup.exe /SP- /VERYSILENT"
kmplayer_path = "${program_files}\KMPlayer\kmplayer.exe"
mplayer_path = "WIN_UTILS:\mplayer.exe"
play_video_cmd = "start /MIN %s %s -loop 0 -fs"
video_url = http://fileshare.com/Peppa_Pig_39_The_Tree_House.avi
play_video_cmd = '"%s" "%s" /play /fullscreen'
target_process = \w+mplayer.exe
guest_alias = "Win2008-sp2-32:2k8\x86,Win2008-sp2-64:2k8\amd64,Win2008-r2-64:2k8\amd64,Win2012-64:2k12\amd64,Win2012-64r2:2k12\amd64"
target_process = mplayer.exe
- with_viorng:
no no_virtio_rng
driver_name = viorng
......
......@@ -2,16 +2,7 @@
type = win_video_play
only Windows
image_snapshot = yes
x86_64:
program_files = "%ProgramFiles(x86)%"
i386:
program_files = "%ProgramFiles%"
#Disable first startup guide for windows media player
wmplayer_reg_cmd = "reg add HKLM\SOFTWARE\Policies\Microsoft\WindowsMediaPlayer /v GroupPrivacyAcceptance /t REG_DWORD /f /d 00000001"
wmplayer_path = "${program_files}\Windows Media Player\wmplayer.exe"
#Install kmplayer if wmplayer is not installed default
kmplayer_install_cmd = "start /wait WIN_UTILS:\kmplayer\%s\KMPlayer-setup.exe /SP- /VERYSILENT"
kmplayer_path = "${program_files}\KMPlayer\kmplayer.exe"
mplayer_path = "WIN_UTILS:\mplayer.exe"
play_video_cmd = "start /MIN %s %s -loop 0 -fs"
video_url = http://fileshare.com/Peppa_Pig_39_The_Tree_House.avi
play_video_cmd = '"%s" "%s" /play /fullscreen'
guest_alias = "Win2008-sp2-32:2k8\x86,Win2008-sp2-64:2k8\amd64,Win2008-r2-64:2k8\amd64,Win2012-64:2k12\amd64,Win2012-64r2:2k12\amd64"
play_video_duration = 300
......@@ -11,87 +11,30 @@ def run(test, params, env):
"""
Run video in Windows guest
1) Boot guest with the device.
2) Check if wmplayer is installed default
3) Install kmplayer if wmplayer is not installed
4) Run video
2) Run video by mplayer
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def check_wmplayer_installed(session):
"""
Check if wmplayer is installed
:param session: VM session
:return: return wmplayer.exe path
"""
error_context.context("Check if wmplayer is installed", logging.info)
install_path = params.get("wmplayer_path")
check_cmd = 'dir "%s"|findstr /I wmplayer'
check_cmd = params.get("wmplayer_check_cmd", check_cmd) % install_path
if session.cmd_status(check_cmd) == 0:
return install_path
def check_kmplayer_installed(session):
"""
Check if kmplayer is installed
:param session: VM session
:return: return kmplayer.exe path
"""
error_context.context("Check if kmplayer is installed", logging.info)
install_path = params.get("kmplayer_path")
check_cmd = 'dir "%s"|findstr /I kmplayer'
check_cmd = params.get("kmplayer_check_cmd", check_cmd) % install_path
if session.cmd_status(check_cmd) != 0:
kmplayer_install(session)
return install_path
def kmplayer_install(session):
"""
Install kmplayer
:param session: VM session
"""
error_context.context("Install kmplayer ...", logging.info)
guest_name = params["guest_name"]
alias_map = params["guest_alias"]
guest_list = dict([x.split(":") for x in alias_map.split(",")])
guest_name = guest_list[guest_name]
install_cmd = params["kmplayer_install_cmd"] % guest_name
install_cmd = utils_misc.set_winutils_letter(session, install_cmd)
s, o = session.cmd_status_output(install_cmd, timeout=240)
if s != 0:
raise exceptions.TestError("Failed to install kmplayer %s" % o)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
timeout = float(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=timeout)
wmplayer = check_wmplayer_installed(session)
if wmplayer:
video_player = wmplayer
if params.get("wmplayer_reg_cmd"):
logging.info("Update regedit")
session.cmd(params.get("wmplayer_reg_cmd"))
else:
kmplayer = check_kmplayer_installed(session)
video_player = kmplayer
video_player = utils_misc.set_winutils_letter(session,
params["mplayer_path"])
video_url = params["video_url"]
play_video_cmd = params["play_video_cmd"] % (video_player, video_url)
error_context.context("Play video", logging.info)
try:
session.cmd(play_video_cmd, timeout=240)
time.sleep(float(params.get("time_for_video", 240)))
except Exception as details:
raise exceptions.TestFail(details)
finally:
logging.info("Stop video")
play_video_duration = params.get("play_video_duration")
if play_video_duration:
time.sleep(int(play_video_duration))
session.cmd("taskkill /IM %s /F" % video_player,
ignore_all_errors=True)
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册