-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tests] Add MonoApi runtime tests #65221
Changes from 39 commits
9e5a43b
529d3ef
e521ae5
beb006e
09c9d21
3bd805b
baa02eb
a4a5c00
bdfc029
243d879
c18a64f
c2acead
7d298df
a3afdc6
8decfb5
1e76e2c
31709ca
b81af1c
c246573
741bdcd
836f37a
aa17935
5803521
95945b8
81cc313
f65c1b4
e746e6f
6bfe2b7
6e4d4aa
ff74d54
ec606ad
75e4097
b368282
541653e
a631c42
4d063ea
d2c30de
3cd562b
6669e05
07c5ec5
0736ff1
8e3aa5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing MIT banner. |
||
using System.Runtime.InteropServices; | ||
|
||
namespace MonoAPI.Tests; | ||
|
||
public class MonoAPISupport | ||
{ | ||
public const string TestLibName = "mono-embedding-api-test"; | ||
|
||
[DllImport(TestLibName)] | ||
private static extern byte libtest_initialize_runtime_symbols(IntPtr libcoreclr_name); | ||
|
||
public static void Setup() | ||
{ | ||
string libName = TestLibrary.XPlatformUtils.GetStandardNativeLibraryFileName("coreclr"); | ||
if (!SetupSymbols(libName)) | ||
throw new Exception ($"Native library could not probe for runtime embedding API symbols in {libName}"); | ||
} | ||
|
||
private static bool SetupSymbols(string libName) | ||
{ | ||
IntPtr ptr = IntPtr.Zero; | ||
byte res = 0; | ||
try { | ||
ptr = Marshal.StringToHGlobalAnsi(libName); | ||
res = libtest_initialize_runtime_symbols(ptr); | ||
} finally { | ||
Marshal.FreeHGlobal(ptr); | ||
} | ||
return res != 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\..\Directory.Build.props" /> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,21 @@ | |
using System.Runtime.InteropServices; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing MIT banner. |
||
using System.Runtime.CompilerServices; | ||
|
||
namespace MonoAPI.Tests.MonoMono.InstallEHCallback; | ||
|
||
public class MonoPInvokeCallbackAttribute : Attribute { | ||
public MonoPInvokeCallbackAttribute (Type delegateType) { } | ||
} | ||
|
||
public class Tests { | ||
public class InstallEHCallback { | ||
|
||
[DllImport ("libtest")] | ||
[DllImport (MonoAPISupport.TestLibName)] | ||
public static extern void mono_test_setjmp_and_call (VoidVoidDelegate del, out IntPtr handle); | ||
|
||
[DllImport ("libtest")] | ||
[DllImport (MonoAPISupport.TestLibName)] | ||
public static extern void mono_test_setup_ftnptr_eh_callback (VoidVoidDelegate del, VoidHandleHandleOutDelegate inside_eh_callback); | ||
|
||
[DllImport ("libtest")] | ||
[DllImport (MonoAPISupport.TestLibName)] | ||
public static extern void mono_test_cleanup_ftptr_eh_callback (); | ||
|
||
public delegate void VoidVoidDelegate (); | ||
|
@@ -168,6 +170,15 @@ public static int test_0_throw_and_raise_exception () | |
|
||
static int Main () | ||
{ | ||
return TestDriver.RunTests (typeof (Tests)); | ||
MonoAPI.Tests.MonoAPISupport.Setup(); | ||
int result; | ||
result = test_0_setjmp_exn_handler (); | ||
if (result != 0) | ||
return 100 + result; | ||
result = test_0_throw_and_raise_exception (); | ||
if (result != 0) | ||
return 100 + result; | ||
return 100; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
<Compile Include="..\Common\*.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Native\mono-embedding-api-test\CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,14 +7,33 @@ | |
using System.Threading; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing MIT banner. |
||
using System.Runtime.InteropServices; | ||
|
||
namespace MonoAPI.Tests.MonoMono.PInvokeDetach; | ||
|
||
public class MonoPInvokeCallbackAttribute : Attribute { | ||
public MonoPInvokeCallbackAttribute (Type delegateType) { } | ||
} | ||
|
||
public class Tests { | ||
public class PInvokeDetach { | ||
const string TestNamespace = "MonoAPI.Tests.MonoMono.PInvokeDetach"; | ||
const string TestName = nameof (PInvokeDetach); | ||
|
||
public static int Main () | ||
{ | ||
return TestDriver.RunTests (typeof (Tests)); | ||
MonoAPI.Tests.MonoAPISupport.Setup(); | ||
int result; | ||
result = test_0_attach_invoke_foreign_thread (); | ||
if (result != 0) | ||
return 100 + result; | ||
result = test_0_attach_invoke_foreign_thread_delegate (); | ||
if (result != 0) | ||
return 100 + result; | ||
result = test_0_attach_invoke_block_foreign_thread (); | ||
if (result != 0) | ||
return 100 + result; | ||
result = test_0_attach_invoke_block_foreign_thread_delegate (); | ||
if (result != 0) | ||
return 100 + result; | ||
return 100; | ||
} | ||
|
||
public delegate void VoidVoidDelegate (); | ||
|
@@ -27,13 +46,13 @@ private static void MethodInvokedFromNative () | |
was_called++; | ||
} | ||
|
||
[DllImport ("libtest", EntryPoint="mono_test_attach_invoke_foreign_thread")] | ||
[DllImport (MonoAPISupport.TestLibName, EntryPoint="mono_test_attach_invoke_foreign_thread")] | ||
public static extern bool mono_test_attach_invoke_foreign_thread (string assm_name, string name_space, string class_name, string method_name, VoidVoidDelegate del); | ||
|
||
public static int test_0_attach_invoke_foreign_thread () | ||
{ | ||
was_called = 0; | ||
bool skipped = mono_test_attach_invoke_foreign_thread (typeof (Tests).Assembly.Location, "", "Tests", "MethodInvokedFromNative", null); | ||
bool skipped = mono_test_attach_invoke_foreign_thread (typeof (PInvokeDetach).Assembly.Location, TestNamespace, TestName, nameof(MethodInvokedFromNative), null); | ||
GC.Collect (); // should not hang waiting for the foreign thread | ||
return skipped || was_called == 5 ? 0 : 1; | ||
} | ||
|
@@ -60,12 +79,12 @@ private static void MethodInvokedFromNative2 () | |
{ | ||
} | ||
|
||
[DllImport ("libtest", EntryPoint="mono_test_attach_invoke_block_foreign_thread")] | ||
[DllImport (MonoAPISupport.TestLibName, EntryPoint="mono_test_attach_invoke_block_foreign_thread")] | ||
public static extern bool mono_test_attach_invoke_block_foreign_thread (string assm_name, string name_space, string class_name, string method_name, VoidVoidDelegate del); | ||
|
||
public static int test_0_attach_invoke_block_foreign_thread () | ||
{ | ||
bool skipped = mono_test_attach_invoke_block_foreign_thread (typeof (Tests).Assembly.Location, "", "Tests", "MethodInvokedFromNative2", null); | ||
bool skipped = mono_test_attach_invoke_block_foreign_thread (typeof (PInvokeDetach).Assembly.Location, TestNamespace, TestName, nameof(MethodInvokedFromNative2), null); | ||
GC.Collect (); // should not hang waiting for the foreign thread | ||
return 0; // really we succeed if the app can shut down without hanging | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
<Compile Include="..\Common\*.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Native\mono-embedding-api-test\CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
using System.Reflection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing MIT banner. |
||
using System.Runtime.InteropServices; | ||
|
||
public class Test | ||
namespace MonoAPI.Tests.MonoMono.Thunks; | ||
|
||
public class Thunks | ||
{ | ||
[DllImport ("libtest")] | ||
[DllImport (MonoAPISupport.TestLibName)] | ||
public static extern int test_method_thunk (int test_id, IntPtr testMethodHandle, | ||
IntPtr createObjectHandle); | ||
|
||
|
@@ -31,14 +33,15 @@ static void RunTests(int series, Type type) | |
|
||
public static int Main () | ||
{ | ||
RunTests (0, typeof (Test)); | ||
MonoAPI.Tests.MonoAPISupport.Setup(); | ||
RunTests (0, typeof (Thunks)); | ||
RunTests (100, typeof (TestStruct)); | ||
return 0; | ||
return 100; | ||
} | ||
|
||
public static object CreateObject () | ||
{ | ||
return new Test (); | ||
return new Thunks (); | ||
} | ||
|
||
public static void Test0 () | ||
|
@@ -102,9 +105,9 @@ public static void Test9 (ref byte a1, ref short a2, ref int a3, ref long a4, re | |
throw new NotImplementedException (); | ||
} | ||
|
||
public static void Test10 (ref Test obj) | ||
public static void Test10 (ref Thunks obj) | ||
{ | ||
obj = new Test (); | ||
obj = new Thunks (); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
<Compile Include="..\Common\*.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Native\mono-embedding-api-test\CMakeLists.txt" /> | ||
</ItemGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
add_subdirectory(mono-embedding-api-test) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.13.0) | ||
project (MonoEmbeddingApiTest) | ||
include_directories(${INC_PLATFORM_DIR}) | ||
|
||
|
||
add_subdirectory(${CLR_SRC_NATIVE_DIR}/public public_api) | ||
|
||
# add the library | ||
add_library (mono-embedding-api-test SHARED mono-embedding-api-test.c api-types.h api-functions.h) | ||
target_link_libraries(mono-embedding-api-test monoapi ${LINK_LIBRARIES_ADDITIONAL}) | ||
|
||
if(CLR_CMAKE_HOST_OSX) | ||
target_compile_definitions(mono-embedding-api-test PRIVATE -DHOST_DARWIN) | ||
elseif(CLR_CMAKE_HOST_WIN32) | ||
target_compile_definitions(mono-embedding-api-test PRIVATE -DHOST_WIN32 -D_CRT_SECURE_NO_WARNINGS) | ||
else() | ||
target_compile_definitions(mono-embedding-api-test PRIVATE -DHOST_LINUX) | ||
endif() | ||
|
||
# add the install targets | ||
install (TARGETS mono-embedding-api-test DESTINATION bin) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file intentionally doesn't have header guards | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing MIT banner. |
||
#include <mono/metadata/details/appdomain-functions.h> | ||
#include <mono/metadata/details/assembly-functions.h> | ||
#include <mono/metadata/details/class-functions.h> | ||
#include <mono/metadata/details/threads-functions.h> | ||
#include <mono/metadata/details/object-functions.h> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
|
||
#ifndef TEST_EMBEDDING_API_TYPES_H | ||
#define TEST_EMBEDDING_API_TYPES_H | ||
|
||
#include <mono/utils/details/mono-publib-types.h> | ||
#include <mono/metadata/details/class-types.h> | ||
#include <mono/metadata/details/object-types.h> | ||
#include <mono/metadata/details/appdomain-types.h> | ||
#include <mono/metadata/details/assembly-types.h> | ||
#include <mono/metadata/details/threads-types.h> | ||
|
||
MONO_BEGIN_DECLS | ||
|
||
|
||
|
||
MONO_END_DECLS | ||
|
||
#endif /*TEST_EMBEDDING_API_TYPES_H*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this up to before the first
if
branch since it should be always done and with that "group".