You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 KiCad Developers, see AUTHORS.TXT for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifdef KICAD_SPICE
  24. #include <qa_utils/wx_utils/unit_test_utils.h>
  25. #include <boost/test/results_collector.hpp> // To check if the current test failed (to be moved?).
  26. #include <eeschema_test_utils.h>
  27. #include <test_netlist_exporter_spice.h>
  28. #include <wx/ffile.h>
  29. #include <mock_pgm_base.h>
  30. #include <locale_io.h>
  31. class TEST_SIM_REGRESSIONS_FIXTURE : public TEST_NETLIST_EXPORTER_SPICE_FIXTURE
  32. {
  33. public:
  34. TEST_SIM_REGRESSIONS_FIXTURE() :
  35. TEST_NETLIST_EXPORTER_SPICE_FIXTURE()
  36. {
  37. }
  38. ~TEST_SIM_REGRESSIONS_FIXTURE()
  39. {
  40. }
  41. wxFileName GetSchematicPath( const wxString& aBaseName ) override
  42. {
  43. wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
  44. fn.SetName( aBaseName );
  45. fn.SetExt( KiCadSchematicFileExtension );
  46. return fn;
  47. }
  48. wxString GetNetlistPath( bool aTest = false ) override
  49. {
  50. wxFileName netFile = m_schematic.Prj().GetProjectFullName();
  51. if( aTest )
  52. netFile.SetName( netFile.GetName() + "_test" );
  53. netFile.SetExt( "spice" );
  54. return netFile.GetFullPath();
  55. }
  56. unsigned GetNetlistOptions() override
  57. {
  58. unsigned options = NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS
  59. | NETLIST_EXPORTER_SPICE::OPTION_SIM_COMMAND;
  60. if( m_SaveCurrents )
  61. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
  62. if( m_SaveVoltages )
  63. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
  64. if( m_SavesDissipations )
  65. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
  66. return options;
  67. }
  68. public:
  69. bool m_SavesDissipations = false;
  70. bool m_SaveVoltages = true;
  71. bool m_SaveCurrents = true;
  72. };
  73. BOOST_FIXTURE_TEST_CASE( WindowsPaths, TEST_SIM_REGRESSIONS_FIXTURE )
  74. {
  75. LOCALE_IO dummy;
  76. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  77. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  78. TestNetlist( "issue13591" );
  79. TestTranPoint( 100e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
  80. TestTranPoint( 500e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
  81. }
  82. BOOST_FIXTURE_TEST_CASE( ImmediateSBCKT, TEST_SIM_REGRESSIONS_FIXTURE )
  83. {
  84. LOCALE_IO dummy;
  85. m_SaveCurrents = false;
  86. TestNetlist( "issue13431" );
  87. TestTranPoint( 0.005, { { "V(/soft_start)", 2.489 } } );
  88. TestTranPoint( 0.012, { { "V(/soft_start)", 5.100 } } );
  89. }
  90. BOOST_FIXTURE_TEST_CASE( LegacyFixups, TEST_SIM_REGRESSIONS_FIXTURE )
  91. {
  92. LOCALE_IO dummy;
  93. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  94. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  95. TestNetlist( "issue13112" );
  96. TestTranPoint( 0.01, { { "V(out)", -0.060 } } );
  97. TestTranPoint( 0.02, { { "V(out)", 0.856 } } );
  98. }
  99. BOOST_FIXTURE_TEST_CASE( DualNMOSAmp, TEST_SIM_REGRESSIONS_FIXTURE )
  100. {
  101. LOCALE_IO dummy;
  102. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  103. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  104. TestNetlist( "issue13162" );
  105. TestTranPoint( 0.030, { { "V(out)", 0.557 } } );
  106. TestTranPoint( 0.035, { { "V(out)", -1.437 } } );
  107. }
  108. BOOST_FIXTURE_TEST_CASE( VariableSubstitutions, TEST_SIM_REGRESSIONS_FIXTURE )
  109. {
  110. LOCALE_IO dummy;
  111. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  112. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  113. TestNetlist( "issue12505" );
  114. TestTranPoint( 0.015, { { "V(Net-_R1-Pad2_)", -311 } } );
  115. TestTranPoint( 0.025, { { "V(Net-_R1-Pad2_)", 311 } } );
  116. }
  117. #endif // KICAD_SPICE