-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new exit test that has a thread with a busy loop
- Loading branch information
Showing
3 changed files
with
82 additions
and
22 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 |
---|---|---|
@@ -1,69 +1,88 @@ | ||
include ../../common.mk | ||
|
||
TEST1=exit-test | ||
TEST2=segfault-test | ||
TEST3=raise-test | ||
TEST_EXIT=exit-test | ||
TEST_SEGFAULT=segfault-test | ||
TEST_RAISE=raise-test | ||
TEST_SPIN=spin-test | ||
|
||
SRCS=$(wildcard *.c) | ||
|
||
DISK_IMAGE=sgxlkl-exit-test.img | ||
IMAGE_SIZE=5M | ||
|
||
SGXLKL_ENV=SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=1 SGXLKL_TRACE_SIGNAL=1 | ||
SGXLKL_ENV=SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=1 SGXLKL_TRACE_SIGNAL=1 SGXLKL_ETHREADS=8 | ||
|
||
SHELL := /bin/bash | ||
|
||
.DELETE_ON_ERROR: | ||
.PHONY: clean | ||
.PHONY: clean run-hw run-sw run-exit-hw run-segfault-hw run-raise-hw run-spin-hw run-exit-sw run-segfault-sw run-raise-sw run-spin-sw | ||
|
||
run: run-hw run-sw | ||
|
||
run-hw: run-exit-hw run-segfault-hw run-raise-hw run-spin-hw | ||
|
||
run-sw: run-exit-sw run-segfault-sw run-raise-sw run-spin-sw | ||
|
||
$(DISK_IMAGE): $(SRCS) | ||
${SGXLKL_DISK_TOOL} create --size=${IMAGE_SIZE} --docker=./Dockerfile ${DISK_IMAGE} | ||
|
||
run-hw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST1); \ | ||
run-exit-hw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST_EXIT); \ | ||
if [ $$? -eq 42 ]; then \ | ||
echo "TEST PASSED: exit() (HW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: exit() (HW mode)"; \ | ||
echo "TEST FAILED: exit() (HW mode)" && exit -1; \ | ||
fi | ||
|
||
run-segfault-hw: $(DISK_IMAGE) | ||
# Next we need to filter out the string "Segementation fault", | ||
# otherwise the CI pipelines flags the test as failed. | ||
@set -o pipefail; ${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST2) | grep -v -x "Segmentation fault"; \ | ||
@set -o pipefail; ${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST_SEGFAULT) | grep -v -x "Segmentation fault"; \ | ||
if [ $$? -eq 139 ]; then \ | ||
echo "TEST PASSED: segv (HW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: segv (HW mode)"; \ | ||
echo "TEST FAILED: segv (HW mode)" && exit -1; \ | ||
fi | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST3); \ | ||
|
||
run-raise-hw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST_RAISE); \ | ||
if [ $$? -eq 143 ]; then \ | ||
echo "TEST PASSED: raise (HW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: raise (HW mode)"; \ | ||
echo "TEST FAILED: raise (HW mode)" && exit -1; \ | ||
fi | ||
|
||
run-sw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST1); \ | ||
run-spin-hw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug ${DISK_IMAGE} $(TEST_SPIN) | ||
|
||
run-exit-sw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST_EXIT); \ | ||
if [ $$? -eq 42 ]; then \ | ||
echo "TEST PASSED: exit (SW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: segfault (SW mode)"; \ | ||
echo "TEST FAILED: segfault (SW mode)" && exit -1; \ | ||
fi | ||
|
||
run-segfault-sw: $(DISK_IMAGE) | ||
# Next we need to filter out the string "Segementation fault", | ||
# otherwise the CI pipelines flags the test as failed. | ||
@set -o pipefail; ${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST2) | grep -v -x "Segmentation fault"; \ | ||
@set -o pipefail; ${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST_SEGFAULT) | grep -v -x "Segmentation fault"; \ | ||
if [ $$? -eq 139 ]; then \ | ||
echo "TEST PASSED: segv (SW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: segv (SW mode)"; \ | ||
echo "TEST FAILED: segv (SW mode)" && exit -1; \ | ||
fi | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST3); \ | ||
if [ $$? -eq 143 ]; then \ | ||
|
||
run-raise-sw: $(DISK_IMAGE) | ||
@${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST_RAISE); \ | ||
if [ $$? -eq 143 ]; then \ | ||
echo "TEST PASSED: raise (SW mode)"; \ | ||
else \ | ||
echo "TEST FAILED: raise (SW mode)"; \ | ||
fi | ||
else \ | ||
echo "TEST FAILED: raise (SW mode)" && exit -1; \ | ||
fi | ||
|
||
run-spin-sw: $(DISK_IMAGE) | ||
${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug ${DISK_IMAGE} $(TEST_SPIN) | ||
|
||
clean: | ||
rm -f $(DISK_IMAGE) |
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,40 @@ | ||
/* | ||
* spin-test.c | ||
* | ||
* This test checks that an application can exit, even it is has another | ||
* thread that is in a busy loop. This means that we cannot stop that | ||
* thread under cooperative scheduling. | ||
* | ||
*/ | ||
|
||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void* thread1_func(void* arg) | ||
{ | ||
printf("Thread 1 in busy loop...\n"); | ||
|
||
for (;;) | ||
; | ||
|
||
return NULL; | ||
} | ||
|
||
int main(void) | ||
{ | ||
pthread_t thread1; | ||
|
||
printf("Creating worker thread...\n"); | ||
int ret = pthread_create(&thread1, NULL, thread1_func, NULL); | ||
if (ret < 0) | ||
{ | ||
printf("Failed to create thread\n"); | ||
exit(-1); | ||
} | ||
|
||
printf("Sleeping for 1 sec...\n"); | ||
sleep(1); | ||
|
||
printf("Exiting...\n"); | ||
} |