Skip to content

Commit 2b3ddd7

Browse files
committed
test: add intergration test for physical counter reset
Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent e13a1e9 commit 2b3ddd7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/integration_tests/functional/test_snapshot_basic.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Basic tests scenarios for snapshot save/restore."""
44

5+
import platform
56
import filecmp
67
import logging
78
import os
@@ -11,7 +12,9 @@
1112
from pathlib import Path
1213

1314
import pytest
15+
from framework import utils
1416

17+
import host_tools.cargo_build as host
1518
import host_tools.drive as drive_tools
1619
from framework.microvm import SnapshotType
1720
from framework.utils import check_filesystem, check_output
@@ -25,6 +28,7 @@
2528
make_host_port_path,
2629
start_guest_echo_server,
2730
)
31+
from framework.properties import global_props
2832

2933
# Kernel emits this message when it resumes from a snapshot with VMGenID device
3034
# present
@@ -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+
@pytest.mark.skipif(
550+
platform.machine() != "aarch64"
551+
or not global_props.is_ec2
552+
or global_props.host_linux_version_tpl < (6, 4),
553+
reason="This is aarch64 specific test and should only be run on ",
554+
)
555+
def test_physical_couter_reset_aarch64(uvm_nano, microvm_factory):
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+
s = line.split(" ")
590+
if len(s) == 2:
591+
reg_id, reg_value = line.split(" ")
592+
if reg_id == CNTPCT_EL0:
593+
assert int(reg_value, 16) < MAX_VALUE

0 commit comments

Comments
 (0)