|
5 | 5 | import filecmp
|
6 | 6 | import logging
|
7 | 7 | import os
|
| 8 | +import platform |
8 | 9 | import re
|
9 | 10 | import shutil
|
10 | 11 | import time
|
11 | 12 | from pathlib import Path
|
12 | 13 |
|
13 | 14 | import pytest
|
14 | 15 |
|
| 16 | +import host_tools.cargo_build as host |
15 | 17 | import host_tools.drive as drive_tools
|
| 18 | +from framework import utils |
16 | 19 | from framework.microvm import SnapshotType
|
| 20 | +from framework.properties import global_props |
17 | 21 | from framework.utils import check_filesystem, check_output
|
18 | 22 | from framework.utils_vsock import (
|
19 | 23 | ECHO_SERVER_PORT,
|
@@ -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 | +# 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