You've already forked linux-packaging-mono
Imported Upstream version 5.20.0.180
Former-commit-id: ff953ca879339fe1e1211f7220f563e1342e66cb
This commit is contained in:
parent
0e2d47d1c8
commit
0510252385
14
external/corert/tests/src/Simple/SharedLibrary/NativeCallable.cs
vendored
Normal file
14
external/corert/tests/src/Simple/SharedLibrary/NativeCallable.cs
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
namespace System.Runtime.InteropServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class NativeCallableAttribute : Attribute
|
||||
{
|
||||
public string EntryPoint;
|
||||
public CallingConvention CallingConvention;
|
||||
public NativeCallableAttribute() { }
|
||||
}
|
||||
}
|
||||
12
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cmd
vendored
Normal file
12
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cmd
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
@echo off
|
||||
setlocal
|
||||
"%1\%2"
|
||||
set ErrorCode=%ERRORLEVEL%
|
||||
IF "%ErrorCode%"=="100" (
|
||||
echo %~n0: pass
|
||||
EXIT /b 0
|
||||
) ELSE (
|
||||
echo %~n0: fail - %ErrorCode%
|
||||
EXIT /b 1
|
||||
)
|
||||
endlocal
|
||||
66
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cpp
vendored
Normal file
66
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cpp
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
// 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.
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "windows.h"
|
||||
#else
|
||||
#include "dlfcn.h"
|
||||
#endif
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#define __stdcall
|
||||
#endif
|
||||
|
||||
// typedef for shared lib exported methods
|
||||
typedef int(__stdcall *f_ReturnsPrimitiveInt)();
|
||||
typedef bool(__stdcall *f_ReturnsPrimitiveBool)();
|
||||
typedef char(__stdcall *f_ReturnsPrimitiveChar)();
|
||||
typedef void(__stdcall *f_EnsureManagedClassLoaders)();
|
||||
|
||||
#ifdef _WIN32
|
||||
int main()
|
||||
#else
|
||||
int main(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
#ifdef _WIN32
|
||||
HINSTANCE handle = LoadLibrary("SharedLibrary.dll");
|
||||
#elif __APPLE__
|
||||
void *handle = dlopen(strcat(argv[0], ".dylib"), RTLD_LAZY);
|
||||
#else
|
||||
void *handle = dlopen(strcat(argv[0], ".so"), RTLD_LAZY);
|
||||
#endif
|
||||
|
||||
if (!handle)
|
||||
return 1;
|
||||
|
||||
#ifdef _WIN32
|
||||
f_ReturnsPrimitiveInt returnsPrimitiveInt = (f_ReturnsPrimitiveInt)GetProcAddress(handle, "ReturnsPrimitiveInt");
|
||||
f_ReturnsPrimitiveBool returnsPrimitiveBool = (f_ReturnsPrimitiveBool)GetProcAddress(handle, "ReturnsPrimitiveBool");
|
||||
f_ReturnsPrimitiveChar returnsPrimitiveChar = (f_ReturnsPrimitiveChar)GetProcAddress(handle, "ReturnsPrimitiveChar");
|
||||
f_EnsureManagedClassLoaders ensureManagedClassLoaders = (f_EnsureManagedClassLoaders)GetProcAddress(handle, "EnsureManagedClassLoaders");
|
||||
#else
|
||||
f_ReturnsPrimitiveInt returnsPrimitiveInt = (f_ReturnsPrimitiveInt)dlsym(handle, "ReturnsPrimitiveInt");
|
||||
f_ReturnsPrimitiveBool returnsPrimitiveBool = (f_ReturnsPrimitiveBool)dlsym(handle, "ReturnsPrimitiveBool");
|
||||
f_ReturnsPrimitiveChar returnsPrimitiveChar = (f_ReturnsPrimitiveChar)dlsym(handle, "ReturnsPrimitiveChar");
|
||||
f_EnsureManagedClassLoaders ensureManagedClassLoaders = (f_EnsureManagedClassLoaders)dlsym(handle, "EnsureManagedClassLoaders");
|
||||
#endif
|
||||
|
||||
if (returnsPrimitiveInt() != 10)
|
||||
return 1;
|
||||
|
||||
if (!returnsPrimitiveBool())
|
||||
return 1;
|
||||
|
||||
if (returnsPrimitiveChar() != 'a')
|
||||
return 1;
|
||||
|
||||
// As long as no unmanaged exception is thrown
|
||||
// managed class loaders were initialized successfully
|
||||
ensureManagedClassLoaders();
|
||||
|
||||
return 100;
|
||||
}
|
||||
37
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cs
vendored
Normal file
37
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.cs
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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;
|
||||
|
||||
namespace SharedLibrary
|
||||
{
|
||||
public class ClassLibrary
|
||||
{
|
||||
[NativeCallable(EntryPoint = "ReturnsPrimitiveInt", CallingConvention = CallingConvention.StdCall)]
|
||||
public static int ReturnsPrimitiveInt()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
[NativeCallable(EntryPoint = "ReturnsPrimitiveBool", CallingConvention = CallingConvention.StdCall)]
|
||||
public static bool ReturnsPrimitiveBool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
[NativeCallable(EntryPoint = "ReturnsPrimitiveChar", CallingConvention = CallingConvention.StdCall)]
|
||||
public static char ReturnsPrimitiveChar()
|
||||
{
|
||||
return 'a';
|
||||
}
|
||||
|
||||
[NativeCallable(EntryPoint = "EnsureManagedClassLoaders", CallingConvention = CallingConvention.StdCall)]
|
||||
public static void EnsureManagedClassLoaders()
|
||||
{
|
||||
Random random = new Random();
|
||||
random.Next();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.csproj
vendored
Normal file
35
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.csproj
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<NativeLib>Shared</NativeLib>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="*.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="NativeRunnerCompile" AfterTargets="LinkNative">
|
||||
<PropertyGroup>
|
||||
<NativeRunnerBinary>$(NativeOutputPath)SharedLibrary</NativeRunnerBinary>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<CppCompile Include="SharedLibrary.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<NativeRunnerCompilerArg Include="@(CppCompile)" />
|
||||
<NativeRunnerCompilerArg Include="-o $(NativeRunnerBinary)" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
<NativeRunnerCompilerArg Include="/Fo$(NativeRunnerBinary)" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
<NativeRunnerCompilerArg Include="/Fe$(NativeRunnerBinary)" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
</ItemGroup>
|
||||
|
||||
<Exec Command="$(CppCompiler) @(NativeRunnerCompilerArg, ' ')" Condition="'$(OS)' != 'Windows_NT'" />
|
||||
<WriteLinesToFile File="$(NativeIntermediateOutputPath)SharedLibrary.cl.rsp" Lines="@(NativeRunnerCompilerArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT'"/>
|
||||
<Exec Command="$(CppCompiler) @"$(NativeIntermediateOutputPath)SharedLibrary.cl.rsp"" Condition="'$(OS)' == 'Windows_NT'" />
|
||||
</Target>
|
||||
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), SimpleTest.targets))\SimpleTest.targets" />
|
||||
|
||||
</Project>
|
||||
9
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.sh
vendored
Executable file
9
external/corert/tests/src/Simple/SharedLibrary/SharedLibrary.sh
vendored
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
$1/$2
|
||||
if [ $? == 100 ]; then
|
||||
echo pass
|
||||
exit 0
|
||||
else
|
||||
echo fail
|
||||
exit 1
|
||||
fi
|
||||
1
external/corert/tests/src/Simple/SharedLibrary/no_cpp
vendored
Normal file
1
external/corert/tests/src/Simple/SharedLibrary/no_cpp
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Skip this test for cpp codegen mode
|
||||
1
external/corert/tests/src/Simple/SharedLibrary/no_linux
vendored
Normal file
1
external/corert/tests/src/Simple/SharedLibrary/no_linux
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Skip this test for linux
|
||||
Reference in New Issue
Block a user