torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spartan6PacketUnitTest.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 Spartan6Packet 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(Spartan6PacketUnitTest) {
33 
34  // build the file paths
36  / "torc" / "bitstream" / "Spartan6UnitTest.reference.bit";
38  / "regression" / "Spartan6PacketUnitTest.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  Spartan6 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<Spartan6Packet> packets;
55  while(cumulativeWordLength < bitstreamWordLength) {
56  Spartan6Packet packet = Spartan6Packet::read(fileStream);
57  packets.push_back(packet);
58  cumulativeWordLength += packet.getWordSize();
59  }
60 
61  cumulativeWordLength = 0;
62  std::vector<Spartan6Packet>::iterator p = packets.begin();
63  std::vector<Spartan6Packet>::iterator e = packets.end();
64  while(p < e) {
65  Spartan6Packet& packet = *p++;
66  cumulativeWordLength += packet.getWordSize();
67  }
68 
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
72 
73 } // namespace bitstream
74 } // namespace torc
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.
Bitstream packet for Spartan 16 bit class architectures.
std::string string
Header for the Spartan6 class.
uint32_t getWordSize(void) const
Returns the total number of words in the packet, including the header word. In the case of Type 2 pa...
boost::filesystem::path path
Header for the Spartan6Packet class.
Spartan6 bitstream.
Definition: Spartan6.hpp:31
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.
static Spartan6Packet read(std::istream &inStream)
Read a packet.