Skip to content
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

Merge master to nullness #6637

Merged
2 commits merged into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Component.NuGet",
"Microsoft.Net.Component.4.6.1.TargetingPack",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
"Microsoft.VisualStudio.Component.FSharp",
"Microsoft.Net.Core.Component.SDK.2.1",
"Microsoft.NetCore.ComponentGroup.DevelopmentTools.2.1",
"Microsoft.Net.Component.4.7.2.SDK",
"Microsoft.Net.Component.4.7.2.TargetingPack",
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.TextTemplating",
"Microsoft.VisualStudio.Component.SQL.CLR",
"Microsoft.VisualStudio.Component.ManagedDesktop.Core",
"Microsoft.Net.Component.4.6.TargetingPack",
"Component.Microsoft.VisualStudio.LiveShare",
"Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
"Microsoft.VisualStudio.Component.Debugger.JustInTime",
"Microsoft.VisualStudio.Component.FSharp.Desktop",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Component.VSSDK",
"Microsoft.VisualStudio.ComponentGroup.VisualStudioExtension.Prerequisites",
"Microsoft.VisualStudio.Workload.VisualStudioExtension"
]
}
17 changes: 12 additions & 5 deletions eng/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ param (
[switch]$warnAsError = $true,
[switch][Alias('test')]$testDesktop,
[switch]$testCoreClr,
[switch]$testFSharpCompiler,
[switch]$testFSharpQA,
[switch]$testCambridge,
[switch]$testCompiler,
[switch]$testFSharpCore,
[switch]$testFSharpQA,
[switch]$testVs,
[switch]$testAll,

Expand Down Expand Up @@ -76,11 +77,12 @@ function Print-Usage() {
Write-Host ""
Write-Host "Test actions"
Write-Host " -testAll Run all tests"
Write-Host " -testCambridge Run Cambridge tests"
Write-Host " -testCompiler Run FSharpCompiler unit tests"
Write-Host " -testDesktop Run tests against full .NET Framework"
Write-Host " -testCoreClr Run tests against CoreCLR"
Write-Host " -testFSharpCompiler Run F# Compiler unit tests"
Write-Host " -testFSharpQA Run F# Cambridge tests"
Write-Host " -testFSharpCore Run FSharpCore unit tests"
Write-Host " -testFSharpQA Run F# Cambridge tests"
Write-Host " -testVs Run F# editor unit tests"
Write-Host ""
Write-Host "Advanced settings:"
Expand Down Expand Up @@ -285,11 +287,16 @@ try {
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Core.UnitTests\FSharp.Core.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
}

if ($testFSharpCompiler) {
if ($testCompiler) {
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj" -targetFramework $desktopTargetFramework
TestUsingNUnit -testProject "$RepoRoot\tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj" -targetFramework $coreclrTargetFramework
}

if ($testCambridge) {
TestUsingNUnit -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $desktopTargetFramework
TestUsingNUnit -testProject "$RepoRoot\tests\fsharp\FSharpSuite.Tests.fsproj" -targetFramework $coreclrTargetFramework
}

if ($testVs) {
TestUsingNUnit -testProject "$RepoRoot\vsintegration\tests\GetTypesVS.UnitTests\GetTypesVS.UnitTests.fsproj" -targetFramework $desktopTargetFramework
TestUsingNUnit -testProject "$RepoRoot\vsintegration\tests\UnitTests\VisualFSharp.UnitTests.fsproj" -targetFramework $desktopTargetFramework
Expand Down
24 changes: 12 additions & 12 deletions src/absil/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,18 +1500,18 @@ let enablePInvoke = true
// but we can run on Netcoreapp3.0 so ... use reflection to invoke the api, when we are executing on netcoreapp3.0
let definePInvokeMethod =
typeof<TypeBuilder>.GetMethod("DefinePInvokeMethod", [|
typeof<string>;
typeof<string>;
typeof<string>;
typeof<System.Reflection.MethodAttributes>;
typeof<System.Reflection.CallingConventions>;
typeof<Type>;
typeof<Type[]>;
typeof<Type[]>;
typeof<Type[]>;
typeof<Type[][]>;
typeof<Type[][]>;
typeof<System.Runtime.InteropServices.CallingConvention>;
typeof<string>
typeof<string>
typeof<string>
typeof<System.Reflection.MethodAttributes>
typeof<System.Reflection.CallingConventions>
typeof<Type>
typeof<Type[]>
typeof<Type[]>
typeof<Type[]>
typeof<Type[][]>
typeof<Type[][]>
typeof<System.Runtime.InteropServices.CallingConvention>
typeof<System.Runtime.InteropServices.CharSet> |])

let enablePInvoke = definePInvokeMethod <> null
Expand Down
153 changes: 27 additions & 126 deletions tests/fsharp/core/pinvoke/test.fsx
Original file line number Diff line number Diff line change
@@ -1,138 +1,20 @@
// #Conformance #Interop #PInvoke #Structs

#if TESTS_AS_APP
module Core_csext
#endif

#nowarn "9"
open System
open System.Runtime.InteropServices
open System.Windows.Forms
open System.Drawing

let failures = ref []

[<DllImport("cards.dll")>]
let cdtInit((width: IntPtr), (height: IntPtr)) : unit = ()

let pinned (obj: obj) f =
let gch = GCHandle.Alloc(obj,GCHandleType.Pinned) in
try f(gch.AddrOfPinnedObject())
finally
gch.Free()

//The following types from the System namespace are blittable types:
//
//System.Byte
//System.SByte
//System.Int16
//System.UInt16
//System.Int32
//System.UInt32
//System.Int64
//System.IntPtr
//System.UIntPtr
//The following complex types are also blittable types:
//One-dimensional arrays of blittable types, such as an array of integers.
//Formatted value types that contain only blittable types (and classes if they are marshaled as formatted types).

//
// assert ((typeof<'a>) == (typeof<int>) or
// (typeof<'a>) == (typeof<int64>) or
// etc.

type PinBox<'a> =
{ v : obj }
static member Create(x) = { v = box(x) }
member x.Value = (unbox x.v : 'a)
member x.Pin(f) = pinned(x.v) f

let card_init () =
let width = PinBox<_>.Create(300) in
let height = PinBox<_>.Create(400) in
width.Pin (fun widthAddress ->
height.Pin (fun heightAddress ->
cdtInit (widthAddress, heightAddress)));
Printf.printf "width = %d\n" width.Value;
Printf.printf "height = %d\n" height.Value;
()

do card_init()

let asciiz (pBytes: nativeptr<sbyte>) = new System.String(pBytes)

#nowarn "0044";;
#nowarn "0051";;

open System
open System.Runtime.InteropServices
open Microsoft.FSharp.NativeInterop

type voidptr = System.IntPtr

//int (*derivs)(double, double [], double [], void *),
type DerivsFunction = delegate of double * double nativeptr * double nativeptr * voidptr -> int

//int (*outputFn)(double, double*, void*) );
type OutputFunction = delegate of double * double nativeptr * voidptr -> int

[<DllImport("PopDyn.dll")>]
// Wrap the C function with the following signature:
//
extern int SolveODE2(double *ystart, int nvar, double x1, double x2, double eps, double h1,
double hmin, double hmax, int *nok, int *nbad, double dx, void *info,
DerivsFunction derivs,
OutputFunction outputFn);
module Array =
let inline pinObjUnscoped (obj: obj) = GCHandle.Alloc(obj,GCHandleType.Pinned)

let inline pinObj (obj: obj) f =
let gch = pinObjUnscoped obj
try f gch
finally
gch.Free()

[<NoDynamicInvocation>]
let inline pin (arr: 'T []) (f : nativeptr<'T> -> 'U) =
pinObj (box arr) (fun _ -> f (&&arr.[0]))


type NativeArray<'T when 'T : unmanaged>(ptr : nativeptr<'T>, len: int) =
member x.Ptr = ptr
[<NoDynamicInvocation>]
member inline x.Item
with get n = NativePtr.get x.Ptr n
and set n v = NativePtr.set x.Ptr n v
member x.Length = len
// Provide a nicer wrapper for use from F# code. This takes an F# array as input,
// and when the callbacks happen wraps up the returned native arrays in the
// F# NativeArray thin wrapper which lets you use nice syntax arr.[n] for getting and
// setting values of these arrays.
let solveODE ystart (x1,x2,eps,h1,hmin,hmax) (nok,nbad) dx derivs outputFn =
Array.pin ystart (fun ystartAddr ->
let nvar = Array.length ystart in
let mutable nok = nok in
let mutable nbad = nbad in
let info = 0n in
let derivsF = new DerivsFunction(fun x arr1 arr2 _ -> derivs x (new NativeArray<_>(arr1,nvar)) (new NativeArray<_>(arr2,nvar))) in
let outputFnF = new OutputFunction(fun x pY _ -> outputFn x) in
SolveODE2(ystartAddr,nvar,x1,x2,eps,h1,hmin,hmax,&&nok,&&nbad,dx,info,derivsF,outputFnF))

let example1() =
solveODE
// initial values
[| 1.0; 2.0 |]
// settings
(1.0,2.0,0.0001,1.0,1.0,1.0)
// nok,nbad
(10,20)
// dx
0.05
// Compute the derivatives. Note outp and inp are both NativeArrays, passed to us from C.
// So there is no bounds checking on these assignments - be careful!
// If it turns out that these arrays are of static known size then we can do better here.
(fun x inp outp ->
outp.[0] <- inp.[0] + 0.05; 1)
// output
(fun v -> printf "v = %G\n" v; 5)


let report_failure (s : string) =
stderr.Write" NO: "
stderr.WriteLine s
failures := !failures @ [s]

module GetSystemTimeTest =
open System
Expand Down Expand Up @@ -241,3 +123,22 @@ module MemoryStatusTest2 =

main()

(*--------------------*)

#if TESTS_AS_APP
let RUN() = !failures
#else
let aa =
match !failures with
| [] ->
stdout.WriteLine "Test Passed"
System.IO.File.WriteAllText("test.ok","ok")
exit 0
| messages ->
printfn "%A" messages
stdout.WriteLine "Test Failed"
exit 1
#endif



15 changes: 14 additions & 1 deletion tests/fsharp/single-test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ let generateProjectArtifacts (pc:ProjectConfiguration) outputType (targetFramewo

generateProjBody

let lockObj = obj()
let singleTestBuildAndRunCore cfg copyFiles p =
let sources = []
let loadSources = []
Expand All @@ -222,7 +223,19 @@ let singleTestBuildAndRunCore cfg copyFiles p =
// optimize = true or false
let executeSingleTestBuildAndRun outputType compilerType targetFramework optimize =
let mutable result = false
let directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() )
let directory =
let mutable result = ""
lock lockObj <| (fun () ->
let rec loop () =
let dir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
if Directory.Exists(dir) then
loop ()
else
Directory.CreateDirectory(dir) |>ignore
dir
result <- loop())
result

let pc = {
OutputType = outputType
Framework = framework
Expand Down
Loading