Skip to content

Commit 406c2c4

Browse files
committed
test: add integration test for physical counter reset
Add a test to verify the reset of the physical counter on aarch64 VMs. To do this we check registers saved in the snapshot and verify the counter value is less than some reasonably small number we choose. The value is based on the observation of how much cycles it takes for a VM to boot and be snapshotted. The idea is that this value will always be smaller than the actual physical counter on the host. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent c9c3634 commit 406c2c4

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/integration_tests/functional/test_snapshot_basic.py

+51
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import filecmp
66
import logging
77
import os
8+
import platform
89
import re
910
import shutil
1011
import time
1112
from pathlib import Path
1213

1314
import pytest
1415

16+
import host_tools.cargo_build as host
1517
import host_tools.drive as drive_tools
18+
from framework import utils
1619
from framework.microvm import SnapshotType
20+
from framework.properties import global_props
1721
from framework.utils import check_filesystem, check_output
1822
from framework.utils_vsock import (
1923
ECHO_SERVER_PORT,
@@ -540,3 +544,50 @@ def test_vmgenid(guest_kernel_linux_6_1, rootfs, microvm_factory, snapshot_type)
540544

541545
# Update the base for next iteration
542546
base_snapshot = snapshot
547+
548+
549+
# TODO add `global_props.host_os == "amzn2"` condition
550+
# once amazon linux kernels have patches.
551+
@pytest.mark.skipif(
552+
platform.machine() != "aarch64" or global_props.host_linux_version_tpl < (6, 4),
553+
reason="This is aarch64 specific test and should only be run on 6.4 and later kernels",
554+
)
555+
def test_physical_couter_reset_aarch64(uvm_nano):
556+
"""
557+
Test that the CNTPCT_EL0 register is reset on VM boot.
558+
Because we cannot read the CNTVCT_EL0 (Virtual counter)
559+
from python, we assume the smallesd VM will not consume more than
560+
MAX_VALUE cycles to be created and snapshotted. We have to use
561+
this approach because we cannot get host counter value from Python.
562+
"""
563+
vm = uvm_nano
564+
vm.add_net_iface()
565+
vm.start()
566+
567+
snapshot = vm.snapshot_full()
568+
vm.kill()
569+
snap_editor = host.get_binary("snapshot-editor")
570+
571+
cntpct_el0 = hex(0x603000000013DF01)
572+
max_value = 800_000_000
573+
574+
cmd = [
575+
str(snap_editor),
576+
"info-vmstate",
577+
"vcpu-states",
578+
"--vmstate-path",
579+
str(snapshot.vmstate),
580+
]
581+
_, stdout, _ = utils.check_output(cmd)
582+
583+
# The output will look like this:
584+
# kvm_mp_state: 0x0
585+
# mpidr: 0x80000000
586+
# 0x6030000000100000 0x0000000e0
587+
# 0x6030000000100002 0xffff00fe33c0
588+
for line in stdout.splitlines():
589+
parts = line.split()
590+
if len(parts) == 2:
591+
reg_id, reg_value = parts
592+
if reg_id == cntpct_el0:
593+
assert int(reg_value, 16) < max_value

0 commit comments

Comments
 (0)