KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_check.cpp
Go to the documentation of this file.
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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "math/vector2d.h"
22#include <boost/test/data/test_case.hpp>
23
24#include <algorithm>
25#include <vector>
26
27#include <base_units.h>
28#include <board.h>
29#include <footprint.h>
30#include <pad.h>
31#include <pad_utils.h>
32#include <padstack.h>
33#include <units_provider.h>
34
35BOOST_AUTO_TEST_SUITE( PadCheck )
36
37namespace
38{
40
44struct PAD_CHECK_TEST_CASE : public KI_TEST::NAMED_CASE
45{
46 PAD_ATTRIB m_Attribute;
47 LSET m_Layers;
48 std::vector<PAD_CHECK_CODE> m_ExpectedCodes;
49};
50
51
52const std::vector<PAD_CHECK_TEST_CASE> padCheckCases = {
53 {
54 "inner-only SMD pad",
56 LSET( { In1_Cu, In2_Cu } ),
57 {
58 PAD_CHECK_CODE::PAD_NO_OUTER_COPPER,
59 PAD_CHECK_CODE::MULTIPLE_COPPER_LAYERS,
60 },
61 },
62 {
63 "inner-only CONN pad",
65 LSET( { In1_Cu } ),
66 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
67 },
68 // The current checker reports the missing outer copper, not the mask issue itself.
69 {
70 "inner-only SMD pad with front mask",
72 LSET( { In1_Cu, F_Mask } ),
73 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
74 },
75 // The current checker reports the missing outer copper, not the paste issue itself.
76 {
77 "inner-only SMD pad with back paste",
79 LSET( { In2_Cu, B_Paste } ),
80 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
81 },
82 {
83 "aperture pad with paste",
85 LSET( { F_Paste } ),
86 {}, // Not expected to trigger any pad check errors
87 },
88 {
89 "outer and inner SMD pad",
91 LSET( { F_Cu, In1_Cu, F_Mask, F_Paste } ),
92 { PAD_CHECK_CODE::MULTIPLE_COPPER_LAYERS },
93 },
94 {
95 "both outer copper sides",
97 LSET( { F_Cu, B_Cu } ),
98 { PAD_CHECK_CODE::MULTIPLE_COPPER_LAYERS },
99 },
100 {
101 "wrong-side mask",
103 LSET( { B_Cu, F_Mask } ),
104 { PAD_CHECK_CODE::MASK_WRONG_SIDE },
105 },
106 {
107 "non-component front pad",
109 LSET( { F_Cu } ),
110 {},
111 },
112 {
113 "non-component inner pad",
115 LSET( { In2_Cu } ),
116 {},
117 },
118 {
119 "non-component inner pad with front mask",
121 LSET( { In1_Cu, F_Mask } ),
122 { PAD_CHECK_CODE::NON_COMPONENT_TECH_ON_INNER },
123 },
124 {
125 "non-component multiple copper layers",
127 LSET( { F_Cu, In1_Cu } ),
128 { PAD_CHECK_CODE::MULTIPLE_COPPER_LAYERS },
129 },
130 {
131 "non-component no copper",
133 LSET( { F_Mask } ),
134 { PAD_CHECK_CODE::NON_COMPONENT_NO_COPPER },
135 },
136};
137
138
139void checkPadResults( const std::vector<PAD_UTILS::PAD_CHECK_RESULT>& aResults,
140 const std::vector<PAD_CHECK_CODE>& aExpectedCodes )
141{
142 std::vector<int> actualCodes;
143 actualCodes.reserve( aResults.size() );
144
145 for( const PAD_UTILS::PAD_CHECK_RESULT& message : aResults )
146 actualCodes.push_back( static_cast<int>( message.code ) );
147
148 std::vector<int> expectedCodes;
149 expectedCodes.reserve( aExpectedCodes.size() );
150
151 for( PAD_CHECK_CODE code : aExpectedCodes )
152 expectedCodes.push_back( static_cast<int>( code ) );
153
154 std::sort( actualCodes.begin(), actualCodes.end() );
155 std::sort( expectedCodes.begin(), expectedCodes.end() );
156
157 BOOST_CHECK_EQUAL_COLLECTIONS( actualCodes.begin(), actualCodes.end(), expectedCodes.begin(), expectedCodes.end() );
158}
159
160} // namespace
161
162
168{
172
176 {
177 m_Board.SetBoardUse( BOARD_USE::FPHOLDER );
178
179 // Inner-layer copper-only pads are only legal with a custom footprint stackup.
181 m_Footprint.SetStackupLayers( LSET::AllCuMask( 4 ) );
182
183 m_Pad.SetAttribute( PAD_ATTRIB::SMD );
184 m_Pad.SetPadstackMode( PADSTACK::MODE::NORMAL );
186
187 const VECTOR2I padSize{ pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) };
188 m_Pad.SetSize( PADSTACK::ALL_LAYERS, padSize );
189 }
190
191 void setLayers( PAD_ATTRIB aAttrib, const LSET& aLayers )
192 {
193 m_Pad.SetAttribute( aAttrib );
194 m_Pad.SetLayerSet( aLayers );
195 }
196
202 std::vector<PAD_UTILS::PAD_CHECK_RESULT> runPadCheckOnPad()
203 {
205 std::vector<PAD_UTILS::PAD_CHECK_RESULT> messages;
206
207 const auto errorHandler =
208 [&]( const PAD_UTILS::PAD_CHECK_RESULT& aResult )
209 {
210 messages.push_back( aResult );
211 };
212
213 PAD_UTILS::CheckPad( m_Pad, units, false, errorHandler );
214
215 return messages;
216 }
217};
218
219
223BOOST_DATA_TEST_CASE_F( PAD_CHECK_FIXTURE, PadCheckCases, boost::unit_test::data::make( padCheckCases ), testCase )
224{
225 BOOST_TEST_CONTEXT( testCase.m_CaseName )
226 {
227 setLayers( testCase.m_Attribute, testCase.m_Layers );
228
229 const auto messages = runPadCheckOnPad();
230
231 checkPadResults( messages, testCase.m_ExpectedCodes );
232 }
233}
234
235
236// SetAttribute() clears the drill, so the hole case cannot use the data table.
237BOOST_FIXTURE_TEST_CASE( CopperOnlyPadWithHole, PAD_CHECK_FIXTURE )
238{
239 setLayers( PAD_ATTRIB::NON_COMPONENT, LSET( { F_Cu } ) );
240 m_Pad.SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.5 ), pcbIUScale.mmToIU( 0.5 ) ) );
241
242 checkPadResults( runPadCheckOnPad(), { PAD_CHECK_CODE::UNEXPECTED_HOLE } );
243}
244
245
246BOOST_FIXTURE_TEST_CASE( CopperOnlyInnerPadNeedsCustomStackup, PAD_CHECK_FIXTURE )
247{
248 m_Footprint.SetStackupMode( FOOTPRINT_STACKUP::EXPAND_INNER_LAYERS );
249 setLayers( PAD_ATTRIB::NON_COMPONENT, LSET( { In1_Cu } ) );
250
251 checkPadResults( runPadCheckOnPad(), { PAD_CHECK_CODE::NON_COMPONENT_INNER_NEEDS_CUSTOM_STACKUP } );
252}
253
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ FPHOLDER
Definition board.h:403
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
@ EXPAND_INNER_LAYERS
The 'normal' stackup handling, where there is a single inner layer (In1) and rule areas using it expa...
Definition footprint.h:111
@ CUSTOM_LAYERS
Stackup handling where the footprint can have any number of copper layers, and objects on those layer...
Definition footprint.h:116
std::string message
@ F_Paste
Definition layer_ids.h:100
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ In2_Cu
Definition layer_ids.h:63
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
void CheckPad(const PAD &aPad, const UNITS_PROVIDER &aUnitsProvider, bool aForPadProperties, const PAD_CHECK_HANDLER &aErrorHandler)
Run non-board-specific checks on a pad.
PAD_CHECK_CODE
A specific pad check finding reason.
Definition pad_utils.h:82
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition padstack.h:98
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
Definition padstack.h:106
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Definition padstack.h:101
@ RECTANGLE
Definition padstack.h:55
A named data-driven test case.
Fixture for pad check tests: This sets up a board, footprint, and pad, and provides utility functions...
std::vector< PAD_UTILS::PAD_CHECK_RESULT > runPadCheckOnPad()
Runs the pad check on the current pad and returns the results.
void setLayers(PAD_ATTRIB aAttrib, const LSET &aLayers)
A single finding from CheckPad().
Definition pad_utils.h:122
BOOST_FIXTURE_TEST_CASE(ServerStartsAndResponds, API_SERVER_E2E_FIXTURE)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_DATA_TEST_CASE_F(CONNECTIVITY_DUMP_FIXTURE, LegacyAndEngineDumpsMatch, boost::unit_test::data::make(PARITY_FIXTURES), fixture)
BOOST_CHECK_EQUAL_COLLECTIONS(mixed.begin(), mixed.end(), expMixed.begin(), expMixed.end())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708