From 84ec50a2aa400e80b14ed708a5a122ebc853ae89 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Thu, 13 Jun 2019 01:28:23 -0700 Subject: [PATCH] [LibOS/regression] Add OpenMP simple for-loop test Previously, OpenMP apps failed to run under Graphene-SGX because it did not support raw system calls (used inside of OpenMP lib, in particular the futex() syscall). Since recently, Graphene-SGX has support for raw syscall execution. This commit adds a test showing that OpenMP works. --- Jenkinsfiles/ubuntu-16.04.dockerfile | 1 + LibOS/shim/test/regression/00_openmp.py | 20 ++++++++++++++++ LibOS/shim/test/regression/Makefile | 7 +++++- LibOS/shim/test/regression/openmp.c | 15 ++++++++++++ .../test/regression/openmp.manifest.template | 24 +++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 LibOS/shim/test/regression/00_openmp.py create mode 100644 LibOS/shim/test/regression/openmp.c create mode 100644 LibOS/shim/test/regression/openmp.manifest.template diff --git a/Jenkinsfiles/ubuntu-16.04.dockerfile b/Jenkinsfiles/ubuntu-16.04.dockerfile index 7e7c242a..2deab0d2 100644 --- a/Jenkinsfiles/ubuntu-16.04.dockerfile +++ b/Jenkinsfiles/ubuntu-16.04.dockerfile @@ -20,6 +20,7 @@ RUN apt-get update \ python3-minimal \ texinfo \ wget \ + libomp-dev \ # Add the user UID:1001, GID:1001, home at /leeroy && groupadd -r leeroy -g 1001 \ diff --git a/LibOS/shim/test/regression/00_openmp.py b/LibOS/shim/test/regression/00_openmp.py new file mode 100644 index 00000000..c502a50c --- /dev/null +++ b/LibOS/shim/test/regression/00_openmp.py @@ -0,0 +1,20 @@ +import os, sys, mmap +from regression import Regression + +loader = sys.argv[1] +sgx = os.environ.get('SGX_RUN') == '1' + +# This test is only meaningful on SGX PAL because only SGX catches raw syscalls +# and redirects to Graphene's LibOS. If we will add seccomp to Linux PAL, then +# we should allow this test on Linux PAL as well. +if not sgx: + sys.exit(0) + +# Running OpenMP +regression = Regression(loader, "openmp") + +regression.add_check(name="OpenMP simple for loop", + check=lambda res: "first: 0, last: 9" in res[0].out) + +rv = regression.run_checks() +if rv: sys.exit(rv) diff --git a/LibOS/shim/test/regression/Makefile b/LibOS/shim/test/regression/Makefile index 726680de..5eb4fc0e 100644 --- a/LibOS/shim/test/regression/Makefile +++ b/LibOS/shim/test/regression/Makefile @@ -1,4 +1,4 @@ -special_executables = bootstrap_static bootstrap_pie shared_object +special_executables = bootstrap_static bootstrap_pie shared_object openmp c_executables = $(filter-out $(special_executables),$(patsubst %.c,%,$(wildcard *.c))) cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp)) manifests = $(patsubst %.manifest.template,%.manifest,$(wildcard *.manifest.template)) manifest @@ -44,6 +44,11 @@ shared_object: %: %.c syscall: CFLAGS += -I$(PALDIR)/../include -I$(PALDIR)/host/$(PAL_HOST) +openmp: %: %.c + @echo [ $@ ] + @$(CC) $(CFLAGS) -o $@ -fopenmp $< \ + $(shell echo $@ | sed 's/^[^\.]*//g' | sed 's/\./ -l/g') + else .IGNORE: $(special_executables) $(c_executables) $(cxx_executables) $(special_executables) $(c_executables) $(cxx_executables): diff --git a/LibOS/shim/test/regression/openmp.c b/LibOS/shim/test/regression/openmp.c new file mode 100644 index 00000000..144be0ce --- /dev/null +++ b/LibOS/shim/test/regression/openmp.c @@ -0,0 +1,15 @@ +/* build with: gcc -fopenmp openmp-test.c -o openmp-test */ +#include +#include +#include + +int v[10]; + +int main(void) { +#pragma omp parallel for + for (int i=0; i<10; i++) + v[i] = i; + + printf("first: %d, last: %d\n", v[0], v[9]); + return 0; +} diff --git a/LibOS/shim/test/regression/openmp.manifest.template b/LibOS/shim/test/regression/openmp.manifest.template new file mode 100644 index 00000000..7350a5c3 --- /dev/null +++ b/LibOS/shim/test/regression/openmp.manifest.template @@ -0,0 +1,24 @@ +loader.preload = file:../../src/libsysdb.so +loader.env.LD_LIBRARY_PATH = /lib:/usrlib +loader.debug_type = none +loader.syscall_symbol = syscalldb + +fs.mount.lib.type = chroot +fs.mount.lib.path = /lib +fs.mount.lib.uri = file:../../../../Runtime + +fs.mount.bin.type = chroot +fs.mount.bin.path = /bin +fs.mount.bin.uri = file:/bin + +fs.mount.usrlib.type = chroot +fs.mount.usrlib.path = /usrlib +fs.mount.usrlib.uri = file:/usr/lib/x86_64-linux-gnu + +sgx.thread_num = 32 + +sgx.trusted_files.ld = file:../../../../Runtime/ld-linux-x86-64.so.2 +sgx.trusted_files.libc = file:../../../../Runtime/libc.so.6 +sgx.trusted_files.libpthread = file:../../../../Runtime/libpthread.so.0 +sgx.trusted_files.libdl = file:../../../../Runtime/libdl.so.2 +sgx.trusted_files.libgomp = file:/usr/lib/x86_64-linux-gnu/libgomp.so.1