2022-02-21 03:58:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2022-08-05 15:37:20 +00:00
|
|
|
#include <sim/sim_model_ngspice.h>
|
2022-11-29 14:04:38 +00:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
class TEST_SIM_MODEL_NGSPICE_FIXTURE : public SIM_MODEL_NGSPICE
|
|
|
|
{
|
|
|
|
public:
|
2022-12-21 17:01:05 +00:00
|
|
|
TEST_SIM_MODEL_NGSPICE_FIXTURE() :
|
|
|
|
SIM_MODEL_NGSPICE( TYPE::NONE )
|
|
|
|
{}
|
2022-08-05 15:37:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( SimModelNgspice, TEST_SIM_MODEL_NGSPICE_FIXTURE )
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( ParamDuplicates )
|
|
|
|
{
|
|
|
|
for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( "Model name: " << ModelInfo( type ).name )
|
|
|
|
{
|
|
|
|
const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
|
|
|
|
const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
|
|
|
|
|
|
|
|
for( const SIM_MODEL::PARAM::INFO& modelParam : modelParams )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( "Model param name: " << modelParam.name )
|
|
|
|
{
|
|
|
|
// Ensure there's no model parameters that have the same name.
|
|
|
|
BOOST_CHECK( std::none_of( modelParams.begin(), modelParams.end(),
|
|
|
|
[modelParam]( const auto& aOtherModelParam )
|
|
|
|
{
|
|
|
|
return modelParam.id != aOtherModelParam.id
|
|
|
|
&& modelParam.name == aOtherModelParam.name;
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
// Ensure there's no model parameters that have the same name as an instance parameter.
|
|
|
|
BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
|
|
|
|
[modelParam]( const auto& aInstanceParam )
|
|
|
|
{
|
|
|
|
return modelParam.name == aInstanceParam.name;
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
if( boost::ends_with( modelParam.name, "_" ) )
|
|
|
|
{
|
|
|
|
// Ensure that for each model parameter ending with a "_" there exists an
|
|
|
|
// instance parameter with the same name but without this final character.
|
|
|
|
// We append an "_" to model parameters to disambiguate from these
|
|
|
|
// corresponding instance parameters.
|
|
|
|
BOOST_CHECK( std::any_of( instanceParams.begin(), instanceParams.end(),
|
|
|
|
[modelParam]( const auto& aInstanceParam )
|
|
|
|
{
|
|
|
|
return modelParam.name.substr( 0, modelParam.name.length() - 1 )
|
|
|
|
== aInstanceParam.name;
|
|
|
|
} ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure there's no instance parameters that have the same name.
|
|
|
|
for( const SIM_MODEL::PARAM::INFO& instanceParam : instanceParams )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( "Instance param name: " << instanceParam.name )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( std::none_of( instanceParams.begin(), instanceParams.end(),
|
|
|
|
[instanceParam]( const auto& aOtherInstanceParam )
|
|
|
|
{
|
|
|
|
return instanceParam.id != aOtherInstanceParam.id
|
|
|
|
&& instanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
|
|
|
|
&& aOtherInstanceParam.dir != SIM_MODEL::PARAM::DIR_OUT
|
|
|
|
&& instanceParam.name == aOtherInstanceParam.name;
|
|
|
|
} ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( ParamCount )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
|
|
|
// Count the total number of model and instance parameters for each model so that there will be
|
|
|
|
// an error if someone accidentally removes a parameter.
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
for( MODEL_TYPE type : MODEL_TYPE_ITERATOR() )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-11-29 14:04:38 +00:00
|
|
|
const std::vector<SIM_MODEL::PARAM::INFO> modelParams = ModelInfo( type ).modelParams;
|
|
|
|
const std::vector<SIM_MODEL::PARAM::INFO> instanceParams = ModelInfo( type ).instanceParams;
|
2022-08-05 15:37:20 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::NONE:
|
|
|
|
case MODEL_TYPE::_ENUM_END:
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
/*case MODEL_TYPE::RESISTOR:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 22 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::CAPACITOR:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 19 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 22 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::INDUCTOR:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 9 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 20 );
|
2022-05-08 09:54:35 +00:00
|
|
|
break;*/
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
/*case MODEL_TYPE::LTRA:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 18 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 9 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::TRANLINE:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 0 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 17 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::URC:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 7 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 5 );
|
2022-05-31 02:55:48 +00:00
|
|
|
break;*/
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
/*case MODEL_TYPE::TRANSLINE:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 6 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 3 );
|
2022-03-09 01:40:59 +00:00
|
|
|
break;*/
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
/*case MODEL_TYPE::SWITCH:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 7 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 8 );
|
2022-04-12 14:37:06 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::CSWITCH:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 7 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 7 );
|
2022-08-28 12:51:03 +00:00
|
|
|
break;*/
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::DIODE:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 76 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::BJT:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 152 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 53 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::VBIC:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 117 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 45 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HICUM2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 149 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 61 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::JFET:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 28 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::JFET2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 46 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MES:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 22 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 25 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MESA:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 71 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 30 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HFET1:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 68 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HFET2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 40 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 28 );
|
2022-11-28 03:45:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MODEL_TYPE::VDMOS:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 69 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MOS1:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 35 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MOS2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 42 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 76 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MOS3:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 48 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::BSIM1:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 81 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::BSIM2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 137 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 14 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MOS6:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 42 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 78 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::BSIM3:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 429 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 46 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::MOS9:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 48 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 81 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::B4SOI:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 915 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::BSIM4:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 892 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 84 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::B3SOIFD:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 393 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::B3SOIDD:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 393 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 27 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::B3SOIPD:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 470 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 36 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HISIM2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 486 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 59 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HISIMHV1:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 610 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 72 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-05 15:37:20 +00:00
|
|
|
case MODEL_TYPE::HISIMHV2:
|
2022-11-29 14:04:38 +00:00
|
|
|
BOOST_CHECK_EQUAL( modelParams.size(), 730 );
|
|
|
|
BOOST_CHECK_EQUAL( instanceParams.size(), 74 );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BOOST_FAIL( wxString::Format(
|
|
|
|
"Unhandled type: %d "
|
|
|
|
"(if you created a new type you need to handle it in this switch statement)",
|
|
|
|
type ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|