KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_block_additional.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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
25
26#include "allegro_block_tests.h"
27
28#include <hash.h>
29
30
43
44
45using namespace ALLEGRO;
46using namespace KI_TEST;
47
48
53{
54 std::string m_BoardName;
56
57 bool operator==( const BLOCK_TEST_KEY& other ) const
58 {
59 return m_BoardName == other.m_BoardName &&
61 }
62};
63
64
65namespace std
66{
67template <>
68struct hash<BLOCK_TEST_KEY>
69{
70 size_t operator()( const BLOCK_TEST_KEY& key ) const
71 {
72 return hash_val( key.m_BoardName, key.m_BlockOffset );
73 }
74};
75} // namespace std
76
77
78using BLOCK_TEST_FUNC = std::function<void( const BLOCK_BASE& )>;
79
80
81static void TestOlympus0x20( const BLOCK_BASE& aBlock )
82{
83 BOOST_REQUIRE( aBlock.GetBlockType() == 0x20 );
84
85 const auto& blk = static_cast<const BLOCK<BLK_0x20_UNKNOWN>&>( aBlock ).GetData();
86 BOOST_TEST( blk.m_R == 0x0507 );
87 BOOST_TEST( blk.m_Key == 0x812AB498 );
88 BOOST_TEST( blk.m_Next == 0x824DF8F0 );
89}
90
91
95static void TestBeagleBoneBlack_0x0F_SlotG1( const BLOCK_BASE& aBlock )
96{
97 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
98
99 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
100 BOOST_TEST( blk.m_Key == 0xbf0 );
101
102 BOOST_TEST( blk.m_Ptr0x06 == 0xb91 );
103 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0xb91 ); // Last slot in component
104
105 BOOST_TEST( blk.m_SlotName == 0x2ba );
106 BOOST_TEST( blk.m_Ptr0x11 == 0x060aa );
107
108 BOOST_TEST( blk.GetCompDeviceTypeStr() == "RES_10K_1/16W_1%_0402_402_10K,1" );
109}
110
111
116{
117 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
118
119 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
120 BOOST_TEST( blk.m_Key == 0x12d );
121
122 BOOST_TEST( blk.m_Ptr0x06 == 0x126 );
123 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0x126 ); // Last slot in component
124
125 BOOST_TEST( blk.m_SlotName == 0x87 );
126 BOOST_TEST( blk.m_Ptr0x11 == 0x264 ); // ptr to "ZERO"
127
128 BOOST_TEST( blk.GetCompDeviceTypeStr() == "AM4096" );
129}
130
131
135static void TestParallellaV163_PS_56X55RT( const BLOCK_BASE& aBlock )
136{
137 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
138
139 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
140
141 BOOST_TEST( blk.m_Key == 0x0acda700 );
142
143 BOOST_TEST( blk.GetLayerCount() == 1 );
144 BOOST_TEST( blk.m_Components.size() == 10 + 3 * 1);
145}
146
147
148static void TestParallellaV163_PS_28C128N( const BLOCK_BASE& aBlock )
149{
150 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
151
152 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
153
154 BOOST_TEST( blk.m_Key == 0x0acd0920 );
155
156 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
157
158 BOOST_TEST( blk.IsPlated() == false );
159
160 BOOST_TEST( hdr16x.m_DrillChar == 'L' );
161}
162
163
165{
166 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
167
168 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
169
170 BOOST_TEST( blk.m_Key == 0x0acd1ea0 );
171
172 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
173
174 BOOST_TEST( hdr16x.m_DrillSize == 2559 );
175
176 BOOST_TEST( hdr16x.m_SlotX == 2559 );
177 BOOST_TEST( hdr16x.m_SlotY == 6693 );
178
179 BOOST_TEST( blk.IsPlated() == true );
180}
181
182
184{
185 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
186
187 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
188
189 BOOST_TEST( blk.m_Key == 0x1421 );
190 BOOST_TEST( blk.GetLayerCount() == 6 );
191
192 const auto& hdr17x = std::get<BLK_0x1C_PADSTACK::HEADER_v17x>( blk.m_Header );
193
194 BOOST_TEST( hdr17x.m_DrillSize == 4000 );
195
196 BOOST_TEST( hdr17x.m_SlotX == 12000 );
197 BOOST_TEST( hdr17x.m_SlotY == 4000 );
198
199 BOOST_TEST( hdr17x.m_TolerancePos == 300 );
200 BOOST_TEST( hdr17x.m_ToleranceNeg == 300 );
201 BOOST_TEST( hdr17x.m_ToleranceTravelPos == 300 );
202 BOOST_TEST( hdr17x.m_ToleranceTravelNeg == 300 );
203
204 BOOST_TEST( blk.IsPlated() == true );
205}
206
207
208static void TestBeagleBoneAI_PS_200C125D( const BLOCK_BASE& aBlock )
209{
210 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
211
212 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
213
214 BOOST_TEST( blk.m_Key == 0x1fda );
215 BOOST_TEST( blk.GetLayerCount() == 12 );
216
217 BOOST_TEST( blk.GetDrillSize() == 125000 );
218
219 BOOST_TEST( blk.m_Components.size() == 21 + 4 * 12 );
220
221 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_RECTANGLE );
222 BOOST_TEST( blk.m_Components[0].m_W == 244000 );
223 BOOST_TEST( blk.m_Components[0].m_H == 244000 );
224
225 BOOST_TEST( blk.IsPlated() == true );
226}
227
228
229static void TestCutiePiV166_PS_C50H340M700N( const BLOCK_BASE& aBlock )
230{
231 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
232
233 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
234
235 BOOST_TEST( blk.m_Key == 0x0bfa9588 );
236
237 BOOST_TEST( blk.GetLayerCount() == 6 );
238 BOOST_TEST( blk.GetDrillSize() == 133858 );
239
240 BOOST_TEST( blk.m_Components.size() == 11 + 3 * 6 );
241
242 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_CIRCLE );
243 BOOST_TEST( blk.m_Components[0].m_W == 275591 );
244 BOOST_TEST( blk.m_Components[0].m_H == 275591 );
245
246 BOOST_TEST( blk.IsPlated() == false );
247}
248
249
258// clang-format off
259static const std::unordered_map<BLOCK_TEST_KEY, BLOCK_TEST_FUNC> additionalBlockTests{
260 { { "Olympus_15061-1b_v165", 0x0131553c }, TestOlympus0x20 },
261
262 // 0x0F
263 { { "BeagleBone_Black_RevC", 0x0000c8b8 }, TestBeagleBoneBlack_0x0F_SlotG1 },
264 { { "OpenBreath_encoder_v174", 0x00001c3c }, TestOpenBreath_0x0F_SlotAM4096_G1 },
265
266 // Padstacks
267 { { "BeagleBone_Black_RevC", 0x0007c420 }, TestBeagleBoneBlack_PS_120X040SLOT },
268 { { "BeagleBone-AI", 0x00047f44 }, TestBeagleBoneAI_PS_200C125D },
269 { { "CutiePi_V2_3_v166", 0x0001ef8c }, TestCutiePiV166_PS_C50H340M700N },
270 { { "parallella_v163", 0x000368c8 }, TestParallellaV163_PS_56X55RT },
271 { { "parallella_v163", 0x0002cc08 }, TestParallellaV163_PS_28C128N },
272 { { "parallella_v163", 0x0002e168 }, TestParallellaV163_PS_P65X1P7SLT },
273};
274// clang-format on
275
276
277void KI_TEST::RunAdditionalBlockTest( const std::string& aBoardName, size_t aBlockOffset, const BLOCK_BASE& block )
278{
279 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
280
281 auto it = additionalBlockTests.find( key );
282 if( it != additionalBlockTests.end() )
283 {
284 const auto& testFunc = it->second;
285 BOOST_REQUIRE( testFunc );
286
287 testFunc( block );
288 }
289 else
290 {
291 BOOST_TEST_FAIL( "No additional test defined for this block" );
292 }
293}
The base class for all blocks in the main body of an Allegro file.
uint8_t GetBlockType() const
This is the actual type code as read from the file.
static constexpr std::size_t hash_val(const Types &... args)
Definition hash.h:51
void RunAdditionalBlockTest(const std::string &aBoardName, size_t aBlockOffset, const ALLEGRO::BLOCK_BASE &aBlock)
Look up and run any additional ad-hoc tests for a block.
STL namespace.
Unique key for identifying a block test, used for looking up additional validation functions.
bool operator==(const BLOCK_TEST_KEY &other) const
size_t operator()(const BLOCK_TEST_KEY &key) const
static void TestBeagleBoneBlack_0x0F_SlotG1(const BLOCK_BASE &aBlock)
Tests a V17.2 slot def.
static void TestOlympus0x20(const BLOCK_BASE &aBlock)
static void TestBeagleBoneBlack_PS_120X040SLOT(const BLOCK_BASE &aBlock)
static void TestCutiePiV166_PS_C50H340M700N(const BLOCK_BASE &aBlock)
std::function< void(const BLOCK_BASE &)> BLOCK_TEST_FUNC
static const std::unordered_map< BLOCK_TEST_KEY, BLOCK_TEST_FUNC > additionalBlockTests
The registry of additional block tests, keyed by board name and block offset.
static void TestParallellaV163_PS_P65X1P7SLT(const BLOCK_BASE &aBlock)
static void TestBeagleBoneAI_PS_200C125D(const BLOCK_BASE &aBlock)
static void TestOpenBreath_0x0F_SlotAM4096_G1(const BLOCK_BASE &aBlock)
Tests a V17.4 slot def.
static void TestParallellaV163_PS_28C128N(const BLOCK_BASE &aBlock)
static void TestParallellaV163_PS_56X55RT(const BLOCK_BASE &aBlock)
This is a 1-layer SMD padstack in v16.3 format.
BOOST_TEST(contains==c.ExpectedContains)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())