Skip to content

Commit

Permalink
maxbytes_negative: Update max-bytes negative cases
Browse files Browse the repository at this point in the history
1. 'max-bytes=0' setting is no longer allowed by the latest QEMU.
Error prompt will be generated when 'max-bytes' is set to 0.
2. Update corresponding error info.

Signed-off-by: ybduan <[email protected]>
  • Loading branch information
ybduan committed Nov 13, 2024
1 parent 8c83d64 commit e9912ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 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
not_preprocess = yes
required_qemu = [9.0.0,)
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
51 changes: 20 additions & 31 deletions qemu/tests/rng_maxbytes_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from virttest import virt_vm
from virttest import utils_misc

from aexpect.exceptions import ShellTimeoutError


@error_context.context_aware
def run(test, params, env):
Expand Down Expand Up @@ -37,17 +35,16 @@ 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)
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
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))
return

vm = env.get_vm(params["main_vm"])
vm.verify_alive()
Expand All @@ -66,23 +63,15 @@ 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 e9912ba

Please sign in to comment.