Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2888: add enclave loading testing in simulation mode r=mingweishih a=jinghe-INTC



Co-authored-by: Jing He <[email protected]>
  • Loading branch information
oeciteam and Jing He committed May 7, 2020
2 parents dcf8bd6 + ca51b12 commit c6aaf8f
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ if (UNIX
add_subdirectory(SampleApp)
add_subdirectory(SampleAppCRT)
add_subdirectory(sealKey)
add_subdirectory(sim-mode)
add_subdirectory(stdc)
add_subdirectory(stdcxx)
add_subdirectory(syscall)
Expand Down
10 changes: 10 additions & 0 deletions tests/sim-mode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Open Enclave SDK contributors.
# Licensed under the MIT License.

add_subdirectory(host)
if (BUILD_ENCLAVES)
add_subdirectory(enc)
endif()

add_enclave_test(tests/sim-signed sim_host enc_signed)
add_enclave_test(tests/sim-unsigned sim_host enc_unsigned)
3 changes: 3 additions & 0 deletions tests/sim-mode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory tests loading enclave with simulation mode, with:
1. A signed enclave image
2. A unsigned enclave image
23 changes: 23 additions & 0 deletions tests/sim-mode/enc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) Open Enclave SDK contributors.
# Licensed under the MIT License.

set (EDL_FILE ../sim_mode.edl)

add_custom_command(
OUTPUT sim_mode_t.h sim_mode_t.c
DEPENDS ${EDL_FILE} edger8r
COMMAND edger8r --trusted ${EDL_FILE} --search-path ${CMAKE_CURRENT_SOURCE_DIR})

add_enclave(TARGET enc_unsigned UUID 6771bad2-805a-11ea-bc55-0242ac130003 SOURCES enc.c props.c ${CMAKE_CURRENT_BINARY_DIR}/sim_mode_t.c)

add_enclave(TARGET enc UUID 82fc6d38-805a-11ea-bc55-0242ac130003 CONFIG sign.conf SOURCES enc.c props.c ${CMAKE_CURRENT_BINARY_DIR}/sim_mode_t.c)

enclave_include_directories(enc_unsigned PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
enclave_link_libraries(enc_unsigned oelibc)

enclave_include_directories(enc PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
enclave_link_libraries(enc oelibc)
11 changes: 11 additions & 0 deletions tests/sim-mode/enc/enc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.

#include <openenclave/edger8r/enclave.h>
#include <openenclave/enclave.h>
#include "sim_mode_t.h"

int test(void)
{
return 0;
}
12 changes: 12 additions & 0 deletions tests/sim-mode/enc/props.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.

#include <openenclave/enclave.h>

OE_SET_ENCLAVE_SGX(
1234, /* ProductID */
5678, /* SecurityVersion */
false, /* AllowDebug */
1024, /* HeapPageCount */
512, /* StackPageCount */
4); /* TCSCount */
10 changes: 10 additions & 0 deletions tests/sim-mode/enc/sign.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) Open Enclave SDK contributors.
# Licensed under the MIT License.

# Enclave settings:
Debug=0
NumHeapPages=1024
NumStackPages=1024
NumTCS=2
ProductID=1
SecurityVersion=1
15 changes: 15 additions & 0 deletions tests/sim-mode/host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) Open Enclave SDK contributors.
# Licensed under the MIT License.

set (EDL_FILE ../sim_mode.edl)

add_custom_command(
OUTPUT sim_mode_u.h sim_mode_u.c
DEPENDS ${EDL_FILE} edger8r
COMMAND edger8r --untrusted ${EDL_FILE} --search-path ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(sim_host host.c sim_mode_u.c)

target_include_directories(sim_host PRIVATE ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(sim_host oehostapp)
45 changes: 45 additions & 0 deletions tests/sim-mode/host/host.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.

#include <openenclave/host.h>
#include <openenclave/internal/calls.h>
#include <openenclave/internal/error.h>
#include <openenclave/internal/tests.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sim_mode_u.h"

static void _launch_enclave_success(const char* path, const uint32_t flags)
{
oe_result_t result;
oe_enclave_t* enclave = NULL;

result = oe_create_sim_mode_enclave(
path, OE_ENCLAVE_TYPE_SGX, flags, NULL, 0, &enclave);

if (result != OE_OK)
oe_put_err("oe_create_sim_mode_enclave(): result=%u", result);

int ret;
if ((result = test(enclave, &ret)) != OE_OK)
oe_put_err("test: result=%u", result);

if ((result = oe_terminate_enclave(enclave)) != OE_OK)
oe_put_err("oe_terminate_enclave(): result=%u", result);
}

int main(int argc, const char* argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s ENCLAVE\n", argv[0]);
exit(1);
}

const uint32_t flags = OE_ENCLAVE_FLAG_SIMULATE;

_launch_enclave_success(argv[1], flags);

return 0;
}
8 changes: 8 additions & 0 deletions tests/sim-mode/sim_mode.edl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Open Enclave SDK contributors.
// Licensed under the MIT License.

enclave {
trusted {
public int test();
};
};

0 comments on commit c6aaf8f

Please sign in to comment.