Skip to content

Commit

Permalink
Merge pull request #166 from SpiceSharp/cir
Browse files Browse the repository at this point in the history
Fix null reference exceptions
  • Loading branch information
marcin-golebiowski authored Jan 7, 2025
2 parents 1386dbf + 772dd9d commit bf21d75
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup dotnet tooling
uses: actions/setup-dotnet@master
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

- name: Restore dependencies
run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* Band pass filter - AC simulation
V1 IN 0 AC 1
LI IN MIDDLE {mc(0.6, tol)}
C1 MIDDLE OUT {mc(10e-6, tol)}
R1 OUT 0 {mc(1000, tol)}
.ac oct 100 1 500
.param tol=0.2
.plot ac v(OUT)
.end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Band pass filter - AC simulation stepping with mc()
V1 IN 0 AC 1
LI IN MIDDLE {mc(0.6, tol)}
C1 MIDDLE OUT {mc(10e-6, tol)}
R1 OUT 0 {mc(1000, tol)}
.ac oct 100 1 500
.step param X 0 10 1
.param tol=0.2
.plot ac v(OUT) merge
.end
44 changes: 44 additions & 0 deletions src/SpiceSharpParser.IntegrationTests/Examples/ExampleBandPass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.IO;
using Xunit;

namespace SpiceSharpParser.IntegrationTests.Examples
{
public class ExampleBandPass : BaseTests
{
[Fact]
public void When_SimulatedBandPass_Expect_NoExceptions()
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_1.cir");
var netlistContent = File.ReadAllText(path);

var parser = new SpiceNetlistParser();
parser.Settings.Lexing.HasTitle = true;

var parseResult = parser.ParseNetlist(netlistContent);

var spiceSharpReader = new SpiceSharpReader();
spiceSharpReader.Settings.ExpandSubcircuits = false;
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);

RunSimulations(spiceSharpModel);
}

[Fact]
public void When_SimulatedBandPass2_Expect_NoExceptions()
{
string path = Path.Combine(Directory.GetCurrentDirectory(), "Examples/Circuits/band-pass_2.cir");
var netlistContent = File.ReadAllText(path);

var parser = new SpiceNetlistParser();
parser.Settings.Lexing.HasTitle = true;

var parseResult = parser.ParseNetlist(netlistContent);

var spiceSharpReader = new SpiceSharpReader();
spiceSharpReader.Settings.ExpandSubcircuits = false;
var spiceSharpModel = spiceSharpReader.Read(parseResult.FinalModel);

RunSimulations(spiceSharpModel);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ProjectGuid>{57920E91-873B-4E66-B0EC-4CAC45007AA9}</ProjectGuid>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -16,12 +16,12 @@


<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PackageReference Include="coverlet.msbuild" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand All @@ -30,7 +30,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -42,6 +42,12 @@
</ItemGroup>

<ItemGroup>
<None Update="Examples\Circuits\band-pass_2.cir">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Examples\Circuits\band-pass_1.cir">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Examples\Circuits\example02.cir">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<ProjectGuid>{53D996E7-8D58-49D0-97F6-71CAD49670A2}</ProjectGuid>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<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.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
11 changes: 6 additions & 5 deletions src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ProjectGuid>{94394567-BC35-43EE-92CB-31AC780305FE}</ProjectGuid>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -14,12 +14,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PackageReference Include="coverlet.msbuild" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
Expand All @@ -32,7 +33,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 7 additions & 7 deletions src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
switch (code)
{
case Simulation.BeforeValidation:
EventBeforeValidation.Invoke(this, EventArgs.Empty);
EventBeforeValidation?.Invoke(this, EventArgs.Empty);
break;

case Simulation.AfterValidation:
EventAfterValidation.Invoke(this, EventArgs.Empty);
EventAfterValidation?.Invoke(this, EventArgs.Empty);
break;

case Simulation.BeforeSetup:
EventBeforeSetup.Invoke(this, EventArgs.Empty);
EventBeforeSetup?.Invoke(this, EventArgs.Empty);
break;
case Simulation.AfterSetup:
EventAfterSetup.Invoke(this, EventArgs.Empty);
EventAfterSetup?.Invoke(this, EventArgs.Empty);
break;
case Simulation.BeforeUnsetup:
EventBeforeUnSetup.Invoke(this, EventArgs.Empty);
EventBeforeUnSetup?.Invoke(this, EventArgs.Empty);
break;

case Simulation.BeforeExecute:
EventBeforeExecute.Invoke(this, EventArgs.Empty);
EventBeforeExecute?.Invoke(this, EventArgs.Empty);

if (this is IBiasingSimulation)
{
Expand All @@ -70,7 +70,7 @@ public IEnumerable<int> InvokeEvents(IEnumerable<int> codes)
break;

case Simulation.AfterExecute:
EventAfterExecute.Invoke(this, EventArgs.Empty);
EventAfterExecute?.Invoke(this, EventArgs.Empty);
break;

case AC.ExportSmallSignal:
Expand Down
10 changes: 5 additions & 5 deletions src/SpiceSharpParser/SpiceSharpParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<ProjectGuid>{DF3DD787-71CC-4C89-9E33-DC4536A52278}</ProjectGuid>
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<Authors>SpiceSharp</Authors>
<PackageProjectUrl>https://github.com/SpiceSharp/SpiceSharpParser</PackageProjectUrl>
<Copyright>Copyright 2024</Copyright>
<Copyright>Copyright 2025</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryUrl>https://github.com/SpiceSharp/SpiceSharpParser</RepositoryUrl>
<RepositoryType></RepositoryType>
Expand All @@ -22,7 +22,7 @@
<StartupObject />
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<LangVersion>latest</LangVersion>
<Version>3.2.3</Version>
<Version>3.2.4</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.5|AnyCPU'">
Expand All @@ -35,10 +35,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
<PackageReference Include="SpiceSharp" Version="3.2.3" />
<PackageReference Include="SpiceSharpBehavioral" Version="3.2.0" />
<PackageReference Include="SpiceSharpGenerator" Version="1.0.7">
<PackageReference Include="SpiceSharpGenerator" Version="1.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit bf21d75

Please sign in to comment.