torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpartanPacketUnitTest.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 SpartanPacket class.
18 
19 #include <boost/test/unit_test.hpp>
23 #include <fstream>
24 #include <iostream>
25 #include <iomanip>
26 
27 namespace torc {
28 namespace bitstream {
29 
30 BOOST_AUTO_TEST_SUITE(bitstream)
31 
32 BOOST_AUTO_TEST_CASE(SpartanPacketUnitTest) {
33 
34  // build the file paths
36  / "torc" / "bitstream" / "Spartan3EUnitTest.reference.bit";
38  / "regression" / "SpartanPacketUnitTest.generated.bit";
39 
40  // read the bitstream
41  std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
42  BOOST_REQUIRE(fileStream.good());
43  Spartan3E bitstream;
44  bitstream.readHeader(fileStream);
45  std::string designName = bitstream.getDesignName();
46  std::string deviceName = bitstream.getDeviceName();
47  std::string designDate = bitstream.getDesignDate();
48  std::string designTime = bitstream.getDesignTime();
49  uint32_t bitstreamWordLength = bitstream.getBitstreamByteLength() >> 2;
50  std::cout << bitstream << std::endl;
51 
52  // add up the words lengths
53  uint32_t cumulativeWordLength = 0;
54  std::vector<SpartanPacket> packets;
55  while(cumulativeWordLength < bitstreamWordLength) {
56  SpartanPacket packet = SpartanPacket::read(fileStream);
57  packets.push_back(packet);
58  cumulativeWordLength += packet.getWordSize();
59  }
60 
61  cumulativeWordLength = 0;
62  std::vector<SpartanPacket>::iterator p = packets.begin();
63  std::vector<SpartanPacket>::iterator e = packets.end();
64  while(p < e) {
65  SpartanPacket& packet = *p++;
66  cumulativeWordLength += packet.getWordSize();
67  }
68 
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
72 
73 } // namespace bitstream
74 } // namespace torc
Header for the SpartanPacket class.
static bool readHeader(std::istream &inStream, string &outDesignName, string &outDeviceName, string &outDesignDate, string &outDesignTime, uint32_t &outBitstreamLength, uint32_t &outHeaderLength)
Read a bitstream header, and return its fields.
Header for the DirectoryTree class.
std::string string
boost::filesystem::path path
Header for the Spartan3E class.
Spartan3E bitstream.
Definition: Spartan3E.hpp:38
Bitstream packet for Spartan class architectures.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
static SpartanPacket read(std::istream &inStream)
Read a packet.
uint32_t getWordSize(void) const
Returns the total number of words in the packet, including the header word.
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.