From dbddcb6e3f74853f2b923986b96f677a45dc820c Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Fri, 13 Nov 2015 17:47:19 -0800 Subject: [PATCH] Add new pal test that tests exceptions across multiple PALs in different modules. Currently disabled for FreeBSD. --- .../palsuite/exception_handling/CMakeLists.txt | 1 + .../exception_handling/pal_sxs/CMakeLists.txt | 4 + .../pal_sxs/test1/CMakeLists.txt | 88 ++++++++++++++++++++++ .../exception_handling/pal_sxs/test1/dlltest1.cpp | 71 +++++++++++++++++ .../exception_handling/pal_sxs/test1/dlltest1.src | 3 + .../exception_handling/pal_sxs/test1/dlltest2.cpp | 71 +++++++++++++++++ .../exception_handling/pal_sxs/test1/dlltest2.src | 3 + .../pal_sxs/test1/exceptionsxs.cpp | 40 ++++++++++ .../exception_handling/pal_sxs/test1/testinfo.dat | 13 ++++ src/pal/tests/palsuite/paltestlist.txt | 1 + 10 files changed, 295 insertions(+) create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.src create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.src create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/exceptionsxs.cpp create mode 100644 src/pal/tests/palsuite/exception_handling/pal_sxs/test1/testinfo.dat diff --git a/src/pal/tests/palsuite/exception_handling/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/CMakeLists.txt index 180d572..d0de335 100644 --- a/src/pal/tests/palsuite/exception_handling/CMakeLists.txt +++ b/src/pal/tests/palsuite/exception_handling/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 2.8.12.2) +add_subdirectory(pal_sxs) #add_subdirectory(pal_except) #add_subdirectory(PAL_EXCEPT_FILTER) #add_subdirectory(PAL_EXCEPT_FILTER_EX) diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_sxs/CMakeLists.txt new file mode 100644 index 0000000..f6aa0cb --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt new file mode 100644 index 0000000..949fe92 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/CMakeLists.txt @@ -0,0 +1,88 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +if(CLR_CMAKE_PLATFORM_UNIX) + add_compile_options(-fPIC) +endif(CLR_CMAKE_PLATFORM_UNIX) + +# Test DLL1 + +set(DEF_SOURCES1 dlltest1.src) +convert_to_absolute_path(DEF_SOURCES1 ${DEF_SOURCES1}) +set(EXPORTS_FILE1 ${CMAKE_CURRENT_BINARY_DIR}/dlltest1.exports) +generate_exports_file(${DEF_SOURCES1} ${EXPORTS_FILE1}) + +if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + set(EXPORTS_LINKER_OPTION1 -Wl,--version-script=${EXPORTS_FILE1}) +endif(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + +if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(EXPORTS_LINKER_OPTION1 -Wl,-exported_symbols_list,${EXPORTS_FILE1}) +endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + +set(DLL1SOURCES dlltest1.cpp) +add_library(paltest_pal_sxs_test1_dll1 SHARED ${DLL1SOURCES}) +add_custom_target(dlltest1_exports DEPENDS ${EXPORTS_FILE1}) +set_property(TARGET paltest_pal_sxs_test1_dll1 APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION1}) +set_property(TARGET paltest_pal_sxs_test1_dll1 APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE1}) + +add_dependencies(paltest_pal_sxs_test1_dll1 + dlltest1_exports + coreclrpal +) + +target_link_libraries(paltest_pal_sxs_test1_dll1 + pthread + m + coreclrpal +) + +# Test DLL2 + +set(DEF_SOURCES2 dlltest2.src) +convert_to_absolute_path(DEF_SOURCES2 ${DEF_SOURCES2}) +set(EXPORTS_FILE2 ${CMAKE_CURRENT_BINARY_DIR}/dlltest2.exports) +generate_exports_file(${DEF_SOURCES2} ${EXPORTS_FILE2}) + +if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + set(EXPORTS_LINKER_OPTION2 -Wl,--version-script=${EXPORTS_FILE2}) +endif(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) + +if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(EXPORTS_LINKER_OPTION2 -Wl,-exported_symbols_list,${EXPORTS_FILE2}) +endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + +set(DLL2SOURCES dlltest2.cpp) +add_library(paltest_pal_sxs_test1_dll2 SHARED ${DLL2SOURCES}) +add_custom_target(dlltest2_exports DEPENDS ${EXPORTS_FILE2}) +set_property(TARGET paltest_pal_sxs_test1_dll2 APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION2}) +set_property(TARGET paltest_pal_sxs_test1_dll2 APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE2}) + +add_dependencies(paltest_pal_sxs_test1_dll2 + dlltest2_exports + coreclrpal +) + +target_link_libraries(paltest_pal_sxs_test1_dll2 + pthread + m + coreclrpal +) + +# Main program + +set(TESTSOURCES exceptionsxs.cpp) + +add_executable(paltest_pal_sxs_test1 ${TESTSOURCES}) + +add_dependencies(paltest_pal_sxs_test1 + paltest_pal_sxs_test1_dll1 + paltest_pal_sxs_test1_dll2 +) + +target_link_libraries(paltest_pal_sxs_test1 + paltest_pal_sxs_test1_dll1 + paltest_pal_sxs_test1_dll2 +) + diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp new file mode 100644 index 0000000..1928062 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.cpp @@ -0,0 +1,71 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: dlltest1.c (exception_handling\pal_sxs\test1) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block with +** multiple PALs in the process. +** +** +**===================================================================*/ +#include + +extern "C" +int InitializeDllTest1() +{ + return PAL_InitializeDLL(); +} + +BOOL bTry = FALSE; +BOOL bExcept = FALSE; + +extern "C" +int DllTest1() +{ + Trace("Starting pal_sxs test1 DllTest1\n"); + + PAL_TRY(VOID*, unused, NULL) + { + volatile int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail("DllTest1 FAILED\n"); + } + + Trace("DLLTest1 PASSED\n"); + + return PASS; +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.src b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.src new file mode 100644 index 0000000..0a0a6ee --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest1.src @@ -0,0 +1,3 @@ +InitializeDllTest1 +DllTest1 + diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp new file mode 100644 index 0000000..45413d5 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.cpp @@ -0,0 +1,71 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: dlltest2.c (exception_handling\pal_sxs\test1) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block with +** multiple PALs in the process. +** +** +**===================================================================*/ +#include + +extern "C" +int InitializeDllTest2() +{ + return PAL_InitializeDLL(); +} + +BOOL bTry = FALSE; +BOOL bExcept = FALSE; + +extern "C" +int DllTest2() +{ + Trace("Starting pal_sxs test1 DllTest2\n"); + + PAL_TRY(VOID*, unused, NULL) + { + volatile int* p = 0x00000000; /* NULL pointer */ + + bTry = TRUE; /* indicate we hit the PAL_TRY block */ + *p = 13; /* causes an access violation exception */ + + Fail("ERROR: code was executed after the access violation.\n"); + } + PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + if (!bTry) + { + Fail("ERROR: PAL_EXCEPT was hit without PAL_TRY being hit.\n"); + } + + bExcept = TRUE; /* indicate we hit the PAL_EXCEPT block */ + } + PAL_ENDTRY; + + if (!bTry) + { + Trace("ERROR: the code in the PAL_TRY block was not executed.\n"); + } + + if (!bExcept) + { + Trace("ERROR: the code in the PAL_EXCEPT block was not executed.\n"); + } + + /* did we hit all the code blocks? */ + if(!bTry || !bExcept) + { + Fail("DllTest2 FAILED\n"); + } + + Trace("DLLTest2 PASSED\n"); + + return PASS; +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.src b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.src new file mode 100644 index 0000000..433419b --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/dlltest2.src @@ -0,0 +1,3 @@ +InitializeDllTest2 +DllTest2 + diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/exceptionsxs.cpp b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/exceptionsxs.cpp new file mode 100644 index 0000000..c9422d1 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/exceptionsxs.cpp @@ -0,0 +1,40 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +/*===================================================================== +** +** Source: exceptionsxs.c (exception_handling\pal_sxs\test1) +** +** Purpose: Test to make sure the PAL_EXCEPT block is executed +** after an exception occurs in the PAL_TRY block with +** multiple PALs in the process. +** +** +**===================================================================*/ + +extern "C" int InitializeDllTest1(); +extern "C" int InitializeDllTest2(); +extern "C" int DllTest1(); +extern "C" int DllTest2(); + +int __cdecl main(int argc, char *argv[]) +{ +#ifndef __FreeBSD__ + if (0 != InitializeDllTest1()) + { + return 1; + } + + if (0 != InitializeDllTest2()) + { + return 1; + } + + DllTest2(); + DllTest1(); + DllTest2(); +#endif + return 0; +} diff --git a/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/testinfo.dat b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/testinfo.dat new file mode 100644 index 0000000..7902979 --- /dev/null +++ b/src/pal/tests/palsuite/exception_handling/pal_sxs/test1/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = exception_handling +Function = test1 +Name = pal_sxs test #1 +TYPE = DEFAULT +EXE1 = test1 +LANG = cpp +Description +=Tests that exceptions across multiples pals work correctly diff --git a/src/pal/tests/palsuite/paltestlist.txt b/src/pal/tests/palsuite/paltestlist.txt index 2230c43..e03b6a7 100644 --- a/src/pal/tests/palsuite/paltestlist.txt +++ b/src/pal/tests/palsuite/paltestlist.txt @@ -440,6 +440,7 @@ debug_api/OutputDebugStringW/test1/paltest_outputdebugstringw_test1 exception_handling/RaiseException/test1/paltest_raiseexception_test1 exception_handling/RaiseException/test2/paltest_raiseexception_test2 exception_handling/RaiseException/test3/paltest_raiseexception_test3 +exception_handling/pal_sxs/test1/paltest_pal_sxs_test1 filemapping_memmgt/CreateFileMappingA/test1/paltest_createfilemappinga_test1 filemapping_memmgt/CreateFileMappingA/test3/paltest_createfilemappinga_test3 filemapping_memmgt/CreateFileMappingA/test4/paltest_createfilemappinga_test4 -- 2.7.4