forked from MKL-NET/MKL.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorTest.cs
More file actions
64 lines (51 loc) · 2.33 KB
/
GeneratorTest.cs
File metadata and controls
64 lines (51 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System.Reflection;
using Xunit;
using FluentAssertions;
namespace MKLNET.WrapperGenerator.Tests;
public class GeneratorTest
{
[Fact]
public void GeneratorShouldAcceptPinvokeStatementAndNotProduceErrors()
{
var inputCompilation = CreateCompilation(@"
using System.Runtime.InteropServices;
namespace MKLNET;
public static partial class BlasOption2
{
public static class Unsafe
{
[DllImport(""dummy.dll"", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, EntryPoint = ""dummy"")]
public static unsafe extern void dummy(int M, int N,
int K, double alpha, double* A,
int lda, double* B, int ldb,
double beta, double* C, int ldc);
public static unsafe extern void summy(int N, double* A, double* B);
}
}
");
var generator = new WrapperGenerator();
GeneratorDriver driver = CSharpGeneratorDriver.Create(generator);
driver = driver.RunGeneratorsAndUpdateCompilation(inputCompilation, out var outputCompilation, out var diagnostics);
diagnostics.Should().BeEmpty();
outputCompilation.SyntaxTrees.Should().HaveCount(2); // input and generated
outputCompilation.GetDiagnostics().Should().BeEmpty();
var runResult = driver.GetRunResult();
runResult.GeneratedTrees.Should().HaveCount(1);
runResult.Diagnostics.Should().BeEmpty();
var generatorResult = runResult.Results[0];
generatorResult.Generator.Should().BeSameAs(generator);
generatorResult.Diagnostics.Should().BeEmpty();
generatorResult.GeneratedSources.Should().ContainSingle()
.Which.SourceText.ToString().Should().Contain(
"///<remarks>" +
"This version infers the length parameter <c>N</c> from <paramref name=\"A\" />'s length.</remarks>");
generatorResult.Exception.Should().BeNull();
}
private static Compilation CreateCompilation(string source)
=> CSharpCompilation.Create("compilation",
new[] { CSharpSyntaxTree.ParseText(source) },
new[] { MetadataReference.CreateFromFile(typeof(Binder).GetTypeInfo().Assembly.Location) },
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true, warningLevel: 0));
}