torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spartan6BuildHelperUnitTest.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 Spartan6BuildHelper class.
18 
19 #include <boost/test/unit_test.hpp>
23 #include "torc/common/Devices.hpp"
24 #include <fstream>
25 #include <iostream>
26 #include <boost/filesystem.hpp>
27 
28 namespace torc {
29 namespace bitstream {
30 
31 BOOST_AUTO_TEST_SUITE(regression)
32 BOOST_AUTO_TEST_SUITE(bitstream)
33 
34 void buildSpartan6Partials(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
35 void buildSpartan6Partials(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
36 
37  // build the file paths
38  boost::filesystem::path regressionPath = inWorkingPath / "torc" / "bitstream" / "regression";
39  boost::filesystem::path generatedPathOdd = regressionPath / (inDeviceName + ".odd.bit");
40  boost::filesystem::path generatedPathEven = regressionPath / (inDeviceName + ".even.bit");
41  boost::filesystem::path referencePath = regressionPath / (inDeviceName + ".full.bit");
42 
43  // read the bitstream
44  std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
45  std::cerr << "Trying to read: " << referencePath << std::endl;
46  BOOST_REQUIRE(fileStream.good());
47  Spartan6 bitstream;
48  bitstream.read(fileStream, false);
49  // write the bitstream digest to the console
50 // std::cout << bitstream << std::endl;
51 
52  // determine the device IO frame length and the FDRI word count; then touch every other frame
53  // in the device
54  uint16_t stdFrameLength = 65;
55  uint16_t ioFrameLength = 0;
56  uint32_t wordCount = 0;
57  Spartan6::iterator p = bitstream.begin();
58  Spartan6::iterator e = bitstream.end();
59  // describe the FLR and FDRI write headers
62  uint32_t writeFDRIHeader = Spartan6Packet::makeHeader(Spartan6Packet::ePacketType2,
64  while(p < e) {
65  const Spartan6Packet& packet = *p++;
66  // determine the IO frame length
67  if(packet.getHeader() == writeFLRHeader) {
68  ioFrameLength = packet[1] + 1;
69  std::cout << inDeviceName << " IO frame length: " << ioFrameLength << std::endl;
70  // determine the FDRI word count, and touch every other frame
71  } else if(packet.getHeader() == writeFDRIHeader) {
72  // get the word count
73  wordCount = packet.getWordCount();
74  boost::shared_array<uint16_t> words = packet.getWords();
75  std::cout << inDeviceName << " FDRI word count: " << wordCount << std::endl;
76  std::cout << inDeviceName << " stdandard words: " << (wordCount - ioFrameLength)
77  << std::endl;
78 
79  // invert a word in every odd frame and write the resulting bitstream
80 
81  {
82  // iterate over every other frame, breaking right after we touch the IO frame
83  size_t pos = 1;
84  size_t end = wordCount - ioFrameLength - stdFrameLength;
85  while(pos <= end) {
86  words[pos] = ~words[pos];
87  pos += (stdFrameLength << 1);
88  // note that we add twice the frame length, effectively skipping every other
89  // frame
90  }
91  // write the modified bitstream for use as a partial bitstream reference
92  std::fstream outputStream(generatedPathOdd.string().c_str(),
93  std::ios::binary | std::ios::out);
94  BOOST_REQUIRE(outputStream.good());
95  bitstream.write(outputStream);
96  outputStream.flush();
97  }
98 
99  // undo inversions to odd frames, and invert a word in every even frame
100 
101  {
102  // iterate over every other frame, breaking right after we touch the IO frame
103  size_t pos = 1;
104  size_t end = wordCount - ioFrameLength - stdFrameLength;
105  while(pos <= end) {
106  words[pos] = ~words[pos];
107  pos += stdFrameLength;
108  // note that by flipping a word in *every* frame, we also undo the previous
109  // inversions to odd frames
110  }
111  // write the modified bitstream for use as a partial bitstream reference
112  std::fstream outputStream(generatedPathEven.string().c_str(),
113  std::ios::binary | std::ios::out);
114  BOOST_REQUIRE(outputStream.good());
115  bitstream.write(outputStream);
116  outputStream.flush();
117  }
118 
119  }
120  }
121 
122 }
123 
124 /// \brief Unit test for the Spartan6BuildHelper class.
125 BOOST_AUTO_TEST_CASE(Spartan6BuildHelperUnitTest) {
126 
127  // this unit test needs to be superseded by torc/trunk/devel/spartan6-debug-bitstream-generation
128  BOOST_REQUIRE(false);
129 
130  // look up the command line arguments
131  int& argc = boost::unit_test::framework::master_test_suite().argc;
132  char**& argv = boost::unit_test::framework::master_test_suite().argv;
133  // make sure that we at least have the name under which we were invoked
134  BOOST_REQUIRE(argc >= 1);
135  // resolve symbolic links if applicable
136  torc::common::DirectoryTree directoryTree(argv[0]);
137 
138  // iterate over the Spartan6 devices
139  {
141  torc::common::DeviceVector::const_iterator dp = devices.begin();
142  torc::common::DeviceVector::const_iterator de = devices.end();
143  while(dp < de) {
144  const std::string& device = *dp++;
145  if(device.empty()) break;
147  }
148  }
149 
150 }
151 
152 /// \brief Unit test to dump Spartan6 bitstream packets.
153 BOOST_AUTO_TEST_CASE(Spartan6DumpPacketsUnitTest) {
154 
155  // look up the command line arguments
156  int& argc = boost::unit_test::framework::master_test_suite().argc;
157  char**& argv = boost::unit_test::framework::master_test_suite().argv;
158  // make sure that we at least have the name under which we were invoked
159  BOOST_REQUIRE(argc >= 1);
160  // resolve symbolic links if applicable
161  torc::common::DirectoryTree directoryTree(argv[0]);
162 
163  // build the file paths
164  std::string inDeviceName = "xc6slx4";
166  / "torc" / "bitstream" / "regression";
167  boost::filesystem::path referencePathOdd = regressionPath / (inDeviceName + ".odd.bit");
168  boost::filesystem::path referencePathEven = regressionPath / (inDeviceName + ".even.bit");
169 
170  {
171  // read the bitstream
172  std::fstream fileStream(referencePathOdd.string().c_str(), std::ios::binary | std::ios::in);
173  std::cerr << "Trying to read: " << referencePathOdd << std::endl;
174  BOOST_REQUIRE(fileStream.good());
175  Spartan6 bitstream;
176  bitstream.read(fileStream, false);
177  // write the bitstream digest to the console
178  std::cout << bitstream << std::endl;
179  }
180 
181  {
182  // read the bitstream
183  std::fstream fileStream(referencePathEven.string().c_str(), std::ios::binary | std::ios::in);
184  std::cerr << "Trying to read: " << referencePathEven << std::endl;
185  BOOST_REQUIRE(fileStream.good());
186  Spartan6 bitstream;
187  bitstream.read(fileStream, false);
188  // write the bitstream digest to the console
189  std::cout << bitstream << std::endl;
190  }
191 
192 }
193 
194 BOOST_AUTO_TEST_SUITE_END()
195 BOOST_AUTO_TEST_SUITE_END()
196 
197 } // namespace bitstream
198 } // namespace torc
uint16_t getHeader(void) const
uint32_t getWordCount(void) const
Returns the number of payload words in the packet, excluding the header word.
static const DeviceVector & getSpartan6Devices(void)
Returns the Spartan6 devices.
Definition: Devices.hpp:205
Header for the DirectoryTree class.
void buildSpartan6Partials(const std::string &inDeviceName, const boost::filesystem::path &inWorkingPath)
const WordSharedArray getWords(void) const
brief Returns the raw packet words, including the header word.
Bitstream packet for Spartan 16 bit class architectures.
static uint16_t makeHeader(EPacketType inType, EOpcode inOpcode, uint16_t inAddress, uint32_t inCount)
Construct a packet header.
std::string string
Header for the Spartan6 class.
Header for the Spartan6BuildHelper class.
Encapsulation of filesystem paths that are used by the library.
Header for the Devices class.
boost::filesystem::path path
Spartan6 bitstream.
Definition: Spartan6.hpp:31
static const boost::filesystem::path & getWorkingPath(void)
Returns the absolute path to the working directory.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
std::vector< std::string > DeviceVector
Vector of device names.
Definition: Devices.hpp:119
virtual void read(std::istream &inStream, bool inCleanDateAndTime=true)
Read the bitstream header and packets from a stream.