forked from nosami/visualfsharp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved fsharpqa/Libraries/Core/NativeInterop/stackalloc test cases to …
…NUnit (dotnet#9521) * Migrated zerosize01.fs test case * Migrated ofint6401.fs test case * Migrated ofint01.fs test case * Cleanup asserts * Migrated ofDateTime01.fs test case * Migrated constraint01.fs test case * Migrated E_constraint02.fs test case * Migrated E_constraint03.fs test case * Migrated ofenum01.fs test case * Reordered tests * Removed obsolete directory
- Loading branch information
1 parent
b61db99
commit f6a63e7
Showing
12 changed files
with
189 additions
and
188 deletions.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
tests/fsharp/Compiler/Libraries/Core/NativeInterop/StackallocTests.fs
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,187 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.UnitTests | ||
|
||
open NUnit.Framework | ||
open FSharp.Test.Utilities | ||
open FSharp.Compiler.SourceCodeServices | ||
|
||
#nowarn "9" | ||
|
||
[<TestFixture>] | ||
module ``Stackalloc Tests`` = | ||
|
||
type E = | A = 1 | ||
| B = 2 | ||
|
||
[<Test>] | ||
let ``Stackalloc of DateTime``() = | ||
let data = NativeInterop.NativePtr.stackalloc<System.DateTime> 100 | ||
let now = System.DateTime.Now | ||
for i = 0 to 99 do | ||
NativeInterop.NativePtr.set data i now | ||
for i = 0 to 99 do | ||
Assert.areEqual (NativeInterop.NativePtr.get data i) now | ||
|
||
let later = now.AddDays 1. | ||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
datai <- later | ||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
Assert.areEqual datai later | ||
|
||
[<Test>] | ||
let ``Stackalloc of enum``() = | ||
let data = NativeInterop.NativePtr.stackalloc<E> 10 | ||
|
||
for i = 0 to 9 do | ||
NativeInterop.NativePtr.set data i (if (i % 2)=0 then E.A else E.B) | ||
|
||
for i = 0 to 9 do | ||
let expected = if (i % 2) = 0 then E.A else E.B | ||
Assert.areEqual (NativeInterop.NativePtr.get data i) expected | ||
|
||
for i = 0 to 9 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
datai <- (if (i % 2)=1 then E.A else E.B) | ||
|
||
for i = 0 to 9 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
let expected = if (i % 2)=1 then E.A else E.B | ||
Assert.areEqual datai expected | ||
|
||
[<Test>] | ||
let ``Stackalloc of imported enum``() = | ||
Assert.DoesNotThrow (TestDelegate (fun () -> | ||
NativeInterop.NativePtr.stackalloc<System.DayOfWeek> 1 |> ignore)) | ||
|
||
[<Test>] | ||
let ``Stackalloc of imported struct``() = | ||
Assert.DoesNotThrow (TestDelegate (fun () -> | ||
NativeInterop.NativePtr.stackalloc<System.TimeSpan> 1 |> ignore)) | ||
|
||
[<Test>] | ||
let ``Stackalloc of imported class``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
#nowarn "9" | ||
let _ = NativeInterop.NativePtr.stackalloc<System.Object> 1 | ||
""" | ||
FSharpErrorSeverity.Error | ||
1 | ||
(4, 9, 4, 43) | ||
"A generic construct requires that the type 'System.Object' is an unmanaged type" | ||
|
||
[<Test>] | ||
let ``Stackalloc of imported interface``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
#nowarn "9" | ||
let _ = NativeInterop.NativePtr.stackalloc<System.Collections.IEnumerable> 1 | ||
""" | ||
FSharpErrorSeverity.Error | ||
1 | ||
(4, 9, 4, 43) | ||
"A generic construct requires that the type 'System.Collections.IEnumerable' is an unmanaged type" | ||
|
||
[<Test>] | ||
let ``Stackalloc of imported delegate``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
#nowarn "9" | ||
let _ = NativeInterop.NativePtr.stackalloc<System.EventHandler> 1 | ||
""" | ||
FSharpErrorSeverity.Error | ||
1 | ||
(4, 9, 4, 43) | ||
"A generic construct requires that the type 'System.EventHandler' is an unmanaged type" | ||
|
||
[<Test>] | ||
let ``Stackalloc of int``() = | ||
let data = NativeInterop.NativePtr.stackalloc<int> 100 | ||
|
||
for i = 0 to 99 do | ||
NativeInterop.NativePtr.set data i (i*i) | ||
|
||
for i = 0 to 99 do | ||
Assert.areEqual (NativeInterop.NativePtr.get data i) (i*i) | ||
|
||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
datai <- 1-i | ||
|
||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
Assert.areEqual datai (1-i) | ||
|
||
[<Test>] | ||
let ``Stackalloc of int64``() = | ||
let data = NativeInterop.NativePtr.stackalloc<int64> 100 | ||
|
||
for i = 0 to 99 do | ||
NativeInterop.NativePtr.set data i (int64 (i*i)) | ||
for i = 0 to 99 do | ||
Assert.areEqual (NativeInterop.NativePtr.get data i) (int64 (i*i)) | ||
|
||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
datai <- int64 (1-i) | ||
|
||
for i = 0 to 99 do | ||
let datai = NativeInterop.NativePtr.toByRef (NativeInterop.NativePtr.add data i) | ||
Assert.areEqual datai (int64 (1-i)) | ||
|
||
[<Test>] | ||
let ``Stackalloc of managed class``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
#nowarn "9" | ||
type C() = | ||
class | ||
member __.M = 10 | ||
member __.N(x) = x + 1 | ||
end | ||
let _ = NativeInterop.NativePtr.stackalloc<C> 1 | ||
""" | ||
FSharpErrorSeverity.Error | ||
1 | ||
(10, 9, 10, 43) | ||
"A generic construct requires that the type 'C' is an unmanaged type" | ||
|
||
[<Test>] | ||
let ``Stackalloc of managed record``() = | ||
CompilerAssert.TypeCheckSingleError | ||
""" | ||
#nowarn "9" | ||
type R = { A : int } | ||
let _ = NativeInterop.NativePtr.stackalloc<R> 1 | ||
""" | ||
FSharpErrorSeverity.Error | ||
1 | ||
(6, 9, 6, 43) | ||
"A generic construct requires that the type 'R' is an unmanaged type" | ||
|
||
[<Test>] | ||
let ``Stackalloc zero-size``() = | ||
// Regression test for FSHARP1.0: | ||
// stackalloc<System.DateTime> 0 | ||
|
||
let testDelegate = TestDelegate (fun () -> | ||
// check stackalloc 0 -- ok | ||
let data = NativeInterop.NativePtr.stackalloc<System.DateTime> 0 | ||
|
||
// The returned pointer is undefined | ||
// No allocation should happen | ||
let _ = NativeInterop.NativePtr.toNativeInt data | ||
|
||
()) | ||
|
||
Assert.DoesNotThrow testDelegate |
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
12 changes: 0 additions & 12 deletions
12
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/E_constraint02.fs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/E_constraint03.fs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/constraint01.fs
This file was deleted.
Oops, something went wrong.
11 changes: 1 addition & 10 deletions
11
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/env.lst
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
SOURCE=constraint01.fs PRECMD="\$CSC_PIPE /target:library publictypes.cs" PEVER=/MD COMPILE_ONLY=1 SCFLAGS="-r:publictypes.dll" # constraint01.fs | ||
SOURCE=E_constraint02.fs PRECMD="\$CSC_PIPE /target:library publictypes.cs" PEVER=/MD COMPILE_ONLY=1 SCFLAGS="-r:publictypes.dll --test:ErrorRanges" # E_constraint02.fs | ||
SOURCE=E_constraint03.fs PEVER=/MD COMPILE_ONLY=1 SCFLAGS="--test:ErrorRanges" # E_constraint03.fs | ||
|
||
SOURCE=negativesize01.fs PEVER=/MD COMPILE_ONLY=1 # negativesize01.fs | ||
SOURCE=ofDateTime01.fs PEVER=/MD # ofDateTime01.fs | ||
SOURCE=ofenum01.fs PEVER=/MD # ofenum01.fs | ||
SOURCE=ofint01.fs PEVER=/MD # ofint01.fs | ||
SOURCE=ofint6401.fs PEVER=/MD # ofint6401.fs | ||
SOURCE=zerosize01.fs PEVER=/MD # zerosize01.fs | ||
SOURCE=negativesize01.fs PEVER=/MD COMPILE_ONLY=1 # negativesize01.fs |
27 changes: 0 additions & 27 deletions
27
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofDateTime01.fs
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofenum01.fs
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint01.fs
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/ofint6401.fs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/publictypes.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
tests/fsharpqa/Source/Libraries/Core/NativeInterop/stackalloc/zerosize01.fs
This file was deleted.
Oops, something went wrong.