torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Virtex5AssemblerUnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/bitstream/assembler/lut/parser.yy $
3 // $Id: parser.yy 1303 2013-02-25 23:18:16Z nsteiner $
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 #include <boost/test/unit_test.hpp>
20 #include <boost/filesystem.hpp>
21 
22 namespace torc {
23 namespace bitstream {
24 
25 BOOST_AUTO_TEST_SUITE(bitstream)
26 
27 bool CompareVirtexBitstreams(boost::filesystem::path bitFile1, boost::filesystem::path bitFile2);
28 void GenerateBitstreamAndCompare(boost::filesystem::path &xdlFilePath);
29 
30 
31 BOOST_AUTO_TEST_CASE(hexCharacterToDec) {
32  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('0'), 0);
33  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('1'), 1);
34  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('2'), 2);
35  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('3'), 3);
36  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('4'), 4);
37  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('5'), 5);
38  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('6'), 6);
39  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('7'), 7);
40  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('8'), 8);
41  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('9'), 9);
42  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('A'), 10);
43  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('B'), 11);
44  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('C'), 12);
45  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('D'), 13);
46  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('E'), 14);
47  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('F'), 15);
48  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('a'), 10);
49  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('b'), 11);
50  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('c'), 12);
51  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('d'), 13);
52  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('e'), 14);
53  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('f'), 15);
54  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('@'), -1);
55  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('g'), -1);
56  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec(' '), -1);
57  BOOST_CHECK_EQUAL(Assembler::hexCharacterToDec('~'), -1);
58 }
59 
60 BOOST_AUTO_TEST_CASE(Virtex5Slicel) {
61 
62  // look up the command line arguments
63  int& argc = boost::unit_test::framework::master_test_suite().argc;
64  char**& argv = boost::unit_test::framework::master_test_suite().argv;
65 
66  BOOST_REQUIRE(argc >= 1);
67  // resolve symbolic links if applicable
68  torc::common::DirectoryTree directoryTree(argv[0]);
69 
70  boost::filesystem::path testFolder = torc::common::DirectoryTree::getExecutablePath() / "torc/bitstream/test_cases";
71 
72  boost::filesystem::path xdlFilePath = testFolder / "slicel.xdl";
73 }
74 
76  // Open the XDL file and check if it opens successfully
77  std::fstream xdlFileStream(xdlFilePath.string().c_str());
78  BOOST_REQUIRE(xdlFileStream.good());
79 
80  // Import the XDL file
82  importer(xdlFileStream, "XdlDesignExample");
83  // Get the design pointer
84  torc::physical::DesignSharedPtr designPtr = importer.getDesignPtr();
85  torc::architecture::DDB ddb(designPtr->getDevice());
86 
87  boost::filesystem::path customBitFile = xdlFilePath.replace_extension("custom.bit");
88  boost::filesystem::path xilinxBitFile = xdlFilePath.replace_extension("bit");
89 
90  // Create bitstream assembler object
92  bitAssemblerPtr->generateBitstream(designPtr, customBitFile);
93 
94  CompareVirtexBitstreams(customBitFile, xilinxBitFile);
95 }
96 
98 
99  using namespace torc::bitstream;
100 
101  bool returnCode = false;
102  const int crcWordIndex = 20; // There are 41 words in the frame and CRC word is the middle one
103 
104  // Read the two bitstreams
107 
108  // Proceed only if both bitstreams were read successfully
109  BOOST_REQUIRE(bitstreamPtr1 != NULL);
110  BOOST_REQUIRE(bitstreamPtr2 != NULL);
111 
112  // dynamically cast the bitstream pointer into a Virtex5 bitstream pointer
113  boost::shared_ptr<Virtex> virtexBitstreamPtr1 = boost::dynamic_pointer_cast<Virtex>(
114  bitstreamPtr1);
115 
116  boost::shared_ptr<Virtex> virtexBitstreamPtr2 = boost::dynamic_pointer_cast<Virtex>(
117  bitstreamPtr2);
118  BOOST_REQUIRE(virtexBitstreamPtr1 != NULL);
119  BOOST_REQUIRE(virtexBitstreamPtr2 != NULL);
120 
121  // initialize frame map
122  virtexBitstreamPtr1->initializeDeviceInfo(bitstreamPtr1->getDesignName());
123  virtexBitstreamPtr1->initializeFrameMaps();
124  virtexBitstreamPtr1->initializeFullFrameBlocks();
125 
126  virtexBitstreamPtr2->initializeDeviceInfo(bitstreamPtr2->getDesignName());
127  virtexBitstreamPtr2->initializeFrameMaps();
128  virtexBitstreamPtr2->initializeFullFrameBlocks();
129 
130  // look up the frame blocks
131  VirtexFrameBlocks& frameBlocks1 = virtexBitstreamPtr1->getFrameBlocks();
132  VirtexFrameBlocks& frameBlocks2 = virtexBitstreamPtr2->getFrameBlocks();
133 
134  // iterate over the block types
135  for(int blockIndex = 0; blockIndex < Virtex5::eFarBlockTypeCount; blockIndex++) {
136  // look up the frame set for this block
137  VirtexFrameSet& frameSet1 = frameBlocks1.mBlock[blockIndex];
138  VirtexFrameSet& frameSet2 = frameBlocks2.mBlock[blockIndex];
139 
140  BOOST_CHECK_EQUAL(frameSet1.size(), frameSet2.size());
141 
142  int usedFrameCount = 0;
143  size_t frameIndex = 0;
144  // iterate over the frames
145  for(; frameIndex < frameSet1.size(); frameIndex++) {
146  // look up the frame for this set
147  VirtexFrameSharedPtr framePtr1 = frameSet1[frameIndex];
148  VirtexFrameSharedPtr framePtr2 = frameSet2[frameIndex];
149 
150  const VirtexFrame::word_t* words1 = framePtr1->getWords();
151  const VirtexFrame::word_t* words2 = framePtr2->getWords();
152 
153  const VirtexFrame::word_t* pWords1 = words1;
154  const VirtexFrame::word_t* pWords2 = words2;
155  const VirtexFrame::word_t* eWords1 = pWords1 + framePtr1->getLength();
156  const VirtexFrame::word_t* eWords2 = pWords2 + framePtr2->getLength();
157 
158  BOOST_CHECK_EQUAL(framePtr1->getLength(), framePtr2->getLength());
159 
160  if(framePtr1->isUsed())
161  usedFrameCount++;
162  // iterate over the frame words
163  bool found = false;
164  int wordIndex = 0;
165 
166  // Iterate over the frame words
167  while(pWords1 < eWords1) {
168 
169  // If the word is not zero and not same as that of null bitstream and not crc word
170  if(*pWords1 != *pWords2 && wordIndex != crcWordIndex) {
171  found = true;
172  returnCode = false;
173  break;
174  }
175  pWords1++;
176  pWords2++;
177  wordIndex++;
178  }
179  // if we found any non-zero words, display them
180  if(found) {
181  std::cout << "Found mis-match frame. Block: " << blockIndex << ", Frame Index: " << Hex32(
182  frameIndex) << std::endl;
183 
184  pWords1 = words1;
185  std::cout << " Frame 1: ";
186  while(pWords1 < eWords1) {
187  std::cout << Hex32(*pWords1++) << " ";
188  }
189  std::cout << std::endl;
190 
191  pWords2 = words2;
192  std::cout << " Frame 2: ";
193  while(pWords2 < eWords2) {
194  std::cout << Hex32(*pWords2++) << " ";
195  }
196  std::cout << std::endl;
197  }
198  }
199 
200  std::cout << std::endl;
201  // std::cout << "Used frame count " << usedFrameCount << std::endl;
202  // std::cout << "Total frame count " << frameIndex << std::endl;
203  }
204  BOOST_CHECK_EQUAL(returnCode, true);
205  return returnCode;
206 }
207 
208 BOOST_AUTO_TEST_SUITE_END()
209 }
210 }
211 
Device database, including complete wiring and logic support.
Definition: DDB.hpp:42
static int hexCharacterToDec(char inDigit)
Convert a hex ASCII character to a decimal value.
Definition: Assembler.hpp:139
static AssemblerSharedPtr newAssemblerPtr(torc::physical::DesignSharedPtr xdlDesignPtr, torc::architecture::DDB &inDB)
Header for the Factory class.
bool CompareVirtexBitstreams(boost::filesystem::path bitFile1, boost::filesystem::path bitFile2)
Encapsulation of filesystem paths that are used by the library.
void GenerateBitstreamAndCompare(boost::filesystem::path &xdlFilePath)
boost::filesystem::path path
boost::shared_ptr< Design > DesignSharedPtr
Shared pointer encapsulation of a Design.
static BitstreamSharedPtr newBitstreamPtr(const boost::filesystem::path &inPath)
Virtex bitstream.
Definition: Virtex.hpp:40
boost::shared_ptr< VirtexFrame > VirtexFrameSharedPtr
Virtex frame type.
Definition: Frame.hpp:108
Importer from XDL format into a physical design.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
boost::shared_ptr< Bitstream > BitstreamSharedPtr
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.
WORD_TYPE word_t
Frame word type.
Definition: Frame.hpp:48
boost::shared_ptr< Assembler > AssemblerSharedPtr
Typedef for shared pointer of Assembler class.
Definition: Assembler.hpp:345