Skip to content

Commit

Permalink
Merge pull request #4166 from ybduan/maxbytes_negative_tests
Browse files Browse the repository at this point in the history
maxbytes_negative: Update max-bytes negative cases
  • Loading branch information
YongxueHong authored Nov 19, 2024
2 parents 2d0ef5e + c26849b commit 7986f76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
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()

0 comments on commit 7986f76

Please sign in to comment.