-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Add native dll resolver #11032
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
Merged
daxian-dbw
merged 15 commits into
PowerShell:master
from
iSazonov:add-native-dll-resolver
Dec 9, 2019
Merged
Add native dll resolver #11032
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ab13ca9
Add native dll resolver
iSazonov c83e8a6
Replace "osx" with "osx-x64"
iSazonov 4bddf37
Fix CodeFactor add Codacy issues
iSazonov 09e2750
Address feedback
iSazonov e17e834
Add test
iSazonov c86989b
Use Null-coalescing assignment
iSazonov aa49b60
Add new test
iSazonov 99c85d1
Add extension
iSazonov 1a92fb6
Fix ext
iSazonov 76776a7
Use EntryPointNotFoundException
iSazonov eba989b
Fix Windows test
iSazonov bf2824a
Fix Unix test
iSazonov c4653b3
Update src/System.Management.Automation/CoreCLR/CorePsAssemblyLoadCon…
iSazonov d28ab8c
Update comment
iSazonov f1207bd
Use ToString().ToLowerInvariant()
iSazonov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
72 changes: 72 additions & 0 deletions
72
test/powershell/engine/Basic/Assembly.LoadNative.Tests.ps1
This file contains hidden or 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,72 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "Can load a native assembly" -Tags "CI" { | ||
|
|
||
| BeforeAll { | ||
| ## The assembly files cannot be removed once they are loaded, unless the current PowerShell session exits. | ||
| ## If we use $TestDrive here, then Pester will try to remove them afterward and result in errors. | ||
| $TempPath = [System.IO.Path]::GetTempFileName() | ||
| if (Test-Path $TempPath) { Remove-Item -Path $TempPath -Force -Recurse } | ||
| New-Item -Path $TempPath -ItemType Directory -Force > $null | ||
|
|
||
| $root = Join-Path $TempPath "testDllNativeFolder" | ||
| New-Item -Path $root -ItemType Directory -Force > $null | ||
|
|
||
| $processArch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLower() | ||
|
|
||
| if ($IsWindows) { | ||
| $arch = "win-" + $processArch | ||
| $nativeDllName = "nativedll.dll" | ||
| $sourceDllName = "hostpolicy.dll" | ||
| } elseif ($IsLinux) { | ||
| $arch = "linux-" + $processArch | ||
| $nativeDllName = "nativedll.so" | ||
| $sourceDllName = "libhostpolicy.so" | ||
| } elseif ($IsMacOs) { | ||
| $arch = "osx-" + $processArch | ||
| $nativeDllName = "nativedll.dylib" | ||
| $sourceDllName = "libhostpolicy.dylib" | ||
| } else { | ||
| throw "Unsupported OS" | ||
| } | ||
|
|
||
| $archFolder = Join-Path $root $arch | ||
| New-Item -Path $archFolder -ItemType Directory -Force > $null | ||
| #New-Item -Path $archFolder\$nativeDllName -ItemType File -Force > $null | ||
| Copy-Item -Path $PSHOME\$sourceDllName -Destination $archFolder\$nativeDllName | ||
|
|
||
| $managedDllPath = Join-Path $root managed.dll | ||
|
|
||
| $source = @" | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
| public class TestNativeClass2 | ||
| { | ||
| public static int Add(int a, int b) | ||
| { | ||
| return (a + b); | ||
| } | ||
|
|
||
| public static void LoadNative() | ||
| { | ||
| TestEntry(); | ||
| } | ||
|
|
||
| [DllImport ("nativedll", CallingConvention = CallingConvention.Cdecl)] | ||
| internal static extern void TestEntry(); | ||
| } | ||
| "@ | ||
|
|
||
| Add-Type -OutputAssembly $managedDllPath -TypeDefinition $source | ||
| Add-Type -Assembly $managedDllPath | ||
| } | ||
|
|
||
| It "Can load native dll" { | ||
| # Managed dll is loaded | ||
| [TestNativeClass2]::Add(1,2) | Should -Be 3 | ||
|
|
||
| # Native dll is loaded from the same managed dll | ||
| { [TestNativeClass2]::LoadNative() } | Should -Throw -ErrorId "EntryPointNotFoundException" | ||
|
daxian-dbw marked this conversation as resolved.
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.