torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VirtexPacketUnitTest.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 VirtexPacket 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 /// \brief Unit test for the VirtexPacket class.
33 BOOST_AUTO_TEST_CASE(VirtexPacketUnitTest) {
34 
35  // build the file paths
37  / "torc" / "bitstream" / "Virtex4UnitTest.reference.bit";
39  / "regression" / "VirtexPacketUnitTest.generated.bit";
40 
41  // read the bitstream
42  std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
43  BOOST_REQUIRE(fileStream.good());
44  Virtex4 bitstream;
45  bitstream.readHeader(fileStream);
46  std::string designName = bitstream.getDesignName();
47  std::string deviceName = bitstream.getDeviceName();
48  std::string designDate = bitstream.getDesignDate();
49  std::string designTime = bitstream.getDesignTime();
50  uint32_t bitstreamWordLength = bitstream.getBitstreamByteLength() >> 2;
51  std::cout << bitstream << std::endl;
52 
53  // add up the words lengths
54  uint32_t cumulativeWordLength = 0;
55  std::vector<VirtexPacket> packets;
56  while(cumulativeWordLength < bitstreamWordLength) {
57  VirtexPacket packet = VirtexPacket::read(fileStream);
58  packets.push_back(packet);
59  cumulativeWordLength += packet.getWordSize();
60  }
61 
62  cumulativeWordLength = 0;
63  std::vector<VirtexPacket>::iterator p = packets.begin();
64  std::vector<VirtexPacket>::iterator e = packets.end();
65  while(p < e) {
66  VirtexPacket& packet = *p++;
67  cumulativeWordLength += packet.getWordSize();
68  }
69 
70 }
71 
72 BOOST_AUTO_TEST_SUITE_END()
73 
74 } // namespace bitstream
75 } // 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 Virtex4 class.
Header for the DirectoryTree class.
uint32_t getWordSize(void) const
Returns the total number of words in the packet, including the header word.
std::string string
boost::filesystem::path path
Virtex4 bitstream.
Definition: Virtex4.hpp:40
Header for the VirtexPacket class.
static VirtexPacket read(std::istream &inStream)
Read a packet.
Bitstream packet for Virtex class architectures.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.