summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/Exceptions/ForeignThread/CMakeLists.txt15
-rw-r--r--tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.cs76
-rw-r--r--tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.csproj43
-rw-r--r--tests/src/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp34
-rw-r--r--tests/src/Exceptions/ForeignThread/project.json35
5 files changed, 203 insertions, 0 deletions
diff --git a/tests/src/Exceptions/ForeignThread/CMakeLists.txt b/tests/src/Exceptions/ForeignThread/CMakeLists.txt
new file mode 100644
index 0000000000..5a16a42f3f
--- /dev/null
+++ b/tests/src/Exceptions/ForeignThread/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required (VERSION 2.6)
+
+project (ForeignThreadExceptionsNative)
+
+include_directories(${INC_PLATFORM_DIR})
+
+set(SOURCES ForeignThreadExceptionsNative.cpp)
+
+# add the executable
+add_library (ForeignThreadExceptionsNative SHARED ${SOURCES})
+
+# add the install targets
+install (TARGETS ForeignThreadExceptionsNative DESTINATION bin)
+
+
diff --git a/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.cs b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.cs
new file mode 100644
index 0000000000..17821abdae
--- /dev/null
+++ b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.cs
@@ -0,0 +1,76 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Runtime.InteropServices;
+
+public delegate void MyCallback();
+
+class ForeignThreadExceptionsTest
+{
+ [DllImport("ForeignThreadExceptionsNative")]
+ public static extern void InvokeCallback(MyCallback callback);
+
+ [DllImport("ForeignThreadExceptionsNative")]
+ public static extern void InvokeCallbackOnNewThread(MyCallback callback);
+
+ public static void MethodThatThrows()
+ {
+ throw new Exception("This is MethodThatThrows.");
+ }
+
+ public static void RunTest()
+ {
+ InvokeCallback(() => {
+ try
+ {
+ MethodThatThrows();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught exception thrown in a function called by a delegate called through Reverse PInvoke.");
+ }
+ });
+
+ InvokeCallbackOnNewThread(() => {
+ try
+ {
+ throw new Exception("Exception from delegate on foreign thread!");
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Caught exception thrown in a delegate called through Reverse PInvoke on a foreign thread.");
+ }
+
+ });
+
+ InvokeCallbackOnNewThread(() => {
+ string s = null;
+ try
+ {
+ int len = s.Length;
+ }
+ catch(Exception e)
+ {
+ Console.WriteLine("Caught hardware exception in a delegate called through Reverse PInvoke on a foreign thread.");
+ }
+ });
+ }
+
+ public static int Main()
+ {
+ try
+ {
+ RunTest();
+ return 100;
+ }
+
+ catch (Exception ex)
+ {
+ Console.WriteLine("Failed to catch an exception! "+ ex.ToString());
+ }
+
+ return 1;
+ }
+} \ No newline at end of file
diff --git a/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.csproj b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.csproj
new file mode 100644
index 0000000000..634bb39d7b
--- /dev/null
+++ b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptions.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <AssemblyName>ForeignThreadExceptions</AssemblyName>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+
+ <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+ </PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ForeignThreadExceptions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="project.json" />
+ </ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="CMakeLists.txt" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
diff --git a/tests/src/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp
new file mode 100644
index 0000000000..2d237b8a27
--- /dev/null
+++ b/tests/src/Exceptions/ForeignThread/ForeignThreadExceptionsNative.cpp
@@ -0,0 +1,34 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "stdio.h"
+
+#pragma warning(push)
+#pragma warning(disable:4265 4577)
+ #include <thread>
+#pragma warning(pop)
+
+
+#if defined _WIN32
+ #define DLL_EXPORT __declspec(dllexport)
+#else
+ #if __GNUC__ >= 4
+ #define DLL_EXPORT __attribute__ ((visibility ("default")))
+ #else
+ #define DLL_EXPORT
+ #endif
+#endif //_WIN32
+
+typedef void (*PFNACTION1)();
+
+extern "C" DLL_EXPORT void InvokeCallback(PFNACTION1 callback)
+{
+ callback();
+}
+
+extern "C" DLL_EXPORT void InvokeCallbackOnNewThread(PFNACTION1 callback)
+{
+ std::thread t1(InvokeCallback, callback);
+ t1.join();
+} \ No newline at end of file
diff --git a/tests/src/Exceptions/ForeignThread/project.json b/tests/src/Exceptions/ForeignThread/project.json
new file mode 100644
index 0000000000..a2e84dc340
--- /dev/null
+++ b/tests/src/Exceptions/ForeignThread/project.json
@@ -0,0 +1,35 @@
+{
+ "dependencies": {
+ "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816",
+ "System.Collections": "4.0.10",
+ "System.Collections.NonGeneric": "4.0.1-rc2-23816",
+ "System.Collections.Specialized": "4.0.1-rc2-23816",
+ "System.ComponentModel": "4.0.1-rc2-23816",
+ "System.Console": "4.0.0-rc2-23816",
+ "System.Diagnostics.Process": "4.1.0-rc2-23816",
+ "System.Globalization": "4.0.10",
+ "System.Globalization.Calendars": "4.0.0",
+ "System.IO": "4.0.10",
+ "System.IO.FileSystem": "4.0.0",
+ "System.IO.FileSystem.Primitives": "4.0.0",
+ "System.Linq": "4.0.1-rc2-23816",
+ "System.Linq.Queryable": "4.0.1-rc2-23816",
+ "System.Reflection": "4.0.10",
+ "System.Reflection.Primitives": "4.0.0",
+ "System.Runtime": "4.1.0-rc2-23816",
+ "System.Runtime.Extensions": "4.0.10",
+ "System.Runtime.Handles": "4.0.0",
+ "System.Runtime.InteropServices": "4.1.0-rc2-23816",
+ "System.Runtime.Loader": "4.0.0-rc2-23816",
+ "System.Text.Encoding": "4.0.10",
+ "System.Threading": "4.0.10",
+ "System.Threading.Thread": "4.0.0-rc2-23816",
+ "System.Xml.ReaderWriter": "4.0.11-rc2-23816",
+ "System.Xml.XDocument": "4.0.11-rc2-23816",
+ "System.Xml.XmlDocument": "4.0.1-rc2-23816",
+ "System.Xml.XmlSerializer": "4.0.11-rc2-23816"
+ },
+ "frameworks": {
+ "dnxcore50": {}
+ }
+}