torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TilesUnitTest.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 Tiles class.
18 
19 #include <boost/test/unit_test.hpp>
22 #include "torc/common/Devices.hpp"
23 
24 namespace torc {
25 namespace architecture {
26 
27 BOOST_AUTO_TEST_SUITE(architecture)
28 
29 // prototype for the worker function
30 void testDeviceTiles(DDB& inDDB);
31 
32 /// \brief Unit test for the Tiles class.
33 BOOST_AUTO_TEST_CASE(TilesUnitTest) {
34 
35  // iterate over the devices
37  torc::common::DeviceVector::const_iterator dp = devices.begin();
38  torc::common::DeviceVector::const_iterator de = devices.end();
39  while(dp < de) {
40  const std::string& device = *dp++;
41  if(device.empty()) break;
42  DDB ddb(device);
43  testDeviceTiles(ddb);
44  }
45 
46 }
47 
48 void testDeviceTiles(DDB& inDDB) {
49  // functions tested during database initialization and deletion:
50  // Tiles(void);
51  // ~Tiles(void);
52  // size_t readTileTypes(DigestStream& inStream);
53  // size_t readTileWireInfo(DigestStream& inStream);
54  // size_t readTileMap(DigestStream& inStream);
55  const Tiles& tiles = inDDB.getTiles();
56 
57  // functions tested:
58  // TileTypeCount getTileTypeCount(void) const;
59  // members tested:
60  // TileTypeCount mTileTypeCount;
61  xilinx::TileTypeCount tileTypeCount = tiles.getTileTypeCount();
62  if(tileTypeCount == xilinx::TileTypeCount(0)) // to reduce output
63  BOOST_CHECK(tileTypeCount != 0);
64 
65  // functions tested:
66  // const char* getTileTypeName(TileTypeIndex inTileTypeIndex) const;
67  // members tested:
68  // Array<const CharStringWrapper> mTileTypeNames;
69  for(xilinx::TileTypeIndex tileTypeIndex; tileTypeIndex < tileTypeCount; tileTypeIndex++) {
70  const char* tileTypeName = tiles.getTileTypeName(tileTypeIndex);
71  if(*tileTypeName == 0) // to reduce output
72  BOOST_CHECK(*tileTypeName != 0);
73  }
74 
75  // functions tested:
76  // TileCount getTileCount(void) const;
77  // TileRow getRowCount(void) const;
78  // TileCol getColCount(void) const;
79  // members tested:
80  // TileCount mTileCount;
81  // TileRow mRowCount;
82  // TileCol mColCount;
83  xilinx::TileCount tileCount = tiles.getTileCount();
84  xilinx::TileRow rowCount = tiles.getRowCount();
85  xilinx::TileCol colCount = tiles.getColCount();
86  if(tileCount == xilinx::TileCount(0)) // to reduce output
87  BOOST_CHECK(tileCount != 0);
88  if(rowCount == xilinx::TileRow(0)) // to reduce output
89  BOOST_CHECK(rowCount != 0);
90  if(colCount == xilinx::TileCol(0)) // to reduce output
91  BOOST_CHECK(colCount != 0);
92  if(static_cast<int>(tileCount) != rowCount * colCount) // to reduce output
93  BOOST_CHECK_EQUAL(static_cast<int>(tileCount), rowCount * colCount);
94 
95  // functions tested:
96  // const TileInfo& getTileInfo(TileIndex inTileIndex) const;
97  // TileIndex getTileIndex(TileRow inRow, TileCol inCol) const;
98  // TileIndex findTileIndex(const string& inName) const;
99  // static bool CompareTilePairByName(const TileNameIndexPair& inA,
100  // const TileNameIndexPair& inB);
101  // members tested:
102  // TileIndex** mTileMap;
103  // Array<const TileInfo> mTiles;
104  // Array<const TileNameIndexPair> mOrderedTileNames;
105  for(xilinx::TileIndex tileIndex; tileIndex < tileCount; tileIndex++) {
106  // look up the tile info
107  const TileInfo& tileInfo = tiles.getTileInfo(tileIndex);
108  // verify that tile indexes and coordinates are consistent
109  xilinx::TileRow tileRow = tileInfo.getRow();
110  xilinx::TileCol tileCol = tileInfo.getCol();
111  const char* tileName = tileInfo.getName();
112  if(*tileName == 0) // to reduce output
113  BOOST_CHECK(*tileName != 0);
114  xilinx::TileIndex rowColTileIndex = tiles.getTileIndex(tileRow, tileCol);
115  if(tileIndex != rowColTileIndex) // to reduce output
116  BOOST_CHECK_EQUAL(tileIndex, rowColTileIndex);
117  xilinx::TileIndex findTileIndex = tiles.findTileIndex(tileName);
118  if(tileIndex != findTileIndex) // to reduce output
119  BOOST_CHECK_EQUAL(tileIndex, findTileIndex);
120  }
121 
122  // functions tested:
123  // const Array<const WireInfo>& getWireInfo(TileTypeIndex inTileTypeIndex) const;
124  // const WireInfo& getWireInfo(TileTypeIndex inTileTypeIndex, WireIndex inWireIndex) const;
125  // static bool CompareWirePairByName(const WireNameIndexPair& inA,
126  // const WireNameIndexPair& inB);
127  // WireIndex findWireIndex(TileTypeIndex inTileTypeIndex, const string& inName) const;
128  // members tested:
129  // Array2D<const WireInfo> mWires;
130  // Array2D<const WireNameIndexPair> mOrderedWireNames;
131  for(xilinx::TileTypeIndex tileTypeIndex; tileTypeIndex < tileTypeCount; tileTypeIndex++) {
132  // verify that wire indexes are consistent
133  xilinx::WireCount wireCount = tiles.getWireCount(tileTypeIndex);
134  const Array<const WireInfo>& wireInfoArray = tiles.getWireInfo(tileTypeIndex);
135  for(xilinx::WireIndex wireIndex; wireIndex < wireCount; wireIndex++) {
136  const WireInfo& wireInfo = tiles.getWireInfo(tileTypeIndex, wireIndex);
137  if(&wireInfo != &wireInfoArray[wireIndex]) // to reduce output
138  BOOST_CHECK(&wireInfo == &wireInfoArray[wireIndex]);
139  const char* wireName = wireInfo.getName();
140  if(*wireName == 0) // to reduce output
141  BOOST_CHECK(*wireName != 0);
142  xilinx::WireIndex findWireIndex = tiles.findWireIndex(tileTypeIndex, wireName);
143  if(wireIndex != findWireIndex) // to reduce output
144  BOOST_CHECK_EQUAL(wireIndex, findWireIndex);
145  }
146  }
147 }
148 
149 BOOST_AUTO_TEST_SUITE_END()
150 
151 } // namespace architecture
152 } // namespace torc
Encapsulation of a tile index in an unsigned 32-bit integer.
const TileCol & getCol(void) const
Returns the column for this tile.
Definition: TileInfo.hpp:96
Encapsulation of a tile row in an unsigned 16-bit integer.
const TileRow & getRow(void) const
Returns the row for this tile.
Definition: TileInfo.hpp:94
Encapsulation of a tile column in an unsigned 16-bit integer.
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
TileTypeCount getTileTypeCount(void) const
Returns the tile type count for this device.
Definition: Tiles.hpp:151
BOOST_AUTO_TEST_CASE(ArcUnitTest)
Unit test for the Arc class.
Definition: ArcUnitTest.cpp:29
TileRow getRowCount(void) const
Returns the row count for this device.
Definition: Tiles.hpp:153
const Tiles & getTiles(void) const
Returns a constant reference to the family and device tile data.
Definition: DDB.hpp:146
const TileInfo & getTileInfo(TileIndex inTileIndex) const
Returns the TileInfo object for the specified tile.
Definition: Tiles.hpp:137
const Array< const WireInfo > & getWireInfo(TileTypeIndex inTileTypeIndex) const
Returns the WireInfo array for the specified tile type.
Definition: Tiles.hpp:140
Encapsulation of a wire index in an unsigned 16-bit integer.
TileCount getTileCount(void) const
Returns the tile count for this device.
Definition: Tiles.hpp:149
std::string string
Tile map, tile type, and wire information for the family and device.
Definition: Tiles.hpp:36
Encapsulation of a wire count in an unsigned 16-bit integer.
Encapsulation of a tile count in an unsigned 32-bit integer.
Encapsulation of a tile within a device tile map.
Definition: TileInfo.hpp:33
const char * getTileTypeName(TileTypeIndex inTileTypeIndex) const
Returns the tile type name for the given tile type index.
Definition: Tiles.hpp:164
Header for the Devices class.
TileIndex findTileIndex(const string &inName) const
Returns the tile index for the given tile name.
Definition: Tiles.hpp:170
Encapsulation of a tile type count in an unsigned 16-bit integer.
TileCol getColCount(void) const
Returns the column count for this device.
Definition: Tiles.hpp:155
WireIndex findWireIndex(TileTypeIndex inTileTypeIndex, const string &inName) const
Returns the wire index for the given wire name in the given tile type.
Definition: Tiles.hpp:182
Encapsulation of a tile type index in an unsigned 16-bit integer.
const char * getName(void) const
Returns the name for this tile.
Definition: TileInfo.hpp:98
Header for the DDB class.
Encapsulation of a wire within a tile type.
Definition: WireInfo.hpp:36
std::vector< std::string > DeviceVector
Vector of device names.
Definition: Devices.hpp:119
Header for the Tiles class.
const char * getName(void) const
Returns the name for this wire.
Definition: WireInfo.hpp:109
static const DeviceVector & getUnitTestDevices(void)
Returns a subset of devices for unit tests.
Definition: Devices.hpp:209
void testDeviceTiles(DDB &inDDB)
WireCount getWireCount(TileTypeIndex inTileTypeIndex) const
Returns the wire count for the specified tile type.
Definition: Tiles.hpp:157
TileIndex getTileIndex(TileRow inRow, TileCol inCol) const
Returns the tile index for the given [row,column] pair.
Definition: Tiles.hpp:161
Encapsulation of a static array.
Definition: Array.hpp:39