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/Virtex.hpp"
00021 #include "torc/common/DirectoryTree.hpp"
00022 #include "torc/common/Devices.hpp"
00023 #include "torc/architecture/DDB.hpp"
00024 #include "torc/common/DeviceDesignator.hpp"
00025 #include "torc/bitstream/OutputStreamHelpers.hpp"
00026 #include "torc/bitstream/build/DeviceInfoHelper.hpp"
00027 #include "torc/common/TestHelpers.hpp"
00028 #include <fstream>
00029 #include <iostream>
00030 #include <boost/filesystem.hpp>
00031
00032 namespace torc {
00033 namespace bitstream {
00034
00035 BOOST_AUTO_TEST_SUITE(bitstream)
00036
00037
00038
00039 BOOST_AUTO_TEST_CASE(VirtexUnitTest) {
00040
00041
00042
00043
00044 boost::uint32_t mask;
00045
00046 mask = Virtex::ePacketMaskType + Virtex::ePacketMaskOpcode
00047 + Virtex::ePacketMaskType1Address + Virtex::ePacketMaskType1Reserved
00048 + Virtex::ePacketMaskType1Count;
00049 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00050
00051 mask = Virtex::ePacketMaskType + Virtex::ePacketMaskOpcode
00052 + Virtex::ePacketMaskType2Count;
00053 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00054
00055 mask = Virtex::eFarMaskBlockType+ Virtex::eFarMaskMajor +
00056 Virtex::eFarMaskMinor;
00057 BOOST_CHECK_EQUAL(mask, 0x07FFFE00u);
00058
00059
00060
00061 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
00062 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[Virtex::ePacketType1], "TYPE1");
00063 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[Virtex::ePacketType2], "TYPE2");
00064 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
00065 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
00066 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
00067 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
00068 BOOST_CHECK_EQUAL(Virtex::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
00069
00070
00071
00072 BOOST_CHECK_EQUAL(Virtex::sOpcodeName[Virtex::eOpcodeRead], "READ");
00073 BOOST_CHECK_EQUAL(Virtex::sOpcodeName[Virtex::eOpcodeWrite], "WRITE");
00074
00075
00076
00077 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterCRC], "CRC");
00078 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterFAR], "FAR");
00079 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterFDRI], "FDRI");
00080 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterFDRO], "FDRO");
00081 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterCMD], "CMD");
00082 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterCTL], "CTL");
00083 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterMASK], "MASK");
00084 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterSTAT], "STAT");
00085 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterLOUT], "LOUT");
00086 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterCOR], "COR");
00087 BOOST_CHECK_EQUAL(Virtex::sRegisterName[Virtex::eRegisterFLR], "FLR");
00088
00089
00090
00091 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandWCFG], "WCFG");
00092 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandLFRM], "LFRM");
00093 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandRCFG], "RCFG");
00094 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandSTART], "START");
00095 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandRCAP], "RCAP");
00096 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandRCRC], "RCRC");
00097 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandAGHIGH], "AGHIGH");
00098 BOOST_CHECK_EQUAL(Virtex::sCommandName[Virtex::eCommandSWITCH], "SWITCH");
00099
00100
00101
00102 boost::filesystem::path regressionPath
00103 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00104 boost::filesystem::path generatedPath = regressionPath / "VirtexUnitTest.generated.bit";
00105 boost::filesystem::path referencePath = regressionPath / "VirtexUnitTest.reference.bit";
00106
00107
00108 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00109 BOOST_REQUIRE(fileStream.good());
00110 Virtex bitstream;
00111 bitstream.read(fileStream, false);
00112
00113 std::cout << bitstream << std::endl;
00114
00115 std::string designName = bitstream.getDesignName();
00116 std::string deviceName = bitstream.getDeviceName();
00117 std::string designDate = bitstream.getDesignDate();
00118 std::string designTime = bitstream.getDesignTime();
00119 torc::common::DeviceDesignator deviceDesignator(deviceName);
00120 std::cout << "family of " << deviceName << " is " << deviceDesignator.getFamily() << std::endl;
00121
00122
00123 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00124 BOOST_REQUIRE(outputStream.good());
00125 bitstream.write(outputStream);
00126 outputStream.flush();
00127
00128
00129 BOOST_CHECK(torc::common::fileContentsAreEqual(generatedPath, referencePath));
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 void testVirtexDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00172
00173
00174 BOOST_AUTO_TEST_CASE(VirtexFarUnitTest) {
00175
00176
00177 int& argc = boost::unit_test::framework::master_test_suite().argc;
00178 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00179
00180 BOOST_REQUIRE(argc >= 1);
00181
00182 torc::common::DirectoryTree directoryTree(argv[0]);
00183
00184
00185 const torc::common::DeviceVector& devices = torc::common::Devices::getVirtexDevices();
00186 torc::common::DeviceVector::const_iterator dp = devices.begin();
00187 torc::common::DeviceVector::const_iterator de = devices.end();
00188 while(dp < de) {
00189 const std::string& device = *dp++;
00190 if(device.empty()) break;
00191
00192 testVirtexDevice(device, torc::common::DirectoryTree::getWorkingPath());
00193 }
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 std::ostream& operator<< (std::ostream& os, const Virtex::FrameAddress& rhs);
00212 std::ostream& operator<< (std::ostream& os, const Virtex::FrameAddress& rhs) {
00213 return os << rhs.mBlockType << "(" << rhs.mMajor << "." << rhs.mMinor << ")";
00214 }
00215
00216 void testVirtexDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00217
00218
00219 boost::filesystem::path debugBitstreamPath = inWorkingPath / "torc" / "bitstream" / "regression";
00220
00221 boost::filesystem::path referencePath = debugBitstreamPath / (inDeviceName + ".debug.bit");
00222 std::cerr << "TRYING TO FIND " << referencePath << std::endl;
00223
00224
00225 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00226 std::cerr << "Trying to read: " << referencePath << std::endl;
00227 BOOST_REQUIRE(fileStream.good());
00228 Virtex bitstream;
00229 bitstream.read(fileStream, false);
00230
00231
00232
00233
00234
00235
00236
00237 bitstream.initializeDeviceInfo(inDeviceName);
00238 bitstream.initializeFrameMaps();
00239
00240
00241 Virtex::FrameAddressToIndex farRemaining = bitstream.mFrameAddressToIndex;
00242 Virtex::FrameAddressToIndex farVisited;
00243 {
00244 bool first = true;
00245 Virtex::const_iterator p = bitstream.begin();
00246 Virtex::const_iterator e = bitstream.end();
00247 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00248 VirtexPacket::eOpcodeWrite, Virtex::eRegisterLOUT, 1);
00249 while(p < e) {
00250 const VirtexPacket& packet = *p++;
00251 if(packet.getHeader() != header) continue;
00252 if(first) { first = false; continue; }
00253 Virtex::FrameAddress far = packet[1];
00254
00255 farVisited[far] = 0;
00256 Virtex::FrameAddressToIndex::iterator found = farRemaining.find(far);
00257 if(found != farRemaining.end()) {
00258 farRemaining.erase(found);
00259 } else {
00260 std::cerr << "missing " << far << " ";
00261 }
00262 }
00263 }
00264
00265 std::cout << "Device: " << inDeviceName << std::endl;
00266 std::cout << "Size of farRemaining: " << farRemaining.size() << std::endl;
00267 std::cout << "Size of farVisited: " << farVisited.size() << std::endl;
00268 BOOST_REQUIRE_EQUAL(bitstream.mFrameAddressToIndex.size(), farVisited.size());
00269 BOOST_REQUIRE_EQUAL(farRemaining.size(), 0u);
00270
00271 return;
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 }
00317
00318 void testVirtexFullMapping(const boost::filesystem::path& inWorkingPath);
00319
00320
00321 BOOST_AUTO_TEST_CASE(VirtexMapUnitTest) {
00322
00323 int& argc = boost::unit_test::framework::master_test_suite().argc;
00324 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00325
00326 BOOST_REQUIRE(argc >= 1);
00327
00328 torc::common::DirectoryTree directoryTree(argv[0]);
00329 testVirtexFullMapping(torc::common::DirectoryTree::getWorkingPath());
00330 }
00331
00332
00333 void testVirtexFullMapping(const boost::filesystem::path& inWorkingPath) {
00334
00335 boost::filesystem::path regressionPath
00336 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00337 boost::filesystem::path generatedPath = regressionPath / "VirtexUnitTest.generatedFull.bit";
00338 boost::filesystem::path referencePath = regressionPath / "VirtexUnitTest.reference.bit";
00339
00340
00341 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00342 BOOST_REQUIRE(fileStream.good());
00343
00344 Virtex bitstream;
00345 bitstream.read(fileStream, false);
00346
00347
00348 bitstream.initializeDeviceInfo("xcv50");
00349 bitstream.initializeFrameMaps();
00350
00351
00352 bitstream.initializeFullFrameBlocks();
00353
00354
00355 uint32_t frameLength = bitstream.getFrameLength();
00356 typedef boost::shared_array<uint32_t> WordSharedArray;
00357 Virtex::iterator p = bitstream.begin();
00358 Virtex::iterator e = bitstream.end();
00359 while (p < e) {
00360 const VirtexPacket& packet = *p++;
00361 if (packet.isType2()) {
00362 WordSharedArray words = packet.getWords();
00363 uint32_t* ptr = words.get();
00364 for (uint32_t block = 0; block < 8; block++) {
00365 for (uint32_t frame = 0; frame < bitstream.mBlockFrameIndexBounds[block]; frame++) {
00366 VirtexFrameBlocks::word_t* words = const_cast<VirtexFrameBlocks::word_t*>(bitstream.mFrameBlocks.mBlock[block][frame]->getWords());
00367 for (uint32_t index = 0; index < frameLength; index++) {
00368 *ptr++ = words[index];
00369 }
00370 }
00371 }
00372 }
00373 }
00374
00375 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00376 BOOST_REQUIRE(outputStream.good());
00377 bitstream.write(outputStream);
00378 outputStream.flush();
00379 BOOST_REQUIRE(torc::common::fileContentsAreEqual(referencePath, generatedPath));
00380
00381 return;
00382 }
00383
00384
00385
00386
00387
00388
00389 BOOST_AUTO_TEST_CASE(VirtexGenerateUnitTest) {
00390
00391 Virtex bitstream;
00392 DeviceInfoHelper::buildFamilyDeviceInfo("Virtex", "VirtexDeviceInfo.template",
00393 "VirtexDeviceInfo.cpp", torc::common::Devices::getVirtexDevices(), bitstream);
00394
00395 }
00396 */
00397
00398 BOOST_AUTO_TEST_SUITE_END()
00399
00400 }
00401 }