torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ArcUsageUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit test for the ArcUsage class.
18 
19 #include <boost/test/unit_test.hpp>
22 
23 namespace torc {
24 namespace architecture {
25 
26 BOOST_AUTO_TEST_SUITE(architecture)
27 
28 using namespace torc::architecture::xilinx;
29 
30 /// \brief Unit test for the ArcUsage class.
31 BOOST_AUTO_TEST_CASE(ArcUsageUnitTest) {
32  // supporting variables
33  DDB ddb("xcv50");
34  const Tiles& tiles = ddb.getTiles();
35  Tilewire tilewire1 = ddb.lookupTilewire("R1C1", "S0_X");
36  Tilewire tilewire2 = ddb.lookupTilewire("R1C1", "OUT0");
37  Tilewire tilewire3(tilewire2.getTileIndex(), WireIndex(10000));
38  Arc arc1(tilewire1, tilewire2);
39  uint32_t virtexCenterArcCount = 1511u;
40 
41  // members tested:
42  // const Tiles& mTiles;
43  // Array<dynamic_bitset*> mBitsets;
44  // dynamic_bitset mTileDirty;
45  // functions tested:
46  // ArcUsage(const Tiles& inTiles);
47  // void autosize(void);
48  // uint32_t getArcUsageCount(void) const;
49  // TileCount getTileUsageCount(void) const;
50  // uint32_t getBitCount(void) const;
51  ArcUsage arcUsage(tiles);
52  arcUsage.autosize();
53  BOOST_CHECK(arcUsage.mBitsets.getSize() > 0);
54  BOOST_CHECK(arcUsage.getArcUsageCount() == 0);
55  BOOST_CHECK(arcUsage.getTileUsageCount() == TileCount(0));
56  BOOST_CHECK(arcUsage.getBitCount() == 0);
57 
58  // members tested:
59  // TileCount mTileUsageCount;
60  // uint32_t mBitCount;
61  // functions tested:
62  // inline bool isUsed(const Arc& inArc);
63  // bool isUsed(const Tilewire& inTilewire1, const Tilewire& inTilewire2) const;
64  // inline void use(const Arc& inArc) ;
65  // void use(const Tilewire& inTilewire1, const Tilewire& inTilewire2);
66  // inline void release(const Arc& inArc);
67  // void release(const Tilewire& inTilewire1, const Tilewire& inTilewire2);
68  // uint32_t getArcUsageCount(void) const;
69  // TileCount getTileUsageCount(void) const;
70  // uint32_t getBitCount(void) const;
71  BOOST_CHECK_EQUAL(arcUsage.isUsed(arc1), false);
72  arcUsage.use(arc1);
73  BOOST_CHECK_EQUAL(arcUsage.isUsed(arc1), true);
74  BOOST_CHECK_EQUAL(arcUsage.getArcUsageCount(), 1u);
75  BOOST_CHECK_EQUAL(arcUsage.getTileUsageCount(), TileCount(1));
76  BOOST_CHECK_EQUAL(arcUsage.getBitCount(), virtexCenterArcCount);
77  arcUsage.release(arc1);
78  BOOST_CHECK_EQUAL(arcUsage.isUsed(arc1), false);
79  BOOST_CHECK_EQUAL(arcUsage.getArcUsageCount(), 0u);
80  BOOST_CHECK_EQUAL(arcUsage.getTileUsageCount(), TileCount(1));
81  BOOST_CHECK_EQUAL(arcUsage.getBitCount(), virtexCenterArcCount);
82 
83  // exceptions tested:
84  // InvalidArcException;
85  // functions tested:
86  // uint32_t getArcOffset(const Tilewire& inTilewire1, const Tilewire& inTilewire2) const;
87  bool threwInvalidArcException = false;
88  try {
89  // this arc's tilewires are undefined
90  (void) arcUsage.getArcOffset(Tilewire(), Tilewire());
91  }
92  catch(InvalidArcException iae) {
93  threwInvalidArcException = true;
94  }
95  BOOST_CHECK_EQUAL(threwInvalidArcException, true);
96  threwInvalidArcException = false;
97  try {
98  // this arc is valid (and its tilewires are defined)
99  (void) arcUsage.getArcOffset(tilewire1, tilewire2);
100  }
101  catch(InvalidArcException iae) {
102  threwInvalidArcException = true;
103  }
104  BOOST_CHECK_EQUAL(threwInvalidArcException, false);
105  threwInvalidArcException = false;
106  try {
107  // this arc's tilewires are defined, but the are is invalid
108  (void) arcUsage.getArcOffset(tilewire1, tilewire3);
109  }
110  catch(InvalidArcException iae) {
111  threwInvalidArcException = true;
112  }
113  BOOST_CHECK_EQUAL(threwInvalidArcException, true);
114 
115  // functions tested:
116  // void clear(void);
117  arcUsage.use(arc1);
118  arcUsage.clear();
119  BOOST_CHECK_EQUAL(arcUsage.getArcUsageCount(), 0u);
120  BOOST_CHECK_EQUAL(arcUsage.getTileUsageCount(), TileCount(1));
121  BOOST_CHECK_EQUAL(arcUsage.getBitCount(), virtexCenterArcCount);
122 
123  // functions not tested:
124  // ~ArcUsage(void);
125  ArcUsage* arcUsagePtr = new ArcUsage(tiles);
126  arcUsagePtr->autosize();
127  arcUsagePtr->use(arc1);
128  arcUsagePtr->~ArcUsage();
129  uint32_t bitsetsAfterDestruction = 0;
130  for(uint32_t i = 0; i < arcUsagePtr->mBitsets.getSize(); i++) {
131  bitsetsAfterDestruction += (arcUsagePtr->mBitsets[i] != 0);
132  }
133  BOOST_CHECK_EQUAL(bitsetsAfterDestruction, 0u);
134 }
135 
136 BOOST_AUTO_TEST_SUITE_END()
137 
138 } // namespace architecture
139 } // namespace torc
Encapsulation of an arc between two tilewires.
Definition: Arc.hpp:28
void autosize(void)
Size the wire usage according to the number of device tiles.
Definition: ArcUsage.hpp:120
void clear(void)
Marks all arcs as being unused, without releasing the bitset objects.
Definition: ArcUsage.hpp:192
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
BOOST_AUTO_TEST_CASE(ArcUnitTest)
Unit test for the Arc class.
Definition: ArcUnitTest.cpp:29
Array< dynamic_bitset * > mBitsets
The wire usage bitset array.
Definition: ArcUsage.hpp:54
TileCount getTileUsageCount(void) const
Returns the number of tiles that have been touched.
Definition: ArcUsage.hpp:246
const Tiles & getTiles(void) const
Returns a constant reference to the family and device tile data.
Definition: DDB.hpp:146
uint32_t getArcUsageCount(void) const
Returns the number of arcs in use.
Definition: ArcUsage.hpp:228
uint32_t getArcOffset(const Tilewire &inTilewire1, const Tilewire &inTilewire2) const
Returns the offset into the bitset for the specified arc.
Definition: ArcUsage.hpp:64
Encapsulation of a wire index in an unsigned 16-bit integer.
uint32_t getBitCount(void) const
Returns the number of bits allocated.
Definition: ArcUsage.hpp:248
void use(const Arc &inArc)
Marks the specified arc as being used.
Definition: ArcUsage.hpp:133
Encapsulation of a device tile and wire pair.
Definition: Tilewire.hpp:39
Encapsulation the design arc usage.
Definition: ArcUsage.hpp:38
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
Encapsulation of a tile count in an unsigned 32-bit integer.
Header for the ArcUsage class.
Tilewire lookupTilewire(const std::string &inTileName, const std::string &inWireName)
Returns the tilewire for the specified tile and wire names.
Definition: DDB.hpp:257
Header for the DDB class.
const TileIndex & getTileIndex(void) const
Returns the tile index.
Definition: Tilewire.hpp:64
void release(const Arc &inArc)
Marks the specified arc as being unused.
Definition: ArcUsage.hpp:169
bool isUsed(const Arc &inArc)
Determines whether the specified arc is in use.
Definition: ArcUsage.hpp:209
uint32_t getSize(void) const
Returns the array size.
Definition: Array.hpp:104