From a42cf97cb07d0cec6fb7fe35d96545c304e60eff Mon Sep 17 00:00:00 2001 From: ybduan Date: Wed, 25 Sep 2024 10:49:56 +0800 Subject: [PATCH] maxbytes_negative: Update max-bytes negative cases 'max-bytes=0' has been forbidden. Update corresponding error info. Signed-off-by: ybduan --- qemu/tests/cfg/rng_maxbytes_period.cfg | 6 +-- qemu/tests/rng_maxbytes_period.py | 51 ++++++++++---------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/qemu/tests/cfg/rng_maxbytes_period.cfg b/qemu/tests/cfg/rng_maxbytes_period.cfg index e6f104fe0e..5344b13bf5 100644 --- a/qemu/tests/cfg/rng_maxbytes_period.cfg +++ b/qemu/tests/cfg/rng_maxbytes_period.cfg @@ -35,13 +35,13 @@ variants: - maxbytes_0: no aarch64 + 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 diff --git a/qemu/tests/rng_maxbytes_period.py b/qemu/tests/rng_maxbytes_period.py index 910cd9dc0c..273bf1b740 100644 --- a/qemu/tests/rng_maxbytes_period.py +++ b/qemu/tests/rng_maxbytes_period.py @@ -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): @@ -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() @@ -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()