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.

150 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. #include <qa_utils/wx_utils/unit_test_utils.h>
  24. #include <boost/test/results_collector.hpp> // To check if the current test failed (to be moved?).
  25. #include <eeschema_test_utils.h>
  26. #include <test_netlist_exporter_spice.h>
  27. #include <wx/ffile.h>
  28. #include <mock_pgm_base.h>
  29. #include <locale_io.h>
  30. class TEST_SIM_REGRESSIONS_FIXTURE : public TEST_NETLIST_EXPORTER_SPICE_FIXTURE
  31. {
  32. public:
  33. TEST_SIM_REGRESSIONS_FIXTURE() :
  34. TEST_NETLIST_EXPORTER_SPICE_FIXTURE()
  35. {
  36. }
  37. ~TEST_SIM_REGRESSIONS_FIXTURE()
  38. {
  39. }
  40. wxFileName GetSchematicPath( const wxString& aBaseName ) override
  41. {
  42. wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
  43. fn.SetName( aBaseName );
  44. fn.SetExt( KiCadSchematicFileExtension );
  45. return fn;
  46. }
  47. wxString GetNetlistPath( bool aTest = false ) override
  48. {
  49. wxFileName netFile = m_schematic.Prj().GetProjectFullName();
  50. if( aTest )
  51. netFile.SetName( netFile.GetName() + "_test" );
  52. netFile.SetExt( "spice" );
  53. return netFile.GetFullPath();
  54. }
  55. unsigned GetNetlistOptions() override
  56. {
  57. unsigned options = NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS
  58. | NETLIST_EXPORTER_SPICE::OPTION_SIM_COMMAND;
  59. if( m_SaveCurrents )
  60. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
  61. if( m_SaveVoltages )
  62. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
  63. if( m_SavesDissipations )
  64. options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
  65. return options;
  66. }
  67. public:
  68. bool m_SavesDissipations = false;
  69. bool m_SaveVoltages = true;
  70. bool m_SaveCurrents = true;
  71. };
  72. BOOST_FIXTURE_TEST_CASE( WindowsPaths, TEST_SIM_REGRESSIONS_FIXTURE )
  73. {
  74. LOCALE_IO dummy;
  75. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  76. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  77. TestNetlist( "issue13591" );
  78. TestTranPoint( 100e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
  79. TestTranPoint( 500e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
  80. }
  81. BOOST_FIXTURE_TEST_CASE( ImmediateSBCKT, TEST_SIM_REGRESSIONS_FIXTURE )
  82. {
  83. LOCALE_IO dummy;
  84. m_SaveCurrents = false;
  85. TestNetlist( "issue13431" );
  86. TestTranPoint( 0.005, { { "V(/soft_start)", 2.489 } } );
  87. TestTranPoint( 0.012, { { "V(/soft_start)", 5.100 } } );
  88. }
  89. BOOST_FIXTURE_TEST_CASE( LegacyFixups, TEST_SIM_REGRESSIONS_FIXTURE )
  90. {
  91. LOCALE_IO dummy;
  92. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  93. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  94. TestNetlist( "issue13112" );
  95. TestTranPoint( 0.01, { { "V(out)", -0.060 } } );
  96. TestTranPoint( 0.02, { { "V(out)", 0.856 } } );
  97. }
  98. BOOST_FIXTURE_TEST_CASE( DualNMOSAmp, TEST_SIM_REGRESSIONS_FIXTURE )
  99. {
  100. LOCALE_IO dummy;
  101. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  102. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  103. TestNetlist( "issue13162" );
  104. TestTranPoint( 0.030, { { "V(out)", 0.557 } } );
  105. TestTranPoint( 0.035, { { "V(out)", -1.437 } } );
  106. }
  107. BOOST_FIXTURE_TEST_CASE( VariableSubstitutions, TEST_SIM_REGRESSIONS_FIXTURE )
  108. {
  109. LOCALE_IO dummy;
  110. const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
  111. MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
  112. TestNetlist( "issue12505" );
  113. TestTranPoint( 0.015, { { "V(Net-_R1-Pad2_)", -311 } } );
  114. TestTranPoint( 0.025, { { "V(Net-_R1-Pad2_)", 311 } } );
  115. }