Skip to content

Commit

Permalink
Merge pull request #177 from hamistao/add_tpm_tests
Browse files Browse the repository at this point in the history
Add tests for TPM usage
  • Loading branch information
tomponline authored May 29, 2024
2 parents a002e8f + 05c2883 commit e961201
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
- "storage-vm lvm-thin"
- "storage-vm zfs"
- storage-volumes-vm
- tpm-vm
- vm-nesting
exclude:
- test: efi-vars-editor-vm # not compatible with 5.0/*
Expand Down
54 changes: 54 additions & 0 deletions tests/tpm-vm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
set -eu

# Install LXD
install_lxd

# Configure LXD
lxd init --auto

IMAGE="${TEST_IMG:-ubuntu-minimal-daily:24.04}"
vmName="test-vm"

# Launch test instance
lxc init "${IMAGE}" "${vmName}" --vm

echo "==> Try starting a VM with two TPM devices"
lxc config device add "${vmName}" tpm1 tpm
lxc config device add "${vmName}" tpm2 tpm
! lxc start "${vmName}" || false

echo "==> Starting VM with TPM"
lxc config device remove "${vmName}" tpm2
lxc start "${vmName}"
waitInstanceReady "${vmName}"

echo "==> Check if TPM files are present"
lxc exec "${vmName}" -- stat /dev/tpm0
lxc exec "${vmName}" -- stat /dev/tpmrm0

echo "==> Try removing TPM from a running VM"
! lxc config device remove "${vmName}" tpm1 || false
lxc exec "${vmName}" -- stat /dev/tpm0
lxc exec "${vmName}" -- stat /dev/tpmrm0

echo "==> Stopping VM and removing TPM"
lxc stop "${vmName}" --force
lxc config device remove "${vmName}" tpm1

echo "==> Check if TPM was indeed removed"
lxc start "${vmName}"
waitInstanceReady "${vmName}"
! lxc exec "${vmName}" -- stat /dev/tpm0 || false
! lxc exec "${vmName}" -- stat /dev/tpmrm0 || false
lxc stop "${vmName}" --force

# TPM names are included on the swtpm socket path and long socket paths can cause problems if not handled correctly.
echo "==> Test handling TPMs with long names"
longName="tpm-device-with-long-name-for-testing"
lxc config device add "${vmName}" "${longName}" tpm
lxc start "${vmName}"
waitInstanceReady "${vmName}"
lxc exec "${vmName}" -- stat /dev/tpm0
lxc exec "${vmName}" -- stat /dev/tpmrm0
lxc delete "${vmName}" --force

0 comments on commit e961201

Please sign in to comment.