From a73bc16f28d61173e6e7f57b83ae254fe881fd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:14:15 +0100 Subject: [PATCH 1/7] Fix null reference exceptions --- .../Examples/Circuits/band-pass_1.cir | 9 ++++ .../Examples/Circuits/band-pass_2.cir | 10 +++++ .../Examples/ExampleBandPass.cs | 44 +++++++++++++++++++ .../SpiceSharpParser.IntegrationTests.csproj | 6 +++ .../CSharp/Events/ACWithEvents.cs | 14 +++--- src/SpiceSharpParser/SpiceSharpParser.csproj | 8 ++-- 6 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir create mode 100644 src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_2.cir create mode 100644 src/SpiceSharpParser.IntegrationTests/Examples/ExampleBandPass.cs diff --git a/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir new file mode 100644 index 00000000..e04951aa --- /dev/null +++ b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir @@ -0,0 +1,9 @@ +* 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 +.param tol=0.2 +.plot ac v(OUT) +.end diff --git a/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_2.cir b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_2.cir new file mode 100644 index 00000000..b8bd8c10 --- /dev/null +++ b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_2.cir @@ -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 diff --git a/src/SpiceSharpParser.IntegrationTests/Examples/ExampleBandPass.cs b/src/SpiceSharpParser.IntegrationTests/Examples/ExampleBandPass.cs new file mode 100644 index 00000000..f1dfe20c --- /dev/null +++ b/src/SpiceSharpParser.IntegrationTests/Examples/ExampleBandPass.cs @@ -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); + } + } +} diff --git a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj index 6cd3a046..ae365ebe 100644 --- a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj +++ b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj @@ -42,6 +42,12 @@ + + Always + + + Always + Always diff --git a/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs index c64eee27..743d4ee4 100644 --- a/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs +++ b/src/SpiceSharpParser/ModelWriters/CSharp/Events/ACWithEvents.cs @@ -42,25 +42,25 @@ public IEnumerable InvokeEvents(IEnumerable 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) { @@ -70,7 +70,7 @@ public IEnumerable InvokeEvents(IEnumerable codes) break; case Simulation.AfterExecute: - EventAfterExecute.Invoke(this, EventArgs.Empty); + EventAfterExecute?.Invoke(this, EventArgs.Empty); break; case AC.ExportSmallSignal: diff --git a/src/SpiceSharpParser/SpiceSharpParser.csproj b/src/SpiceSharpParser/SpiceSharpParser.csproj index 9626bd10..5aa4de92 100644 --- a/src/SpiceSharpParser/SpiceSharpParser.csproj +++ b/src/SpiceSharpParser/SpiceSharpParser.csproj @@ -5,7 +5,7 @@ netstandard2.0;net6.0;net8.0 SpiceSharp https://github.com/SpiceSharp/SpiceSharpParser - Copyright 2024 + Copyright 2025 true https://github.com/SpiceSharp/SpiceSharpParser @@ -22,7 +22,7 @@ MIT latest - 3.2.3 + 3.2.4 @@ -35,10 +35,10 @@ - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 97205d8c765e2e831fc97769ccb4ae1aba4e65b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:17:02 +0100 Subject: [PATCH 2/7] Update example --- .../Examples/Circuits/band-pass_1.cir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir index e04951aa..92dd4d88 100644 --- a/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir +++ b/src/SpiceSharpParser.IntegrationTests/Examples/Circuits/band-pass_1.cir @@ -1,4 +1,4 @@ -* Band pass filter - AC simulation stepping with mc() +* Band pass filter - AC simulation V1 IN 0 AC 1 LI IN MIDDLE {mc(0.6, tol)} C1 MIDDLE OUT {mc(10e-6, tol)} From 2c76341ada68aa693851b3c2e5c7bc06ce161631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:19:06 +0100 Subject: [PATCH 3/7] Remove .NET 6 support --- src/SpiceSharpParser/SpiceSharpParser.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpiceSharpParser/SpiceSharpParser.csproj b/src/SpiceSharpParser/SpiceSharpParser.csproj index 5aa4de92..33eb6675 100644 --- a/src/SpiceSharpParser/SpiceSharpParser.csproj +++ b/src/SpiceSharpParser/SpiceSharpParser.csproj @@ -2,7 +2,7 @@ {DF3DD787-71CC-4C89-9E33-DC4536A52278} - netstandard2.0;net6.0;net8.0 + netstandard2.0;net8.0 SpiceSharp https://github.com/SpiceSharp/SpiceSharpParser Copyright 2025 From 1bc124a723b03e8c8968ea076a410d6481957c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:20:25 +0100 Subject: [PATCH 4/7] Fix linux build --- .github/workflows/test-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index 7ad6939e..85904555 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -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: From ce2dcb9f550a09073597b0996dc1ff668dd0bce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:24:56 +0100 Subject: [PATCH 5/7] Update packages --- .../SpiceSharpParser.CodeAnalysis.csproj | 2 +- .../SpiceSharpParser.IntegrationTests.csproj | 8 ++++---- .../SpiceSharpParser.PerformanceTests.csproj | 5 +++-- src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj | 9 +++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj b/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj index f33b6c0b..bdf96f85 100644 --- a/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj +++ b/src/SpiceSharpParser.CodeAnalysis/SpiceSharpParser.CodeAnalysis.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj index ae365ebe..1bbf447a 100644 --- a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj +++ b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj @@ -16,12 +16,12 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + @@ -30,7 +30,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj index bb9c6264..fccab413 100644 --- a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj +++ b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj @@ -8,14 +8,15 @@ - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj index bd066ce8..5cbb4772 100644 --- a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj +++ b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj @@ -14,12 +14,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + @@ -32,7 +33,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From ceb08b1b055d5e62422aaf1136bffccfbb4db8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:27:29 +0100 Subject: [PATCH 6/7] Migrate to .NET 8 in test projects --- .../SpiceSharpParser.IntegrationTests.csproj | 2 +- .../SpiceSharpParser.PerformanceTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj index 1bbf447a..9bad3f35 100644 --- a/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj +++ b/src/SpiceSharpParser.IntegrationTests/SpiceSharpParser.IntegrationTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 {57920E91-873B-4E66-B0EC-4CAC45007AA9} false diff --git a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj index fccab413..66eb5ea2 100644 --- a/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj +++ b/src/SpiceSharpParser.PerformanceTests/SpiceSharpParser.PerformanceTests.csproj @@ -3,7 +3,7 @@ Exe {53D996E7-8D58-49D0-97F6-71CAD49670A2} - net6.0 + net8.0 From 772dd9dab87cbf4f4622a0a28b58d98aa77f2793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Go=C5=82=C4=99biowski?= Date: Tue, 7 Jan 2025 20:29:14 +0100 Subject: [PATCH 7/7] Migrate to .NET 8 --- src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj index 5cbb4772..f0e47ffa 100644 --- a/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj +++ b/src/SpiceSharpParser.Tests/SpiceSharpParser.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 {94394567-BC35-43EE-92CB-31AC780305FE} false