Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxbytes_negative: Update max-bytes negative cases #4166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions qemu/tests/cfg/rng_maxbytes_period.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
variants:
- maxbytes_0:
no aarch64
required_qemu = [9.0.0,)
not_preprocess = yes
max-bytes_virtio-rng = 0
read_rng_timeout = 10
read_rng_cmd = "dd if=/dev/hwrng of=/dev/null bs=1 count=1"
expected_error_info = "'max-bytes' parameter must be positive, and less than 2^63"
- maxbytes_negative:
not_preprocess = yes
max-bytes_virtio-rng = -1
expected_error_info = "'max-bytes' parameter must be non-negative, and less than 2^63"
expected_error_info = "'max-bytes' parameter must be positive, and less than 2^63"
- period_0:
not_preprocess = yes
period_virtio-rng = 0
Expand Down
64 changes: 27 additions & 37 deletions qemu/tests/rng_maxbytes_period.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re

from aexpect.exceptions import ShellTimeoutError
from virttest import env_process, error_context, utils_misc, virt_vm


Expand Down Expand Up @@ -34,23 +33,22 @@ def _is_rngd_running():
if not max_bytes and not period:
test.error("Please specify the expected max-bytes and/or period.")
if not max_bytes or not period:
if max_bytes != "0":
error_info = params["expected_error_info"]
try:
env_process.process(
test,
params,
env,
env_process.preprocess_image,
env_process.preprocess_vm,
error_info = params["expected_error_info"]
try:
env_process.process(
test,
params,
env,
env_process.preprocess_image,
env_process.preprocess_vm,
)
except virt_vm.VMCreateError as e:
if error_info not in e.output:
test.fail(
"Expected error info '%s' is not reported, "
"output: %s" % (error_info, e.output)
)
except virt_vm.VMCreateError as e:
if error_info not in e.output:
test.fail(
"Expected error info '%s' is not reported, "
"output: %s" % (error_info, e.output)
)
return
return

vm = env.get_vm(params["main_vm"])
vm.verify_alive()
Expand All @@ -68,25 +66,17 @@ def _is_rngd_running():
if status:
test.error(output)

if max_bytes == "0":
try:
s, o = session.cmd_status_output(read_rng_cmd, timeout=read_rng_timeout)
except ShellTimeoutError:
pass
else:
test.fail("Unexpected dd result, status: %s, output: %s" % (s, o))
else:
s, o = session.cmd_status_output(read_rng_cmd, timeout=read_rng_timeout)
if s:
test.error(o)
test.log.info(o)
data_rate = re.search(r"\s(\d+\.\d+) kB/s", o, re.M)
expected_data_rate = float(params["expected_data_rate"])
if float(data_rate.group(1)) > expected_data_rate * 1.1:
test.error(
"Read data rate is not as expected. "
"data rate: %s kB/s, max-bytes: %s, period: %s"
% (data_rate.group(1), max_bytes, period)
)
s, o = session.cmd_status_output(read_rng_cmd, timeout=read_rng_timeout)
if s:
test.error(o)
test.log.info(o)
data_rate = re.search(r"\s(\d+\.\d+) kB/s", o, re.M)
expected_data_rate = float(params["expected_data_rate"])
if float(data_rate.group(1)) > expected_data_rate * 1.1:
test.error(
"Read data rate is not as expected. "
"data rate: %s kB/s, max-bytes: %s, period: %s"
% (data_rate.group(1), max_bytes, period)
)

session.close()
Loading