Skip to content

Commit 9322cae

Browse files
Run functional tests in CI (#102)
* add a functional test that retrieves secret via local attestation * optimize tests for the limited resources available in CI * add a functional test that runs a confidential VM with multiple vCPUs --------- Signed-off-by: Wojciech Ozga <[email protected]> Co-authored-by: Lennard Gäher <[email protected]>
1 parent 800572a commit 9322cae

File tree

16 files changed

+138
-186
lines changed

16 files changed

+138
-186
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ACE Build
1+
name: Functional tests
22

33
on:
44
push:
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
runs-on: ubuntu-24.04
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
with:
1515
submodules: 'true'
1616
- name: install build dependencies
@@ -32,14 +32,18 @@ jobs:
3232
- name: install rust nightly
3333
run: rustup component add rustfmt
3434
- name: build riscv toolchain
35-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make devtools
35+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 devtools
3636
- name: build emulator
37-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make emulator
37+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 emulator
3838
- name: build tools
39-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make tools
39+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 tools
4040
- name: build hypervisor
41-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make hypervisor
41+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 hypervisor
4242
- name: build firmware
43-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make firmware
44-
- name: build confidential_vms
45-
run: ACE_DIR=$(pwd)/build/ MAKEFLAGS="--silent -j4" make confidential_vms
43+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 firmware
44+
- name: build confidential vms
45+
run: ACE_DIR=$(pwd)/build/ make --silent -j8 confidential_vms
46+
- name: rebuild all to include changes to cvm disk
47+
run: ACE_DIR=$(pwd)/build/ make --silent -j8
48+
- name: run tests on confidential vms
49+
run: ACE_DIR=$(pwd)/build/ PATH=$PATH:$(pwd)/build/tools ace test

confidential-vms/linux_vm/hypervisor_rootfs/run_linux_vm_qemu.sh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
# SPDX-FileContributor: Wojciech Ozga <[email protected]>, IBM Research - Zurich
44
# SPDX-License-Identifier: Apache-2.0
55

6-
QEMU_CMD=qemu-system-riscv64
7-
KERNEL=/root/linux_vm/Image
8-
DRIVE=/root/linux_vm/rootfs.ext2
9-
INITRAMFS=/root/linux_vm/rootfs.cpio
10-
TAP=/root/linux_vm/cove_tap_qemu
11-
126
HOST_PORT="$((3000 + RANDOM % 3000))"
137
INTERACTIVE="-nographic"
148
SMP=2
159
MEMORY=1G
10+
ID=""
1611

1712
for i in "$@"; do
1813
case $i in
@@ -34,6 +29,10 @@ for i in "$@"; do
3429
MEMORY="${i#*=}"
3530
shift
3631
;;
32+
-i=*|--id=*)
33+
ID="${i#*=}"
34+
shift
35+
;;
3736
--daemonize*)
3837
INTERACTIVE="-daemonize"
3938
shift
@@ -47,8 +46,19 @@ for i in "$@"; do
4746
esac
4847
done
4948

49+
if [ ! -f "/root/linux_vm${ID}" ]; then
50+
cp -rf /root/linux_vm /root/linux_vm${ID}
51+
fi
52+
53+
QEMU_CMD=qemu-system-riscv64
54+
KERNEL=/root/linux_vm${ID}/Image
55+
DRIVE=/root/linux_vm${ID}/rootfs.ext2
56+
INITRAMFS=/root/linux_vm${ID}/rootfs.cpio
57+
TAP=/root/linux_vm${ID}/cove_tap_qemu
58+
5059
echo "SSH port: ${HOST_PORT}"
5160
echo "Number of cores assigned to the guest: ${SMP}"
61+
echo "${INTERACTIVE}"
5262

5363
${QEMU_CMD} ${DEBUG_OPTIONS} \
5464
${INTERACTIVE} \
@@ -61,5 +71,4 @@ ${QEMU_CMD} ${DEBUG_OPTIONS} \
6171
-device virtio-blk-pci,drive=hd0,iommu_platform=on,disable-legacy=on,disable-modern=off \
6272
-drive if=none,format=raw,file=${DRIVE},id=hd0 \
6373
-device virtio-net-pci,netdev=net0,iommu_platform=on,disable-legacy=on,disable-modern=off \
64-
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22 \
65-
-nographic
74+
-netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22

confidential-vms/linux_vm/hypervisor_rootfs/run_linux_vm_qemu2.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello from confidential VM's filesystem
1+
hello from confidential VM filesystem
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hello from confidential VM's filesystem
1+
hello from confidential VM filesystem

hypervisor/configurations/qemu_riscv64_virt_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ BR2_GLOBAL_PATCH_DIR=""
5656

5757
# Packages
5858
BR2_PACKAGE_DROPBEAR=y
59+
BR2_PACKAGE_OPENSSH_CLIENT=y
60+
BR2_PACKAGE_SSHPASS=y
5961

6062
# Qemu
6163
BR2_PACKAGE_QEMU=y

hypervisor/rootfs/common.sh

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22
# SPDX-FileCopyrightText: 2023 IBM Corporation
33
# SPDX-FileContributor: Wojciech Ozga <[email protected]>, IBM Research - Zurich
44
# SPDX-License-Identifier: Apache-2.0
5-
6-
function run_confidential_vm() {
7-
fallocate -l 128M hdd.dsk
8-
9-
KERNEL_IMAGE=$1
10-
NUMBER_OF_CORES=$2
11-
MEMORY_SIZE=$3
12-
DRIVE="hdd.dsk"
13-
14-
qemu-system-riscv64 -machine virt -cpu rv64 -smp $NUMBER_OF_CORES -m $MEMORY_SIZE \
15-
--enable-kvm \
16-
-global virtio-mmio.force-legacy=false \
17-
-append "console=ttyS0 ro root=/dev/vda swiotlb=mmnn,force nosplash debug promote_to_tvm" \
18-
-device virtio-blk-pci,drive=hd0,iommu_platform=on,disable-legacy=on,disable-modern=off \
19-
-drive if=none,format=raw,file=${DRIVE},id=hd0 \
20-
-nographic -bios none \
21-
-kernel $KERNEL_IMAGE &
22-
}
5+
export TVM_TEST_PASSWD="passwd"
6+
export SSH_CMD="sshpass -p ${TVM_TEST_PASSWD} ssh -y -q"
237

248
function kill_confidential_vm() {
259
PID="$(pidof qemu-system-riscv64)"
2610
kill -9 $PID
2711
wait $PID 2>/dev/null
2812
}
2913

14+
function wait_for_ssh () {
15+
for i in $(seq 1 30); do
16+
if [ "$( $SSH_CMD -p$3 $1@$2 'whoami' )" == "root" ]; then
17+
break
18+
fi
19+
echo "Waiting for the TVM's SSH ..."
20+
sleep 1
21+
done
22+
}

hypervisor/rootfs/selftest.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
# This script runs all tests in harness
77

8-
declare -a TESTS=("test_esm")
8+
declare -a TESTS=("test_attestation" "test_smp")
99

1010
for i in "${TESTS[@]}"; do
11-
./$i.sh 2>&1 > $i.log
11+
./$i.sh 2>&1 > $i.log
1212
RESULT=$?
1313
if [ $RESULT -eq 0 ]; then
1414
echo "$i: success"
1515
else
1616
echo "$i: failed"
17-
cat $i.log
17+
echo ""
18+
echo "======= Logs: ======="
19+
cat $i.log
1820
fi
19-
done
21+
done
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2025 IBM Corporation
3+
# SPDX-FileContributor: Wojciech Ozga <[email protected]>, IBM Research - Zurich
4+
# SPDX-License-Identifier: Apache-2.0
5+
. common.sh
6+
7+
/root/run_linux_vm_qemu.sh -s=1 -m=256M --daemonize 2>&1 > tmp_run_vm.log &
8+
sleep 5
9+
10+
TVM_USER="root"
11+
TVM_HOST="localhost"
12+
TVM_PORT="$(grep 'SSH port' tmp_run_vm.log | awk -F': ' '{ print $2 }' )"
13+
echo "TVM's SSH is listening on port: $TVM_PORT"
14+
15+
wait_for_ssh $TVM_USER $TVM_HOST $TVM_PORT
16+
17+
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'insmod /root/ace_module/ace.ko'
18+
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'dmesg | grep Secret' > tmp_dmesg.log
19+
20+
ATTESTATION_RESULT="$(grep 'Secret=0xc0ffee' tmp_dmesg.log | wc -l)"
21+
22+
kill_confidential_vm
23+
sleep 5
24+
25+
if [[ "x$ATTESTATION_RESULT" == "x1" ]]; then
26+
echo "Attestation test succeeded"
27+
exit 0
28+
else
29+
echo "Attestation test failed"
30+
exit 1
31+
fi

hypervisor/rootfs/test_smp.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2025 IBM Corporation
3+
# SPDX-FileContributor: Wojciech Ozga <[email protected]>, IBM Research - Zurich
4+
# SPDX-License-Identifier: Apache-2.0
5+
. common.sh
6+
7+
/root/run_linux_vm_qemu.sh -s=2 -m=256M --daemonize 2>&1 > tmp_run_smp.log &
8+
sleep 5
9+
10+
TVM_USER="root"
11+
TVM_HOST="localhost"
12+
TVM_PORT="$(grep 'SSH port' tmp_run_smp.log | awk -F': ' '{ print $2 }' )"
13+
echo "TVM's SSH is listening on port: $TVM_PORT"
14+
15+
wait_for_ssh $TVM_USER $TVM_HOST $TVM_PORT
16+
17+
$SSH_CMD -p${TVM_PORT} ${TVM_USER}@${TVM_HOST} 'cat /root/this_is_confidential_vm_filesystem' > tmp_smp_dmesg.log
18+
RESULT="$(grep 'hello from confidential VM filesystem' tmp_smp_dmesg.log | wc -l)"
19+
20+
kill_confidential_vm
21+
sleep 5
22+
23+
if [[ "x$RESULT" == "x1" ]]; then
24+
echo "SMP test succeeded"
25+
exit 0
26+
else
27+
echo "SMP test failed"
28+
exit 1
29+
fi

0 commit comments

Comments
 (0)