Skip to content

Commit

Permalink
update sharedlib test, make it pass on darwin (dotnet#4985)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonerdo committed Feb 24, 2018
1 parent 8bf5b8d commit 5c322f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tests/src/Simple/SharedLibrary/SharedLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "dlfcn.h"
#endif
#include "stdio.h"
#include "string.h"

#ifndef _WIN32
#define __stdcall
Expand All @@ -15,14 +16,18 @@ 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("SharedLibrary.dylib", RTLD_LAZY);
void *handle = dlopen(strcat(argv[0], ".dylib"), RTLD_LAZY);
#else
void *handle = dlopen("SharedLibrary.so", RTLD_LAZY);
void *handle = dlopen(strcat(argv[0], ".so"), RTLD_LAZY);
#endif

if (!handle)
Expand All @@ -34,10 +39,10 @@ int main()
f_ReturnsPrimitiveChar returnsPrimitiveChar = (f_ReturnsPrimitiveChar)GetProcAddress(handle, "ReturnsPrimitiveChar");
f_EnsureManagedClassLoaders ensureManagedClassLoaders = (f_EnsureManagedClassLoaders)GetProcAddress(handle, "EnsureManagedClassLoaders");
#else
f_ReturnsPrimitiveInt returnsPrimitiveInt = dlsym(handle, "ReturnsPrimitiveInt");
f_ReturnsPrimitiveBool returnsPrimitiveBool = dlsym(handle, "ReturnsPrimitiveBool");
f_ReturnsPrimitiveChar returnsPrimitiveChar = dlsym(handle, "ReturnsPrimitiveChar");
f_EnsureManagedClassLoaders ensureManagedClassLoaders = dlsym(handle, "EnsureManagedClassLoaders");
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)
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Simple/SharedLibrary/SharedLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

<ItemGroup>
<LibNativeCompilerArg Include="@(ClCompile)" />
<LibNativeCompilerArg Include="-o $(LibNativeObject)" Condition="'$(OS)' != 'Windows_NT'" />
<LibNativeCompilerArg Include="/Fo$(LibNativeObject)" Condition="'$(OS)' == 'Windows_NT'" />
<LibNativeCompilerArg Include="/Fe$(LibNativeObject)" Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup>

<Exec Command="$(CppCompiler) @(LibNativeCompilerArg, ' ')" Condition="'$(OS)' != 'Windows_NT'" />
<WriteLinesToFile File="$(IntermediateOutputPath)lib_native.rsp" Lines="@(LibNativeCompilerArg)" Overwrite="true" Condition="'$(OS)' == 'Windows_NT'"/>
<Exec Command="$(CppCompiler) @&quot;$(IntermediateOutputPath)lib_native.rsp&quot;" Condition="'$(OS)' == 'Windows_NT'" />

Expand Down
9 changes: 9 additions & 0 deletions tests/src/Simple/SharedLibrary/SharedLibrary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
$1/$2
if [ $? == 100 ]; then
echo pass
exit 0
else
echo fail
exit 1
fi

0 comments on commit 5c322f6

Please sign in to comment.