00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <boost/test/unit_test.hpp>
00020 #include "torc/bitstream/build/Spartan6BuildHelper.hpp"
00021 #include "torc/bitstream/Spartan6.hpp"
00022 #include "torc/common/DirectoryTree.hpp"
00023 #include "torc/common/Devices.hpp"
00024 #include <fstream>
00025 #include <iostream>
00026 #include <boost/filesystem.hpp>
00027
00028 namespace torc {
00029 namespace bitstream {
00030
00031 BOOST_AUTO_TEST_SUITE(bitstream)
00032
00033 void buildSpartan6Partials(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00034 void buildSpartan6Partials(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00035
00036
00037 boost::filesystem::path regressionPath = inWorkingPath / "torc" / "bitstream" / "regression";
00038 boost::filesystem::path generatedPathOdd = regressionPath / (inDeviceName + ".odd.bit");
00039 boost::filesystem::path generatedPathEven = regressionPath / (inDeviceName + ".even.bit");
00040 boost::filesystem::path referencePath = regressionPath / (inDeviceName + ".full.bit");
00041
00042
00043 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00044 std::cerr << "Trying to read: " << referencePath << std::endl;
00045 BOOST_REQUIRE(fileStream.good());
00046 Spartan6 bitstream;
00047 bitstream.read(fileStream, false);
00048
00049
00050
00051
00052
00053 uint16_t stdFrameLength = 65;
00054 uint16_t ioFrameLength = 0;
00055 uint32_t wordCount = 0;
00056 Spartan6::iterator p = bitstream.begin();
00057 Spartan6::iterator e = bitstream.end();
00058
00059 uint32_t writeFLRHeader = Spartan6Packet::makeHeader(Spartan6Packet::ePacketType1,
00060 Spartan6Packet::eOpcodeWrite, Spartan6::eRegisterFLR, 1);
00061 uint32_t writeFDRIHeader = Spartan6Packet::makeHeader(Spartan6Packet::ePacketType2,
00062 Spartan6Packet::eOpcodeWrite, Spartan6::eRegisterFDRI, 1);
00063 while(p < e) {
00064 const Spartan6Packet& packet = *p++;
00065
00066 if(packet.getHeader() == writeFLRHeader) {
00067 ioFrameLength = packet[1] + 1;
00068 std::cout << inDeviceName << " IO frame length: " << ioFrameLength << std::endl;
00069
00070 } else if(packet.getHeader() == writeFDRIHeader) {
00071
00072 wordCount = packet.getWordCount();
00073 boost::shared_array<uint16_t> words = packet.getWords();
00074 std::cout << inDeviceName << " FDRI word count: " << wordCount << std::endl;
00075 std::cout << inDeviceName << " stdandard words: " << (wordCount - ioFrameLength)
00076 << std::endl;
00077
00078
00079
00080 {
00081
00082 size_t pos = 1;
00083 size_t end = wordCount - ioFrameLength - stdFrameLength;
00084 while(pos <= end) {
00085 words[pos] = ~words[pos];
00086 pos += (stdFrameLength << 1);
00087
00088
00089 }
00090
00091 std::fstream outputStream(generatedPathOdd.string().c_str(),
00092 std::ios::binary | std::ios::out);
00093 BOOST_REQUIRE(outputStream.good());
00094 bitstream.write(outputStream);
00095 outputStream.flush();
00096 }
00097
00098
00099
00100 {
00101
00102 size_t pos = 1;
00103 size_t end = wordCount - ioFrameLength - stdFrameLength;
00104 while(pos <= end) {
00105 words[pos] = ~words[pos];
00106 pos += stdFrameLength;
00107
00108
00109 }
00110
00111 std::fstream outputStream(generatedPathEven.string().c_str(),
00112 std::ios::binary | std::ios::out);
00113 BOOST_REQUIRE(outputStream.good());
00114 bitstream.write(outputStream);
00115 outputStream.flush();
00116 }
00117
00118 }
00119 }
00120
00121 }
00122
00123
00124 BOOST_AUTO_TEST_CASE(Spartan6BuildHelperUnitTest) {
00125
00126 BOOST_REQUIRE(true);
00127
00128
00129 int& argc = boost::unit_test::framework::master_test_suite().argc;
00130 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00131
00132 BOOST_REQUIRE(argc >= 1);
00133
00134 torc::common::DirectoryTree directoryTree(argv[0]);
00135
00136
00137 {
00138 const torc::common::DeviceVector& devices = torc::common::Devices::getSpartan6Devices();
00139 torc::common::DeviceVector::const_iterator dp = devices.begin();
00140 torc::common::DeviceVector::const_iterator de = devices.end();
00141 while(dp < de) {
00142 const std::string& device = *dp++;
00143 if(device.empty()) break;
00144 buildSpartan6Partials(device, torc::common::DirectoryTree::getWorkingPath());
00145 }
00146 }
00147
00148
00149 {
00150 const torc::common::DeviceVector& devices = torc::common::Devices::getSpartan6LDevices();
00151 torc::common::DeviceVector::const_iterator dp = devices.begin();
00152 torc::common::DeviceVector::const_iterator de = devices.end();
00153 while(dp < de) {
00154 const std::string& device = *dp++;
00155 if(device.empty()) break;
00156 buildSpartan6Partials(device, torc::common::DirectoryTree::getWorkingPath());
00157 }
00158 }
00159
00160 }
00161
00162
00163 BOOST_AUTO_TEST_CASE(Spartan6DumpPacketsUnitTest) {
00164
00165
00166 int& argc = boost::unit_test::framework::master_test_suite().argc;
00167 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00168
00169 BOOST_REQUIRE(argc >= 1);
00170
00171 torc::common::DirectoryTree directoryTree(argv[0]);
00172
00173
00174 std::string inDeviceName = "xc6slx4";
00175 boost::filesystem::path regressionPath = torc::common::DirectoryTree::getWorkingPath()
00176 / "torc" / "bitstream" / "regression";
00177 boost::filesystem::path referencePathOdd = regressionPath / (inDeviceName + ".partial.odd.bit");
00178 boost::filesystem::path referencePathEven = regressionPath / (inDeviceName + ".partial.even.bit");
00179
00180 {
00181
00182 std::fstream fileStream(referencePathOdd.string().c_str(), std::ios::binary | std::ios::in);
00183 std::cerr << "Trying to read: " << referencePathOdd << std::endl;
00184 BOOST_REQUIRE(fileStream.good());
00185 Spartan6 bitstream;
00186 bitstream.read(fileStream, false);
00187
00188 std::cout << bitstream << std::endl;
00189 }
00190
00191 {
00192
00193 std::fstream fileStream(referencePathEven.string().c_str(), std::ios::binary | std::ios::in);
00194 std::cerr << "Trying to read: " << referencePathEven << std::endl;
00195 BOOST_REQUIRE(fileStream.good());
00196 Spartan6 bitstream;
00197 bitstream.read(fileStream, false);
00198
00199 std::cout << bitstream << std::endl;
00200 }
00201
00202 }
00203
00204 BOOST_AUTO_TEST_SUITE_END()
00205
00206 }
00207 }