-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from canonical/pek1286_memory_confidentiality…
…_tests Adding memory confidentiality tests
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2024 Canonical Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License version 3, as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | ||
# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import os | ||
import time | ||
import json | ||
import subprocess | ||
|
||
import Qemu | ||
from common import * | ||
|
||
MEMORY_FILE='memory.bin' | ||
CHECK_EXEC='export INCLEAR=6150079244' | ||
|
||
def check_for_string(filename, needle): | ||
cs = subprocess.run(['sudo', 'grep', needle, filename], capture_output=True) | ||
return cs.returncode | ||
|
||
def remove_file(filename): | ||
cs = subprocess.run(['sudo', 'rm', '-f', filename], capture_output=True) | ||
return cs.returncode | ||
|
||
def test_guest_memory_confidentiality_no_tdx(qm): | ||
""" | ||
Test guest memory confidentiality without TDX | ||
""" | ||
with Qemu.QemuMachine(memory='1G', machine=Qemu.QemuEfiMachine.OVMF_Q35) as qm: | ||
qm.run() | ||
|
||
qmon = Qemu.QemuMonitor(qm) | ||
qmon.wait_for_state('running') | ||
|
||
qssh = Qemu.QemuSSH(qm) | ||
|
||
qssh.check_exec(CHECK_EXEC) | ||
|
||
qmon.send_command('dump-guest-memory %s' % (MEMORY_FILE)) | ||
|
||
rc = check_for_string(MEMORY_FILE, CHECK_EXEC) | ||
assert rc == 0, 'Failed finding %s in %s' % (CHECK_EXEC, MEMORY_FILE) | ||
|
||
remove_file(MEMORY_FILE) | ||
|
||
qm.stop() | ||
|
||
def test_guest_memory_confidentiality_tdx(qm): | ||
""" | ||
Test guest memory confidentiality with TDX | ||
""" | ||
with Qemu.QemuMachine(memory='1G') as qm: | ||
qm.run() | ||
|
||
qmon = Qemu.QemuMonitor(qm) | ||
qmon.wait_for_state('running') | ||
|
||
qssh = Qemu.QemuSSH(qm) | ||
|
||
qssh.check_exec(CHECK_EXEC) | ||
|
||
qmon.send_command('dump-guest-memory %s' % (MEMORY_FILE)) | ||
|
||
rc = check_for_string(MEMORY_FILE, CHECK_EXEC) | ||
assert rc == 1, 'Failed by finding %s in %s' % (CHECK_EXEC, MEMORY_FILE) | ||
|
||
remove_file(MEMORY_FILE) | ||
|
||
qm.stop() |