KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bus_entry_concurrency.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 * https://www.gnu.org/licenses/gpl-3.0.en.html
19 * or you may search the http://www.gnu.org website for the version 32 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 <algorithm>
27
28#include <connection_graph.h>
29#include <schematic.h>
30#include <sch_bus_entry.h>
31#include <sch_line.h>
32#include <sch_screen.h>
33#include <sch_sheet.h>
35#include <thread_pool.h>
36
38{
40 m_mgr( true /* headless */ )
41 {
42 m_mgr.LoadProject( "" );
43 m_schematic = std::make_unique<SCHEMATIC>( &m_mgr.Prj() );
44 m_screen = new SCH_SCREEN( m_schematic.get() );
45 m_sheet = new SCH_SHEET( m_schematic.get() );
47 m_schematic->SetRoot( m_sheet );
48 }
49
51 std::unique_ptr<SCHEMATIC> m_schematic;
54};
55
56static SCH_LINE* make_bus( const VECTOR2I& aStart, const VECTOR2I& aEnd )
57{
58 SCH_LINE* const line = new SCH_LINE{ aStart, LAYER_BUS };
59 line->SetEndPoint( aEnd );
60 return line;
61}
62
63static SCH_BUS_BUS_ENTRY* make_entry( const VECTOR2I& aPos, int aDy )
64{
65 SCH_BUS_BUS_ENTRY* entry = new SCH_BUS_BUS_ENTRY( aPos );
66 entry->SetSize( VECTOR2I( 0, aDy ) );
67 return entry;
68}
69
71{
73 tp.reset( 2 );
74
75 SCH_LINE* bus1 = make_bus( { 0, 0 }, { 5000000, 0 } );
76 SCH_LINE* bus2 = make_bus( { 0, 10000 }, { 5000000, 10000 } );
77
78 m_screen->Append( bus1 );
79 m_screen->Append( bus2 );
80
81 std::vector<SCH_BUS_BUS_ENTRY*> entries;
82
83 for( int ii = 0; ii < 50; ++ii )
84 {
85 int x = ii * 10000;
86 SCH_BUS_BUS_ENTRY* entry = make_entry( { x, 0 }, 10000 );
87 m_screen->Append( entry );
88 entries.push_back( entry );
89 }
90
91 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
92 m_schematic->ConnectionGraph()->Recalculate( sheets, true );
93
94 SCH_SHEET_PATH path = sheets[0];
95
96 for( SCH_BUS_BUS_ENTRY* entry : entries )
97 {
98 BOOST_CHECK( entry->m_connected_bus_items[0] == bus1 );
99 BOOST_CHECK( entry->m_connected_bus_items[1] == bus2 );
100 }
101
102 SCH_ITEM_VEC bus1_items = bus1->ConnectedItems( path );
103 SCH_ITEM_VEC bus2_items = bus2->ConnectedItems( path );
104
105 BOOST_CHECK_EQUAL( bus1_items.size(), entries.size() );
106 BOOST_CHECK_EQUAL( bus2_items.size(), entries.size() );
107
108 for( SCH_BUS_BUS_ENTRY* entry : entries )
109 {
110 BOOST_CHECK( std::find( bus1_items.begin(), bus1_items.end(), entry ) != bus1_items.end() );
111 BOOST_CHECK( std::find( bus2_items.begin(), bus2_items.end(), entry ) != bus2_items.end() );
112 }
113}
Class for a bus to bus entry.
void SetSize(const VECTOR2I &aSize)
Definition: sch_bus_entry.h:74
const SCH_ITEM_VEC & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:411
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:42
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:145
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:137
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
@ LAYER_BUS
Definition: layer_ids.h:443
std::vector< SCH_ITEM * > SCH_ITEM_VEC
Definition: sch_item.h:157
SCH_SCREEN * m_screen
SCH_SHEET * m_sheet
std::unique_ptr< SCHEMATIC > m_schematic
BUS_ENTRY_CONCURRENCY_FIXTURE()
SETTINGS_MANAGER m_mgr
static SCH_BUS_BUS_ENTRY * make_entry(const VECTOR2I &aPos, int aDy)
BOOST_FIXTURE_TEST_CASE(BusEntryConcurrency, BUS_ENTRY_CONCURRENCY_FIXTURE)
static SCH_LINE * make_bus(const VECTOR2I &aStart, const VECTOR2I &aEnd)
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
Definition: thread_pool.cpp:30
static thread_pool * tp
Definition: thread_pool.cpp:28
BS::thread_pool thread_pool
Definition: thread_pool.h:31
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695