-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: Add scripts to run samples automatically
The scripts are a mix of bash and a bit of GNU expect for flexibility, as each sample needs to be tested in slightly different ways. Each sample must have a test.sh script in its folder so that the CI detects it and runs it. They are executed by run_sample.sh script, created using run_test.sh as an example. This commit adds several samples to the CI, but not all of them: - The ml folder samples, for example, take far too long to be part of a regular CI run, and need caching of docker images, which is a task on its own. - The openmp and nodejs samples seem to be broken.
- Loading branch information
Showing
27 changed files
with
406 additions
and
34 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,86 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$SGXLKL_ROOT" ]; then | ||
echo "ERROR: 'SGXLKL_ROOT' is undefined. Please export SGXLKL_ROOT=<SGX-LKL-OE> source code repository" | ||
exit 1 | ||
fi | ||
if [ -z "$SGXLKL_BUILD_MODE" ]; then | ||
echo "ERROR: 'SGXLKL_BUILD_MODE' is undefined. Please export SGXLKL_BUILD_MODE=<mode>" | ||
exit 1 | ||
fi | ||
|
||
#shellcheck source=.azure-pipelines/scripts/junit_utils.sh | ||
. "$SGXLKL_ROOT/.azure-pipelines/scripts/junit_utils.sh" | ||
#shellcheck source=.azure-pipelines/scripts/test_utils.sh | ||
. "$SGXLKL_ROOT/.azure-pipelines/scripts/test_utils.sh" | ||
|
||
# Initialize the variables and test case [mandatory]. | ||
sample_mode=$1 # clean, init or run | ||
run_mode=$2 # run-hw or run-sw | ||
|
||
if [[ "$sample_mode" == "clean" ]]; then | ||
./test.sh clean | ||
exit $? | ||
fi | ||
|
||
samples_dir=$SGXLKL_ROOT/samples | ||
sample_name="$(realpath --relative-to="$samples_dir" "$(pwd)")" | ||
sample_name="${sample_name//\//-}" | ||
sample_name+="-($SGXLKL_BUILD_MODE)-($run_mode)-($SGXLKL_ETHREADS-ethreads)" | ||
sample_class=$(realpath --relative-to="$samples_dir" "$(pwd)/..") | ||
test_suite="sgx-lkl-oe" | ||
|
||
if [[ -z $sample_name || -z $sample_class || -z $sample_mode ]]; then | ||
echo -e "\n ERROR: sample_name sample_class or sample_mode not passed \n" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$sample_mode" == "init" ]]; then | ||
InitializeTestCase "$sample_name" "$sample_class" "$test_suite" "$run_mode" | ||
fi | ||
|
||
# Get the timeout from the test module | ||
DEFAULT_TIMEOUT=300 | ||
if ! timeout=$(./test.sh gettimeout 2> /dev/null); then | ||
timeout=$DEFAULT_TIMEOUT | ||
fi | ||
echo "Execution timeout: $timeout" | ||
|
||
case "$run_mode" in | ||
"run-hw") | ||
echo "Will run samples for run-hw" | ||
;; | ||
"run-sw") | ||
echo "Will run samples for run-sw" | ||
;; | ||
*) | ||
echo "Invalid run_mode parameter: $run_mode. Valid options: run-hw/run-sw" | ||
exit 1; | ||
;; | ||
esac | ||
|
||
if [[ $sample_mode == "init" ]]; then | ||
timeout --kill-after=$((timeout + 60)) $timeout ./test.sh init | ||
script_exit=$? | ||
elif [[ $sample_mode == "run" ]]; then | ||
timeout --kill-after=$((timeout + 60)) $timeout ./test.sh run "$run_mode" | ||
script_exit=$? | ||
else | ||
echo "Invalid sample_mode parameter: $sample_mode. Valid options: clean/init/run/gettimeout" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$script_exit" == "124" ]]; then | ||
echo "$run_mode: TIMED OUT after $timeout secs" | ||
elif [[ "$script_exit" != "0" ]]; then | ||
echo "$run_mode: FAILED WITH EXIT CODE: $script_exit" | ||
fi | ||
|
||
if [[ $sample_mode == "init" ]]; then | ||
echo "Sample initialization completed with EXIT CODE $script_exit" | ||
return $script_exit | ||
fi | ||
|
||
echo "Sample run completed with EXIT CODE $script_exit" | ||
|
||
exit $script_exit |
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
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ parameters: | |
- core | ||
- ltp1 | ||
- ltp2 | ||
- samples | ||
- name: 'ethreads' | ||
type: object | ||
default: | ||
|
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,13 @@ | ||
#!/usr/bin/expect -f | ||
|
||
set timeout -1 | ||
|
||
spawn docker run --rm attackme /read_secret | ||
set dockerID $spawn_id | ||
expect -i $dockerID "Ready to be attacked..." | ||
|
||
spawn ./read_memory.sh read_secret Secret42! | ||
set readID $spawn_id | ||
expect -i $readID "Match found." | ||
|
||
send -i $dockerID -- "\r" |
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,21 @@ | ||
#!/usr/bin/expect -f | ||
|
||
set SGXLKL_STARTER "$env(SGXLKL_STARTER)" | ||
set SGXLKL_DISK_TOOL "$env(SGXLKL_DISK_TOOL)" | ||
|
||
set timeout -1 | ||
|
||
spawn "$SGXLKL_DISK_TOOL" create --force --docker=attackme --size 5M --encrypt --key-file rootfs.img | ||
expect "Succesfully created rootfs.img" | ||
expect eof | ||
|
||
set env(SGXLKL_HD_KEY) rootfs.img.key | ||
spawn "$SGXLKL_STARTER" --hw-debug rootfs.img /read_secret | ||
set oeID $spawn_id | ||
expect -i $oeID "Ready to be attacked..." | ||
|
||
spawn ./read_memory.sh sgx-lkl-run-oe Secret42! | ||
set readID $spawn_id | ||
expect -i $readID "No match found." | ||
|
||
send -i $oeID -- "\r" |
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,27 @@ | ||
#!/bin/bash | ||
|
||
# shellcheck source=/dev/null | ||
source "../../common.sh" | ||
|
||
test_mode=$1 | ||
run_mode=$2 | ||
|
||
set -e | ||
|
||
if [[ "$test_mode" == "clean" ]]; then | ||
rm -f rootfs.img rootfs.img.docker rootfs.img.key | ||
elif [[ "$test_mode" == "init" ]]; then | ||
rm -f mem.dump.* | ||
docker build -t attackme . | ||
elif [[ "$test_mode" == "run" ]]; then | ||
if [[ "$run_mode" == "run-sw" ]]; then | ||
./plain-docker.exp | ||
elif [[ "$run_mode" == "run-hw" ]]; then | ||
./sgx.exp | ||
fi | ||
elif [[ "$test_mode" == "gettimeout" ]]; then | ||
# 20 minutes | ||
echo 1200 | ||
fi | ||
|
||
exit 0 |
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,19 @@ | ||
#!/bin/bash | ||
|
||
test_mode=$1 | ||
run_mode=$2 | ||
|
||
set -e | ||
|
||
if [[ "$test_mode" == "clean" ]]; then | ||
make clean | ||
elif [[ "$test_mode" == "init" ]]; then | ||
make | ||
elif [[ "$test_mode" == "run" ]]; then | ||
make "$run_mode" | ||
elif [[ "$test_mode" == "gettimeout" ]]; then | ||
# Default | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
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,20 @@ | ||
samples_dir=$(dirname $(realpath "$BASH_SOURCE")) | ||
SGXLKL_ROOT=$(realpath "${samples_dir}/..") | ||
|
||
if [[ -z "${SGXLKL_PREFIX}" ]]; then | ||
export SGXLKL_STARTER=${SGXLKL_ROOT}/build/sgx-lkl-run-oe | ||
export SGXLKL_DISK_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-disk | ||
export SGXLKL_DOCKER_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-docker | ||
export SGXLKL_CFG_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-cfg | ||
export SGXLKL_SETUP_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-setup | ||
export SGXLKL_GDB=${SGXLKL_ROOT}/tools/gdb/sgx-lkl-gdb | ||
export SGXLKL_JAVA_RUN=${SGXLKL_ROOT}/tools/sgx-lkl-java | ||
else | ||
export SGXLKL_STARTER=${SGXLKL_PREFIX}/bin/sgx-lkl-run-oe | ||
export SGXLKL_DISK_TOOL=${SGXLKL_PREFIX}/bin/sgx-lkl-disk | ||
export SGXLKL_DOCKER_TOOL=${SGXLKL_PREFIX}/bin/sgx-lkl-docker | ||
export SGXLKL_CFG_TOOL=${SGXLKL_PREFIX}/bin/sgx-lkl-cfg | ||
export SGXLKL_SETUP_TOOL=${SGXLKL_PREFIX}/bin/sgx-lkl-setup | ||
export SGXLKL_GDB=${SGXLKL_PREFIX}/bin/sgx-lkl-gdb | ||
export SGXLKL_JAVA_RUN=${SGXLKL_PREFIX}/bin/sgx-lkl-java | ||
fi |
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,18 @@ | ||
#!/bin/bash | ||
|
||
test_mode=$1 | ||
|
||
set -e | ||
|
||
if [[ "$test_mode" == "clean" ]]; then | ||
make clean | ||
elif [[ "$test_mode" == "init" ]]; then | ||
echo "Nothing to do" | ||
elif [[ "$test_mode" == "run" ]]; then | ||
make | ||
elif [[ "$test_mode" == "gettimeout" ]]; then | ||
# Default | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
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,21 @@ | ||
#!/bin/bash | ||
|
||
test_mode=$1 | ||
run_mode=$2 | ||
|
||
set -e | ||
|
||
if [[ "$test_mode" == "clean" ]]; then | ||
make clean | ||
elif [[ "$test_mode" == "init" ]]; then | ||
make | ||
elif [[ "$test_mode" == "run" ]]; then | ||
make "$run_mode"-verity | ||
# TODO: This doesn't work | ||
#make "$run_mode"-integrity | ||
elif [[ "$test_mode" == "gettimeout" ]]; then | ||
# Default | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
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
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,15 @@ | ||
#!/usr/bin/expect -f | ||
|
||
set timeout -1 | ||
|
||
spawn make run-hw | ||
set serverID $spawn_id | ||
expect -i $serverID "Ready to accept connections" | ||
|
||
spawn ./run-redis-client.sh | ||
set clientID $spawn_id | ||
expect -i $clientID "Test succeeded" | ||
|
||
send -i $serverID -- "" | ||
|
||
exit 0 |
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
Oops, something went wrong.