2023-01-21 14:27:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.TXT for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef KICAD_SPICE
|
|
|
|
|
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
|
|
|
#include <boost/test/results_collector.hpp> // To check if the current test failed (to be moved?).
|
|
|
|
#include <eeschema_test_utils.h>
|
|
|
|
#include <test_netlist_exporter_spice.h>
|
|
|
|
#include <wx/ffile.h>
|
|
|
|
#include <mock_pgm_base.h>
|
|
|
|
#include <locale_io.h>
|
|
|
|
|
|
|
|
|
|
|
|
class TEST_SIM_REGRESSIONS_FIXTURE : public TEST_NETLIST_EXPORTER_SPICE_FIXTURE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_SIM_REGRESSIONS_FIXTURE() :
|
|
|
|
TEST_NETLIST_EXPORTER_SPICE_FIXTURE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~TEST_SIM_REGRESSIONS_FIXTURE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName GetSchematicPath( const wxString& aBaseName ) override
|
|
|
|
{
|
|
|
|
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
|
|
|
|
fn.SetName( aBaseName );
|
|
|
|
fn.SetExt( KiCadSchematicFileExtension );
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetNetlistPath( bool aTest = false ) override
|
|
|
|
{
|
|
|
|
wxFileName netFile = m_schematic.Prj().GetProjectFullName();
|
|
|
|
|
|
|
|
if( aTest )
|
|
|
|
netFile.SetName( netFile.GetName() + "_test" );
|
|
|
|
|
|
|
|
netFile.SetExt( "spice" );
|
|
|
|
return netFile.GetFullPath();
|
|
|
|
}
|
|
|
|
|
2023-01-21 18:07:06 +00:00
|
|
|
unsigned GetNetlistOptions() override
|
|
|
|
{
|
|
|
|
unsigned options = NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS
|
|
|
|
| NETLIST_EXPORTER_SPICE::OPTION_SIM_COMMAND;
|
|
|
|
|
|
|
|
if( m_SaveCurrents )
|
|
|
|
options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
|
|
|
|
|
|
|
|
if( m_SaveVoltages )
|
|
|
|
options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
|
2023-01-21 14:27:33 +00:00
|
|
|
|
2023-02-20 18:12:58 +00:00
|
|
|
if( m_SavesDissipations )
|
|
|
|
options |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
|
|
|
|
|
2023-01-21 18:07:06 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2023-02-20 18:12:58 +00:00
|
|
|
bool m_SavesDissipations = false;
|
|
|
|
bool m_SaveVoltages = true;
|
|
|
|
bool m_SaveCurrents = true;
|
2023-01-21 18:07:06 +00:00
|
|
|
};
|
2023-01-21 14:27:33 +00:00
|
|
|
|
|
|
|
|
2023-01-21 18:07:06 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( WindowsPaths, TEST_SIM_REGRESSIONS_FIXTURE )
|
2023-01-21 14:27:33 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
2023-01-22 15:52:00 +00:00
|
|
|
const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
|
|
|
|
MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
|
|
|
|
|
2023-01-21 14:27:33 +00:00
|
|
|
TestNetlist( "issue13591" );
|
2023-01-21 18:07:06 +00:00
|
|
|
TestTranPoint( 100e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
|
|
|
|
TestTranPoint( 500e-6, { { "I(R1)", 0 }, { "I(R2)", 0 } }, 0.00001 );
|
2023-01-21 14:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 18:23:58 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( ImmediateSBCKT, TEST_SIM_REGRESSIONS_FIXTURE )
|
2023-01-21 18:07:06 +00:00
|
|
|
{
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
|
|
|
m_SaveCurrents = false;
|
|
|
|
|
|
|
|
TestNetlist( "issue13431" );
|
2023-01-22 14:34:59 +00:00
|
|
|
TestTranPoint( 0.005, { { "V(/soft_start)", 2.489 } } );
|
|
|
|
TestTranPoint( 0.012, { { "V(/soft_start)", 5.100 } } );
|
2023-01-21 18:07:06 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 14:27:33 +00:00
|
|
|
|
2023-01-21 18:23:58 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( LegacyFixups, TEST_SIM_REGRESSIONS_FIXTURE )
|
|
|
|
{
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
2023-01-22 15:52:00 +00:00
|
|
|
const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
|
|
|
|
MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
|
|
|
|
|
2023-01-21 18:23:58 +00:00
|
|
|
TestNetlist( "issue13112" );
|
2023-01-22 14:34:59 +00:00
|
|
|
TestTranPoint( 0.01, { { "V(out)", -0.060 } } );
|
|
|
|
TestTranPoint( 0.02, { { "V(out)", 0.856 } } );
|
2023-01-21 18:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 19:32:00 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( DualNMOSAmp, TEST_SIM_REGRESSIONS_FIXTURE )
|
|
|
|
{
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
2023-01-22 15:52:00 +00:00
|
|
|
const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
|
|
|
|
MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
|
|
|
|
|
2023-01-21 19:32:00 +00:00
|
|
|
TestNetlist( "issue13162" );
|
2023-01-31 14:40:46 +00:00
|
|
|
TestTranPoint( 0.030, { { "V(out)", 0.557 } } );
|
2023-01-22 14:34:59 +00:00
|
|
|
TestTranPoint( 0.035, { { "V(out)", -1.437 } } );
|
2023-01-21 19:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-06 10:26:06 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( VariableSubstitutions, TEST_SIM_REGRESSIONS_FIXTURE )
|
|
|
|
{
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
|
|
|
|
const MOCK_PGM_BASE& program = static_cast<MOCK_PGM_BASE&>( Pgm() );
|
|
|
|
MOCK_EXPECT( program.GetLocalEnvVariables ).returns( ENV_VAR_MAP() );
|
|
|
|
|
|
|
|
TestNetlist( "issue12505" );
|
|
|
|
TestTranPoint( 0.015, { { "V(Net-_R1-Pad2_)", -311 } } );
|
|
|
|
TestTranPoint( 0.025, { { "V(Net-_R1-Pad2_)", 311 } } );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 14:27:33 +00:00
|
|
|
#endif // KICAD_SPICE
|