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

Use latest SpiceSharp and .NET 8.0 #160

Merged
merged 10 commits into from
Oct 11, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner --version 5.2.0
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner --version 9.0.0
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Include="SpiceSharp" Version="3.1.5" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.1.3" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
54 changes: 35 additions & 19 deletions src/SpiceSharpParser.IntegrationTests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using SpiceSharpParser.Common;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace SpiceSharpParser.IntegrationTests
{
Expand Down Expand Up @@ -140,15 +141,15 @@ public static List<object> RunSimulationsAndReturnExports(SpiceSharpModel reader
{
var dcResult = new List<double>();
result.Add(dcResult);
simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
dcResult.Add(export.Extract());
};
}

if (simulation is OP)
{
simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
var opResult = export.Extract();
result.Add(opResult);
Expand All @@ -159,7 +160,7 @@ public static List<object> RunSimulationsAndReturnExports(SpiceSharpModel reader
{
var tranResult = new List<Tuple<double, double>>();
result.Add(tranResult);
simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
tranResult.Add(new Tuple<double, double>(e.Time, export.Extract()));
};
Expand All @@ -168,7 +169,10 @@ public static List<object> RunSimulationsAndReturnExports(SpiceSharpModel reader

foreach (var simulation in readerResult.Simulations)
{
simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
codes = simulation.AttachEvents(codes);

codes.ToArray(); //eval
}

return result;
Expand All @@ -185,7 +189,10 @@ public static void RunSimulations(SpiceSharpModel readerResult)
{
foreach (var simulation in readerResult.Simulations)
{
simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
codes = simulation.AttachEvents(codes);

codes.ToArray(); // eval
}
}

Expand All @@ -194,13 +201,14 @@ public static double RunOpSimulation(SpiceSharpModel readerResult, string nameOf
double result = double.NaN;
var export = readerResult.Exports.Find(e => e.Name == nameOfExport);
var simulation = readerResult.Simulations.Single();
simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
result = export.Extract();
};

simulation.Run(readerResult.Circuit);

var codes = simulation.Run(readerResult.Circuit, -1);
codes = simulation.AttachEvents(codes);
codes.ToArray(); // eval
return result;
}

Expand All @@ -209,16 +217,18 @@ public static double[] RunOpSimulation(SpiceSharpModel readerResult, params stri
var simulation = readerResult.Simulations.Single();
double[] result = new double[nameOfExport.Length];

simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
for (var i = 0; i < nameOfExport.Length; i++)
{
var export = readerResult.Exports.Find(exp => exp.Name == nameOfExport[i]);
result[i] = export.Extract();
}
};

simulation.Run(readerResult.Circuit);

var codes = simulation.Run(readerResult.Circuit, -1);
var attached = simulation.AttachEvents(codes);
attached.ToArray(); // eval

return result;
}
Expand All @@ -228,7 +238,7 @@ public static Tuple<string, double>[] RunOpSimulation(SpiceSharpModel readerResu
var simulation = readerResult.Simulations.First(s => s is OP);
Tuple<string, double>[] result = new Tuple<string, double>[readerResult.Exports.Count];

simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
for (var i = 0; i < readerResult.Exports.Count; i++)
{
Expand All @@ -244,7 +254,9 @@ public static Tuple<string, double>[] RunOpSimulation(SpiceSharpModel readerResu
}
};

simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
var attached = simulation.AttachEvents(codes);
attached.ToArray(); // eval

return result;
}
Expand All @@ -255,12 +267,14 @@ public static Tuple<double, double>[] RunTransientSimulation(SpiceSharpModel rea

var export = readerResult.Exports.Find(e => e.Name == nameOfExport && e.Simulation is Transient);
var simulation = readerResult.Simulations.First(s => s is Transient);
simulation.ExportSimulationData += (sender, e) =>
simulation.EventExportData += (sender, e) =>
{
list.Add(new Tuple<double, double>(e.Time, export.Extract()));
};

simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
var attached = simulation.AttachEvents(codes);
attached.ToArray(); // eval

return list.ToArray();
}
Expand All @@ -270,13 +284,15 @@ public static Tuple<double, double>[] RunDCSimulation(SpiceSharpModel readerResu
var list = new List<Tuple<double, double>>();

var export = readerResult.Exports.Find(e => e.Name == nameOfExport && e.Simulation is DC);
var simulation = readerResult.Simulations.First(s => s is DC);
simulation.ExportSimulationData += (sender, e) =>
var simulation = readerResult.Simulations.First(s => s is DC d);
simulation.EventExportData += (sender, e) =>
{
list.Add(new Tuple<double, double>(e.GetSweepValues().First(), export.Extract()));
list.Add(new Tuple<double, double>(((DC)simulation).GetCurrentSweepValue().Last(), export.Extract()));
};

simulation.Run(readerResult.Circuit);
var codes = simulation.Run(readerResult.Circuit, -1);
var attached = simulation.AttachEvents(codes);
attached.ToArray(); // eval

return list.ToArray();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using SpiceSharp.Simulations;
using SpiceSharpParser.Common;
using SpiceSharpParser.ModelReaders.Netlist.Spice;
using System;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

Expand Down Expand Up @@ -129,7 +131,10 @@ public void When_DistributionNameSensitive_Positive_Expect_NoException()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

spiceModel.Simulations[0].Run(spiceModel.Circuit);
var codes = spiceModel.Simulations[0].Run(spiceModel.Circuit, -1);
codes = spiceModel.Simulations[0].AttachEvents(codes);

codes.ToArray();
}

[Fact]
Expand All @@ -153,8 +158,11 @@ public void When_DistributionNameSensitive_Negative_Expect_Exception()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

Assert.Throws<ArgumentException>(() =>
spiceModel.Simulations[0].Run(spiceModel.Circuit));
var codes = spiceModel.Simulations[0].Run(spiceModel.Circuit, -1);
codes = spiceModel.Simulations[0].AttachEvents(codes);


Assert.Throws<ArgumentException>(() => codes.ToArray());
}

[Fact]
Expand All @@ -179,7 +187,7 @@ public void BuiltInFunctionNamePositive()
reader.Settings.CaseSensitivity.IsDistributionNameCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

var exception = Record.Exception(() => spiceModel.Simulations[0].Run(spiceModel.Circuit));
var exception = Record.Exception(() => spiceModel.Simulations[0].Run(spiceModel.Circuit).ToArray());
Assert.Null(exception);

}
Expand Down Expand Up @@ -291,7 +299,7 @@ public void ComponentNamesException()
reader.Settings.CaseSensitivity.IsEntityNamesCaseSensitive = true;
var spiceModel = reader.Read(parseResult.FinalModel);

Assert.Throws<SpiceSharp.BehaviorsNotFoundException>(() => RunOpSimulation(spiceModel, "I(r1)"));
Assert.Throws<SpiceSharpParserException>(() => RunOpSimulation(spiceModel, "I(r1)"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ public void When_InvalidExportForSimulationWithoutFilter_Expect_Reference()
"R1 IN OUT 10e3",
"C1 OUT 0 10e-6",
".OP",
".PRINT V(OUT) I(C1)",
".PRINT V(OUT)",
".END");
RunSimulations(model);

Assert.Single(model.Prints);
Assert.Equal("#1 OP", model.Prints[0].Name);
Assert.Single(model.Prints[0].ColumnNames);
Assert.Single(model.Prints[0].Rows[0].Columns);
Assert.Single(model.Prints[0].Rows);
}

Expand Down Expand Up @@ -164,7 +163,6 @@ public void When_PrintOpWithoutArgumentsWithoutFilter_Expect_Reference()
Assert.Equal("V(IN)", model.Prints[0].ColumnNames[2]);
Assert.Equal("V(0)", model.Prints[0].ColumnNames[3]);
Assert.Equal("V(OUT)", model.Prints[0].ColumnNames[4]);

Assert.Single(model.Prints[0].Rows);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@


<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="SpiceSharp" Version="3.1.5" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.1.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.console" Version="2.4.2">
<PackageReference Include="xunit.runner.console" Version="2.9.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 10 additions & 4 deletions src/SpiceSharpParser.IntegrationTests/Waveforms/PulseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Test01()
var simulation = netlist.Simulations.First(s => s is Transient);
bool riseHit = false, risenHit = false, fallHit = false, fallenHit = false;

simulation.ExportSimulationData += (sender, args) =>
simulation.EventExportData += (sender, args) =>
{
if (Math.Abs(args.Time - 0.2) < 1e-12)
riseHit = true;
Expand All @@ -34,7 +34,8 @@ public void Test01()
fallenHit = true;
};

simulation.Run(netlist.Circuit);
var events = simulation.Run(netlist.Circuit);
simulation.AttachEvents(events).ToArray();

Assert.True(riseHit);
Assert.True(risenHit);
Expand All @@ -57,7 +58,7 @@ public void Test02()
var simulation = netlist.Simulations.First(s => s is Transient);
bool riseHit = false, risenHit = false, fallHit = false, fallenHit = false;

simulation.ExportSimulationData += (sender, args) =>
simulation.EventExportData += (sender, args) =>
{
if (Math.Abs(args.Time - 0.2) < 1e-12)
riseHit = true;
Expand All @@ -69,7 +70,12 @@ public void Test02()
fallenHit = true;
};

simulation.Run(netlist.Circuit);

var events = simulation.Run(netlist.Circuit);
var codes = simulation.AttachEvents(events);

//eval
codes.ToArray();

Assert.True(riseHit);
Assert.True(risenHit);
Expand Down
9 changes: 6 additions & 3 deletions src/SpiceSharpParser.IntegrationTests/Waveforms/PwlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Test01()
var wasHit1 = false;
var wasHit2 = false;

simulation.ExportSimulationData += (sender, args) =>
simulation.EventExportData += (sender, args) =>
{
if (args.Time == 1.111)
{
Expand All @@ -39,10 +39,13 @@ public void Test01()
wasHit2 = true;
}

Assert.True(EqualsWithTol(2.0, args.GetVoltage("a")));
Assert.True(EqualsWithTol(2.0, simulation.GetVoltage("a")));
};

simulation.Run(netlist.Circuit);
var codes = simulation.Run(netlist.Circuit);
var withEvents = simulation.AttachEvents(codes);

withEvents.ToArray(); //eval

Assert.True(wasHit1);
Assert.True(wasHit2);
Expand Down
Loading
Loading