Skip to content

Commit 2bc963f

Browse files
committed
fix(test_rng): check virtio_rng is not available through sysfs
On guest 6.1 on ARM instances we have a new paravirtualized SMCC TRNG device, which breaks the assumptions of test_rng_not_present. This patch changes the test to read the list of available hwrng devices and assert virtio_rng is not preset. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent 8aa5034 commit 2bc963f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

tests/integration_tests/functional/test_rng.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66

77
from framework.utils import check_entropy
8+
from host_tools.network import SSHConnection
89

910

1011
@pytest.fixture(params=[None])
@@ -22,6 +23,15 @@ def uvm_with_rng(uvm_plain, request):
2223
return uvm
2324

2425

26+
def list_rng_available(ssh_connection: SSHConnection) -> list[str]:
27+
"""Returns a list of rng devices available in the VM"""
28+
return (
29+
ssh_connection.check_output("cat /sys/class/misc/hw_random/rng_available")
30+
.stdout.strip()
31+
.split()
32+
)
33+
34+
2535
def test_rng_not_present(uvm_nano):
2636
"""
2737
Test a guest microVM *without* an entropy device and ensure that
@@ -32,15 +42,9 @@ def test_rng_not_present(uvm_nano):
3242
vm.add_net_iface()
3343
vm.start()
3444

35-
# If the guest kernel has been built with the virtio-rng module
36-
# the device should exist in the guest filesystem but we should
37-
# not be able to get random numbers out of it.
38-
cmd = "test -e /dev/hwrng"
39-
vm.ssh.check_output(cmd)
40-
41-
cmd = "dd if=/dev/hwrng of=/dev/null bs=10 count=1"
42-
ecode, _, _ = vm.ssh.run(cmd)
43-
assert ecode == 1
45+
assert not any(
46+
rng.startswith("virtio_rng") for rng in list_rng_available(vm.ssh)
47+
), "virtio_rng device should not be available in the uvm"
4448

4549

4650
def test_rng_present(uvm_with_rng):

0 commit comments

Comments
 (0)