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.

110 lines
4.3 KiB

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