-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Add MonoApi runtime tests (#65221)
Contributes to #64456 Create a new directory src/tests/Interop/MonoAPI for tests that use the mono embedding API. Move the mono libtest.c native library along with managed tests: InstallEHCallback.cs, PInvokeDetach.cs and Thunks.cs to src/tests/Interop/MonoAPI/... The native library (now called mono-embedding-api-test.c) builds on all platforms where we build native support libraries for the runtime tests. The managed tests only run on desktop mono configurations for now. * copy libtest.c from mono to src/tests and add cmake builds * Make it build with the monoapi project * remove mono-compiler.h dependency * Remove dependency on gmodule.h Had to copy the w32_find_symbol code that searches for a symbol in every module. * Remove test library eglib dependency Delete some unrunnable tests. Copy some basic eglib utilities into the test. * Move native embedding API test lib to Interop/MonoAPI/Native * Move install_eh_callback test to src/tests/Interop/MonoAPI/MonoMono * add issues.targets excludes for MonoAPI tests Not expected to run on coreclr or mono on wasm or mobile, for now. * Add PInvokeDetach MonoAPI test * Return exit code 100 on success * Change test class names to be unique * fix win32 and gcc builds * simplify managed code * put all the MonoMono tests in a single directory * Use the new MONO_API_FUNCTION monoapi headers * compile the native library as C, not C++, same as libtest.c in the past * delete many unused test functions * delete unused utilities * Add Thunks.cs tests * Use a common setup method to probe for symbols * simplify the native test library * Make the PInvokeDetach native code sleep less * add MIT banner * skip Thunks test on AOT In the mono/mono repo that test was not expected to work with AOT
- Loading branch information
1 parent
9053aa1
commit 483b8f2
Showing
15 changed files
with
1,299 additions
and
18 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,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
using System; | ||
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; | ||
} | ||
} |
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,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> |
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
13 changes: 13 additions & 0 deletions
13
src/tests/Interop/MonoAPI/MonoMono/InstallEHCallback.csproj
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,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> |
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,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> |
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,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> |
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,2 @@ | ||
|
||
add_subdirectory(mono-embedding-api-test) |
22 changes: 22 additions & 0 deletions
22
src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/CMakeLists.txt
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,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) | ||
|
9 changes: 9 additions & 0 deletions
9
src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/api-functions.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,9 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
// This file intentionally doesn't have header guards | ||
#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> |
21 changes: 21 additions & 0 deletions
21
src/tests/Interop/MonoAPI/Native/mono-embedding-api-test/api-types.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,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*/ |
Oops, something went wrong.