diff --git a/tests/benchmarks/.gitignore b/tests/benchmarks/.gitignore new file mode 100644 index 00000000..26828f50 --- /dev/null +++ b/tests/benchmarks/.gitignore @@ -0,0 +1,3 @@ +/__pycache__/ +/helloworld +/write_pages diff --git a/tests/benchmarks/Makefile b/tests/benchmarks/Makefile new file mode 100644 index 00000000..740c91dc --- /dev/null +++ b/tests/benchmarks/Makefile @@ -0,0 +1,10 @@ +BENCHMARKS = \ + helloworld \ + write_pages + +.PHONY: all +all: $(BENCHMARKS) + +.PHONY: clean +clean: + $(RM) $(BENCHMARKS) diff --git a/tests/benchmarks/basic.manifest.template b/tests/benchmarks/basic.manifest.template new file mode 100644 index 00000000..38153bfc --- /dev/null +++ b/tests/benchmarks/basic.manifest.template @@ -0,0 +1,21 @@ +#sgx.enable_stats = 1 + +loader.preload = file:@GRAPHENEDIR@/Runtime/libsysdb.so +loader.env.LD_LIBRARY_PATH = /lib +loader.debug_type = none +loader.syscall_symbol = syscalldb +loader.insecure__use_cmdline_argv = 1 + +fs.mount.graphene_lib.type = chroot +fs.mount.graphene_lib.path = /lib +fs.mount.graphene_lib.uri = file:@GRAPHENEDIR@/Runtime + +sgx.trusted_files.ld = file:@GRAPHENEDIR@/Runtime/ld-linux-x86-64.so.2 +sgx.trusted_files.libc = file:@GRAPHENEDIR@/Runtime/libc.so.6 +sgx.trusted_files.libdl = file:@GRAPHENEDIR@/Runtime/libdl.so.2 +sgx.trusted_files.libm = file:@GRAPHENEDIR@/Runtime/libm.so.6 +sgx.trusted_files.libpthread = file:@GRAPHENEDIR@/Runtime/libpthread.so.0 + +sgx.thread_num = 3 + +#sgx.static_address = 1 diff --git a/tests/benchmarks/basic.py b/tests/benchmarks/basic.py new file mode 100644 index 00000000..62855b58 --- /dev/null +++ b/tests/benchmarks/basic.py @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: LGPL-3.0-or-later +# Copyright (c) 2020 Intel Corporation +# Wojtek Porczyk +# + +from . import Exec + +# pylint: disable=invalid-name + +class HelloWorld: + # pylint: disable=no-self-use + + helloworld = Exec('helloworld', manifest_template='basic.manifest.template') + setup = helloworld.setup + + def time_graphene_nosgx(self): + self.helloworld.run_in_graphene(sgx=False) + + def time_graphene_sgx(self): + self.helloworld.run_in_graphene(sgx=True) + +class WritePages: + # pylint: disable=no-self-use + + write_pages = Exec('write_pages', manifest_template='basic.manifest.template') + params = [10000, 100000, 1000000, 10000000] + param_names = ['pagecount'] + setup = write_pages.setup + + def time_graphene_nosgx(self, pagecount): + self.write_pages.run_in_graphene(str(pagecount), sgx=False) + + def time_graphene_sgx(self, pagecount): + self.write_pages.run_in_graphene(str(pagecount), sgx=True) diff --git a/tests/benchmarks/helloworld.c b/tests/benchmarks/helloworld.c new file mode 100644 index 00000000..33c14ce1 --- /dev/null +++ b/tests/benchmarks/helloworld.c @@ -0,0 +1,3 @@ +int main() { + return 0; +} diff --git a/tests/benchmarks/write_pages.c b/tests/benchmarks/write_pages.c new file mode 100644 index 00000000..fb00b4ae --- /dev/null +++ b/tests/benchmarks/write_pages.c @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* Copyright (c) 2020 Intel Corporation + * Wojtek Porczyk + */ + +/* + * write a number of pages to /dev/null + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void usage(char* argv0) { + fprintf(stderr, "usage: %s PAGECOUNT\n", argv0); +} + +int main(int argc, char* argv[]) { + void* buf; + size_t pagesize; + ssize_t r; + int fd, i, ret, pagecount; + + if (argc != 2) { + usage(argv[0]); + return 2; + } + + errno = 0; + pagecount = strtol(argv[1], NULL, 0); + if (errno != 0) { + usage(argv[0]); + return 2; + } + + ret = 1; + + pagesize = sysconf(_SC_PAGESIZE); + + buf = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (buf == MAP_FAILED) { + perror("mmap"); + goto err_return; + } + + memset(buf, 0xa5, pagesize); + + fd = open("/dev/null", O_WRONLY); + if (fd < 0) { + perror("open"); + goto err_unmap; + } + + for (i = 0; i < pagecount; i++) { + r = write(fd, buf, pagesize); + if (r < 0) { + perror("write"); + goto err_close; + } + } + + ret = 0; + +err_close: + close(fd); +err_unmap: + munmap(buf, pagesize); +err_return: + return ret; +}