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.

111 lines
4.5 KiB

7 months ago
7 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 <pcbnew_utils/board_test_utils.h>
  25. #include <board.h>
  26. #include <board_design_settings.h>
  27. #include <drc/drc_item.h>
  28. #include <settings/settings_manager.h>
  29. struct DRC_REGRESSION_TEST_FIXTURE
  30. {
  31. DRC_REGRESSION_TEST_FIXTURE() :
  32. m_settingsManager( true /* headless */ )
  33. { }
  34. SETTINGS_MANAGER m_settingsManager;
  35. std::unique_ptr<BOARD> m_board;
  36. };
  37. BOOST_FIXTURE_TEST_CASE( DRCComponentClasses, DRC_REGRESSION_TEST_FIXTURE )
  38. {
  39. // Check for minimum copper connection errors
  40. std::vector<std::pair<wxString, int>> tests =
  41. {
  42. { "component_classes_drc", 2 }
  43. };
  44. for( const std::pair<wxString, int>& test : tests )
  45. {
  46. KI_TEST::LoadBoard( m_settingsManager, test.first, m_board );
  47. KI_TEST::FillZones( m_board.get() );
  48. std::vector<DRC_ITEM> violations;
  49. BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
  50. // Disable DRC tests not useful or not handled in this testcase
  51. bds.m_DRCSeverities[ DRCE_INVALID_OUTLINE ] = SEVERITY::RPT_SEVERITY_IGNORE;
  52. bds.m_DRCSeverities[ DRCE_UNCONNECTED_ITEMS ] = SEVERITY::RPT_SEVERITY_IGNORE;
  53. bds.m_DRCSeverities[ DRCE_COPPER_SLIVER ] = SEVERITY::RPT_SEVERITY_IGNORE;
  54. bds.m_DRCSeverities[ DRCE_STARVED_THERMAL ] = SEVERITY::RPT_SEVERITY_IGNORE;
  55. bds.m_DRCSeverities[ DRCE_DRILL_OUT_OF_RANGE ] = SEVERITY::RPT_SEVERITY_IGNORE;
  56. bds.m_DRCSeverities[ DRCE_VIA_DIAMETER ] = SEVERITY::RPT_SEVERITY_IGNORE;
  57. // These DRC tests are not useful and do not work because they need a footprint library
  58. // associated to the board
  59. bds.m_DRCSeverities[ DRCE_LIB_FOOTPRINT_ISSUES ] = SEVERITY::RPT_SEVERITY_IGNORE;
  60. bds.m_DRCSeverities[ DRCE_LIB_FOOTPRINT_MISMATCH ] = SEVERITY::RPT_SEVERITY_IGNORE;
  61. bds.m_DRCSeverities[ DRCE_UNCONNECTED_ITEMS ] = SEVERITY::RPT_SEVERITY_IGNORE;
  62. // Ensure that our desired error is fired
  63. bds.m_DRCSeverities[ DRCE_ASSERTION_FAILURE ] = SEVERITY::RPT_SEVERITY_ERROR;
  64. bds.m_DRCEngine->SetViolationHandler(
  65. [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
  66. const std::vector<PCB_SHAPE>& aShapes )
  67. {
  68. if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
  69. violations.push_back( *aItem );
  70. } );
  71. bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
  72. if( violations.size() == test.second )
  73. {
  74. BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
  75. BOOST_TEST_MESSAGE( wxString::Format( "DRC component classes: %s, passed", test.first ) );
  76. }
  77. else
  78. {
  79. UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
  80. std::map<KIID, EDA_ITEM*> itemMap;
  81. m_board->FillItemMap( itemMap );
  82. for( const DRC_ITEM& item : violations )
  83. {
  84. BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
  85. itemMap ) );
  86. }
  87. BOOST_ERROR( wxString::Format( "DRC component classes: %s, failed (violations found %d "
  88. "expected %d)",
  89. test.first,
  90. (int) violations.size(),
  91. test.second ) );
  92. }
  93. }
  94. }