|
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 | """Basic tests scenarios for snapshot save/restore.""" |
4 | 4 |
|
| 5 | +import platform |
5 | 6 | import filecmp |
6 | 7 | import logging |
7 | 8 | import os |
|
11 | 12 | from pathlib import Path |
12 | 13 |
|
13 | 14 | import pytest |
| 15 | +from framework import utils |
14 | 16 |
|
| 17 | +import host_tools.cargo_build as host |
15 | 18 | import host_tools.drive as drive_tools |
16 | 19 | from framework.microvm import SnapshotType |
17 | 20 | from framework.utils import check_filesystem, check_output |
|
25 | 28 | make_host_port_path, |
26 | 29 | start_guest_echo_server, |
27 | 30 | ) |
| 31 | +from framework.properties import global_props |
28 | 32 |
|
29 | 33 | # Kernel emits this message when it resumes from a snapshot with VMGenID device |
30 | 34 | # present |
@@ -540,3 +544,50 @@ def test_vmgenid(guest_kernel_linux_6_1, rootfs, microvm_factory, snapshot_type) |
540 | 544 |
|
541 | 545 | # Update the base for next iteration |
542 | 546 | 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