-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression 1031 (C++ support in TAs)
This commit adds C++ source files to the os_test TA and libraries. Regression 1031 is added which tests the following: - Construction of global objects in the TA main executable and in shared libraries (loaded automatically and via dlopen()) - Exception handling in the main program only (EH in shared libraries is not supported). - A "mixed frame" exception test, in which a C++ function calls a C function which calls a C++ function which throws. The initial caller is expected to be able to catch the exception. Signed-off-by: Jerome Forissier <[email protected]> Acked-by: Jens Wiklander <[email protected]> Acked-by: Etienne Carriere <[email protected]>
- Loading branch information
1 parent
4565c45
commit 1a205ae
Showing
13 changed files
with
283 additions
and
0 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,107 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
*/ | ||
|
||
extern "C" { | ||
|
||
#include <dlfcn.h> | ||
#include <os_test_lib.h> | ||
#include <stdint.h> | ||
#include <tee_ta_api.h> | ||
|
||
#include "cxx_tests.h" | ||
#include "os_test.h" | ||
|
||
}; | ||
|
||
class CtorTest { | ||
public: | ||
CtorTest() : val(1) {} | ||
|
||
int val; | ||
}; | ||
|
||
static CtorTest ctor_test; | ||
|
||
TEE_Result ta_entry_cxx_ctor_main(void) | ||
{ | ||
if (ctor_test.val != 1) | ||
return TEE_ERROR_GENERIC; | ||
|
||
return TEE_SUCCESS; | ||
} | ||
|
||
TEE_Result ta_entry_cxx_ctor_shlib(void) | ||
{ | ||
return os_test_shlib_cxx_ctor(); | ||
} | ||
|
||
TEE_Result ta_entry_cxx_ctor_shlib_dl(void) | ||
{ | ||
TEE_Result res = TEE_ERROR_GENERIC; | ||
TEE_Result (*ctor_test_fn)(void); | ||
void *handle = NULL; | ||
|
||
handle = dlopen("b3091a65-9751-4784-abf7-0298a7cc35ba", | ||
RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); | ||
if (!handle) | ||
return TEE_ERROR_GENERIC; | ||
|
||
ctor_test_fn = (TEE_Result (*)(void))dlsym(handle, | ||
"os_test_shlib_dl_cxx_ctor"); | ||
if (ctor_test_fn) | ||
res = ctor_test_fn(); | ||
|
||
dlclose(handle); | ||
return res; | ||
} | ||
|
||
class MyException { | ||
}; | ||
|
||
TEE_Result ta_entry_cxx_exc_main(void) | ||
{ | ||
try { | ||
throw MyException(); | ||
} catch (MyException &e) { | ||
return TEE_SUCCESS; | ||
} | ||
|
||
return TEE_ERROR_GENERIC; | ||
} | ||
|
||
class MixedFrameException { | ||
}; | ||
|
||
void throw_mfe(void) | ||
{ | ||
throw MixedFrameException(); | ||
} | ||
|
||
class MixedFrameExceptionTest { | ||
public: | ||
MixedFrameExceptionTest() {} | ||
|
||
bool test(); | ||
}; | ||
|
||
bool MixedFrameExceptionTest::test() | ||
{ | ||
try { | ||
throwing_c_func(); | ||
} catch (MixedFrameException e) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
TEE_Result ta_entry_cxx_exc_mixed(void) | ||
{ | ||
MixedFrameExceptionTest test; | ||
|
||
if (test.test()) | ||
return TEE_SUCCESS; | ||
|
||
return TEE_ERROR_GENERIC; | ||
} |
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,12 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
*/ | ||
|
||
#ifndef CXX_TESTS_H | ||
#define CXX_TESTS_H | ||
|
||
void throw_mfe(void); | ||
void throwing_c_func(void); | ||
|
||
#endif /* CXX_TESTS_H */ |
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,11 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
*/ | ||
|
||
#include "cxx_tests.h" | ||
|
||
void throwing_c_func(void) | ||
{ | ||
throw_mfe(); | ||
} |
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
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,26 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
*/ | ||
|
||
extern "C" { | ||
#include "os_test_lib.h" | ||
#include <tee_api_types.h> | ||
} | ||
|
||
class OsTestLibCtorTest { | ||
public: | ||
OsTestLibCtorTest() : val(2) {} | ||
|
||
int val; | ||
}; | ||
|
||
static OsTestLibCtorTest os_test_lib_ctor_test; | ||
|
||
TEE_Result os_test_shlib_cxx_ctor(void) | ||
{ | ||
if (os_test_lib_ctor_test.val != 2) | ||
return TEE_ERROR_GENERIC; | ||
|
||
return TEE_SUCCESS; | ||
} |
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,2 +1,5 @@ | ||
global-incdirs-y += include | ||
srcs-y += os_test_lib.c | ||
ifneq ($(COMPILER),clang) | ||
srcs-y += os_test_lib_cxx.cpp | ||
endif |
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,26 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2018, Linaro Limited | ||
*/ | ||
|
||
extern "C" { | ||
#include "os_test_lib_dl.h" | ||
#include <tee_api_types.h> | ||
} | ||
|
||
class OsTestLibDlCtorTest { | ||
public: | ||
OsTestLibDlCtorTest() : val(2) {} | ||
|
||
int val; | ||
}; | ||
|
||
static OsTestLibDlCtorTest os_test_lib_dl_ctor_test; | ||
|
||
TEE_Result os_test_shlib_dl_cxx_ctor(void) | ||
{ | ||
if (os_test_lib_dl_ctor_test.val != 2) | ||
return TEE_ERROR_GENERIC; | ||
|
||
return TEE_SUCCESS; | ||
} |
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,2 +1,5 @@ | ||
global-incdirs-y += include | ||
srcs-y += os_test_lib_dl.c | ||
ifneq ($(COMPILER),clang) | ||
srcs-y += os_test_lib_dl_cxx.cpp | ||
endif |