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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include "allegro_block_tests.h"
23
24#include <hash.h>
25
26
39
40
41using namespace ALLEGRO;
42using namespace KI_TEST;
43
44
49{
50 std::string m_BoardName;
52
53 bool operator==( const BLOCK_TEST_KEY& other ) const
54 {
55 return m_BoardName == other.m_BoardName &&
57 }
58};
59
60
61namespace std
62{
63template <>
64struct hash<BLOCK_TEST_KEY>
65{
66 size_t operator()( const BLOCK_TEST_KEY& key ) const
67 {
68 return hash_val( key.m_BoardName, key.m_BlockOffset );
69 }
70};
71} // namespace std
72
73
74using BLOCK_TEST_FUNC = std::function<void( const BLOCK_BASE& )>;
75
76
77static void TestOlympus0x20( const BLOCK_BASE& aBlock )
78{
79 BOOST_REQUIRE( aBlock.GetBlockType() == 0x20 );
80
81 const auto& blk = static_cast<const BLOCK<BLK_0x20_UNKNOWN>&>( aBlock ).GetData();
82 BOOST_TEST( blk.m_R == 0x0507 );
83 BOOST_TEST( blk.m_Key == 0x812AB498 );
84 BOOST_TEST( blk.m_Next == 0x824DF8F0 );
85}
86
87
91static void TestBeagleBoneBlack_0x0F_SlotG1( const BLOCK_BASE& aBlock )
92{
93 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
94
95 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
96 BOOST_TEST( blk.m_Key == 0xbf0 );
97
98 BOOST_TEST( blk.m_Ptr0x06 == 0xb91 );
99 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0xb91 ); // Last slot in component
100
101 BOOST_TEST( blk.m_SlotName == 0x2ba );
102 BOOST_TEST( blk.m_Ptr0x11 == 0x060aa );
103
104 BOOST_TEST( blk.GetCompDeviceTypeStr() == "RES_10K_1/16W_1%_0402_402_10K,1" );
105}
106
107
112{
113 BOOST_REQUIRE( aBlock.GetBlockType() == 0x0f );
114
115 const auto& blk = static_cast<const BLOCK<BLK_0x0F_FUNCTION_SLOT>&>( aBlock ).GetData();
116 BOOST_TEST( blk.m_Key == 0x12d );
117
118 BOOST_TEST( blk.m_Ptr0x06 == 0x126 );
119 BOOST_TEST( blk.m_Next.value_or( 0 ) == 0x126 ); // Last slot in component
120
121 BOOST_TEST( blk.m_SlotName == 0x87 );
122 BOOST_TEST( blk.m_Ptr0x11 == 0x264 ); // ptr to "ZERO"
123
124 BOOST_TEST( blk.GetCompDeviceTypeStr() == "AM4096" );
125}
126
127
131static void TestParallellaV163_PS_56X55RT( const BLOCK_BASE& aBlock )
132{
133 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
134
135 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
136
137 BOOST_TEST( blk.m_Key == 0x0acda700 );
138
139 BOOST_TEST( blk.GetLayerCount() == 1 );
140 BOOST_TEST( blk.m_Components.size() == 10 + 3 * 1);
141}
142
143
144static void TestParallellaV163_PS_28C128N( const BLOCK_BASE& aBlock )
145{
146 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
147
148 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
149
150 BOOST_TEST( blk.m_Key == 0x0acd0920 );
151
152 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
153
154 BOOST_TEST( blk.IsPlated() == false );
155
156 BOOST_TEST( hdr16x.m_DrillChar == 'L' );
157}
158
159
161{
162 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
163
164 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
165
166 BOOST_TEST( blk.m_Key == 0x0acd1ea0 );
167
168 const auto& hdr16x = std::get<BLK_0x1C_PADSTACK::HEADER_v16x>( blk.m_Header );
169
170 BOOST_TEST( hdr16x.m_DrillSize == 2559 );
171
172 BOOST_TEST( hdr16x.m_SlotX == 2559 );
173 BOOST_TEST( hdr16x.m_SlotY == 6693 );
174
175 BOOST_TEST( blk.IsPlated() == true );
176}
177
178
180{
181 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
182
183 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
184
185 BOOST_TEST( blk.m_Key == 0x1421 );
186 BOOST_TEST( blk.GetLayerCount() == 6 );
187
188 const auto& hdr17x = std::get<BLK_0x1C_PADSTACK::HEADER_v17x>( blk.m_Header );
189
190 BOOST_TEST( hdr17x.m_DrillSize == 4000 );
191
192 BOOST_TEST( hdr17x.m_SlotX == 12000 );
193 BOOST_TEST( hdr17x.m_SlotY == 4000 );
194
195 BOOST_TEST( hdr17x.m_TolerancePos == 300 );
196 BOOST_TEST( hdr17x.m_ToleranceNeg == 300 );
197 BOOST_TEST( hdr17x.m_ToleranceTravelPos == 300 );
198 BOOST_TEST( hdr17x.m_ToleranceTravelNeg == 300 );
199
200 BOOST_TEST( blk.IsPlated() == true );
201}
202
203
204static void TestBeagleBoneAI_PS_200C125D( const BLOCK_BASE& aBlock )
205{
206 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
207
208 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
209
210 BOOST_TEST( blk.m_Key == 0x1fda );
211 BOOST_TEST( blk.GetLayerCount() == 12 );
212
213 BOOST_TEST( blk.GetDrillSize() == 125000 );
214
215 BOOST_TEST( blk.m_Components.size() == 21 + 4 * 12 );
216
217 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_RECTANGLE );
218 BOOST_TEST( blk.m_Components[0].m_W == 244000 );
219 BOOST_TEST( blk.m_Components[0].m_H == 244000 );
220
221 BOOST_TEST( blk.IsPlated() == true );
222}
223
224
225static void TestCutiePiV166_PS_C50H340M700N( const BLOCK_BASE& aBlock )
226{
227 BOOST_REQUIRE( aBlock.GetBlockType() == 0x1c );
228
229 const auto& blk = static_cast<const BLOCK<BLK_0x1C_PADSTACK>&>( aBlock ).GetData();
230
231 BOOST_TEST( blk.m_Key == 0x0bfa9588 );
232
233 BOOST_TEST( blk.GetLayerCount() == 6 );
234 BOOST_TEST( blk.GetDrillSize() == 133858 );
235
236 BOOST_TEST( blk.m_Components.size() == 11 + 3 * 6 );
237
238 BOOST_TEST( blk.m_Components[0].m_Type == PADSTACK_COMPONENT::TYPE_CIRCLE );
239 BOOST_TEST( blk.m_Components[0].m_W == 275591 );
240 BOOST_TEST( blk.m_Components[0].m_H == 275591 );
241
242 BOOST_TEST( blk.IsPlated() == false );
243}
244
245
254// clang-format off
255static const std::unordered_map<BLOCK_TEST_KEY, BLOCK_TEST_FUNC> additionalBlockTests{
256 { { "Olympus_15061-1b_v165", 0x0131553c }, TestOlympus0x20 },
257
258 // 0x0F
259 { { "BeagleBone_Black_RevC", 0x0000c8b8 }, TestBeagleBoneBlack_0x0F_SlotG1 },
260 { { "OpenBreath_encoder_v174", 0x00001c3c }, TestOpenBreath_0x0F_SlotAM4096_G1 },
261
262 // Padstacks
263 { { "BeagleBone_Black_RevC", 0x0007c420 }, TestBeagleBoneBlack_PS_120X040SLOT },
264 { { "BeagleBone-AI", 0x00047f44 }, TestBeagleBoneAI_PS_200C125D },
265 { { "CutiePi_V2_3_v166", 0x0001ef8c }, TestCutiePiV166_PS_C50H340M700N },
266 { { "parallella_v163", 0x000368c8 }, TestParallellaV163_PS_56X55RT },
267 { { "parallella_v163", 0x0002cc08 }, TestParallellaV163_PS_28C128N },
268 { { "parallella_v163", 0x0002e168 }, TestParallellaV163_PS_P65X1P7SLT },
269};
270// clang-format on
271
272
273void KI_TEST::RunAdditionalBlockTest( const std::string& aBoardName, size_t aBlockOffset, const BLOCK_BASE& block )
274{
275 const BLOCK_TEST_KEY key{ aBoardName, aBlockOffset };
276
277 auto it = additionalBlockTests.find( key );
278 if( it != additionalBlockTests.end() )
279 {
280 const auto& testFunc = it->second;
281 BOOST_REQUIRE( testFunc );
282
283 testFunc( block );
284 }
285 else
286 {
287 BOOST_TEST_FAIL( "No additional test defined for this block" );
288 }
289}
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:47
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_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST(netlist.find("R_G1 ARM_OUT1 DIE_B R='0.001 / ((SW_STATE)") !=std::string::npos)