Skip to content

Commit 40a57fc

Browse files
committed
fix(test_rng): ensure virtio_rng is the current device used by hwrng
ARM Uvm with 6.1 kernel have an additional SMCCC TRNG device which is paravirtualized by KVM. We need to ensure we are testing the virtio-rng device, which is the one picked up by default by the kernel, if available. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 2bc963f commit 40a57fc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/integration_tests/functional/test_rng.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ def list_rng_available(ssh_connection: SSHConnection) -> list[str]:
3232
)
3333

3434

35+
def get_rng_current(ssh_connection: SSHConnection) -> str:
36+
"""Returns the current rng device used by hwrng"""
37+
return ssh_connection.check_output(
38+
"cat /sys/class/misc/hw_random/rng_current"
39+
).stdout.strip()
40+
41+
42+
def assert_virtio_rng_is_current_hwrng_device(ssh_connection: SSHConnection):
43+
"""Asserts that virtio_rng is the current device used by hwrng"""
44+
# we expect something like virtio_rng.0
45+
assert get_rng_current(ssh_connection).startswith(
46+
"virtio_rng"
47+
), "virtio_rng device should be the current used by hwrng"
48+
49+
3550
def test_rng_not_present(uvm_nano):
3651
"""
3752
Test a guest microVM *without* an entropy device and ensure that
@@ -54,6 +69,7 @@ def test_rng_present(uvm_with_rng):
5469
"""
5570

5671
vm = uvm_with_rng
72+
assert_virtio_rng_is_current_hwrng_device(vm.ssh)
5773
check_entropy(vm.ssh)
5874

5975

@@ -64,13 +80,15 @@ def test_rng_snapshot(uvm_with_rng, microvm_factory):
6480
"""
6581

6682
vm = uvm_with_rng
83+
assert_virtio_rng_is_current_hwrng_device(vm.ssh)
6784
check_entropy(vm.ssh)
6885
snapshot = vm.snapshot_full()
6986

7087
new_vm = microvm_factory.build()
7188
new_vm.spawn()
7289
new_vm.restore_from_snapshot(snapshot, resume=True)
7390
new_vm.wait_for_up()
91+
assert_virtio_rng_is_current_hwrng_device(new_vm.ssh)
7492
check_entropy(new_vm.ssh)
7593

7694

@@ -203,6 +221,7 @@ def test_rng_bw_rate_limiter(uvm_with_rng):
203221

204222
expected_kbps = size / refill_time
205223

224+
assert_virtio_rng_is_current_hwrng_device(vm.ssh)
206225
# Check the rate limiter using a request size equal to the size
207226
# of the token bucket.
208227
_check_entropy_rate_limited(vm.ssh, size, expected_kbps)

0 commit comments

Comments
 (0)