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/Virtex5.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 BOOST_AUTO_TEST_CASE(Virtex5CrcUnitTest) {
00039 std::fstream fileStream("Virtex5UnitTest.reference.bit", std::ios::binary | std::ios::in);
00040 Virtex5 bitstream;
00041 bitstream.read(fileStream, false);
00042 std::cout << bitstream << std::endl;
00043 bitstream.preflightPackets();
00044 BOOST_REQUIRE(true);
00045 }
00046
00047
00048 BOOST_AUTO_TEST_CASE(Virtex5UnitTest) {
00049
00050
00051
00052
00053 boost::uint32_t mask;
00054
00055 mask = Virtex5::ePacketMaskType + Virtex5::ePacketMaskOpcode
00056 + Virtex5::ePacketMaskType1Address + Virtex5::ePacketMaskType1Reserved
00057 + Virtex5::ePacketMaskType1Count;
00058 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00059
00060 mask = Virtex5::ePacketMaskType + Virtex5::ePacketMaskOpcode
00061 + Virtex5::ePacketMaskType2Count;
00062 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00063
00064 mask = Virtex5::eFarMaskBlockType + Virtex5::eFarMaskTopBottom + Virtex5::eFarMaskRow
00065 + Virtex5::eFarMaskMajor + Virtex5::eFarMaskMinor;
00066 BOOST_CHECK_EQUAL(mask, 0x00FFFFFFu);
00067
00068
00069
00070 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
00071 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[Virtex5::ePacketType1], "TYPE1");
00072 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[Virtex5::ePacketType2], "TYPE2");
00073 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
00074 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
00075 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
00076 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
00077 BOOST_CHECK_EQUAL(Virtex5::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
00078
00079
00080
00081 BOOST_CHECK_EQUAL(Virtex5::sOpcodeName[Virtex5::eOpcodeNOP], "NOP");
00082 BOOST_CHECK_EQUAL(Virtex5::sOpcodeName[Virtex5::eOpcodeRead], "READ");
00083 BOOST_CHECK_EQUAL(Virtex5::sOpcodeName[Virtex5::eOpcodeWrite], "WRITE");
00084 BOOST_CHECK_EQUAL(Virtex5::sOpcodeName[Virtex5::eOpcodeReserved], "RESERVED");
00085
00086
00087
00088 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCRC], "CRC");
00089 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterFAR], "FAR");
00090 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterFDRI], "FDRI");
00091 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterFDRO], "FDRO");
00092 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCMD], "CMD");
00093 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCTL0], "CTL0");
00094 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterMASK], "MASK");
00095 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterSTAT], "STAT");
00096 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterLOUT], "LOUT");
00097 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCOR0], "COR0");
00098 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterMFWR], "MFWR");
00099 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCBC], "CBC");
00100 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterIDCODE], "IDCODE");
00101 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterAXSS], "AXSS");
00102 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCOR1], "COR1");
00103 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCSOB], "CSOB");
00104 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterWBSTAR], "WBSTAR");
00105 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterTIMER], "TIMER");
00106 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterBOOTSTS], "BOOTSTS");
00107 BOOST_CHECK_EQUAL(Virtex5::sRegisterName[Virtex5::eRegisterCTL1], "CTL1");
00108
00109
00110
00111 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandNULL], "NULL");
00112 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandWCFG], "WCFG");
00113 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandMFW], "MFW");
00114 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandLFRM], "DGHIGH/LFRM");
00115 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandRCFG], "RCFG");
00116 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandSTART], "START");
00117 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandRCAP], "RCAP");
00118 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandRCRC], "RCRC");
00119 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandAGHIGH], "AGHIGH");
00120 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandSWITCH], "SWITCH");
00121 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandGRESTORE], "GRESTORE");
00122 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandSHUTDOWN], "SHUTDOWN");
00123 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandGCAPTURE], "GCAPTURE");
00124 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandDESYNCH], "DESYNCH");
00125 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandReserved], "Reserved");
00126 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandIPROG], "IPROG");
00127 BOOST_CHECK_EQUAL(Virtex5::sCommandName[Virtex5::eCommandLTIMER], "LTIMER");
00128
00129 uint32_t u1 = 0xffffffff & mask;
00130 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u1)), u1);
00131 uint32_t u2 = 0xffff0000 & mask;
00132 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u2)), u2);
00133 uint32_t u3 = 0xff00ff00 & mask;
00134 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u3)), u3);
00135 uint32_t u4 = 0xf0f0f0f0 & mask;
00136 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u4)), u4);
00137 uint32_t u5 = 0xcccccccc & mask;
00138 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u5)), u5);
00139 uint32_t u6 = 0xaaaaaaaa & mask;
00140 BOOST_CHECK_EQUAL(uint32_t(Virtex5::FrameAddress(u6)), u6);
00141
00142
00143 boost::filesystem::path regressionPath
00144 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00145 boost::filesystem::path generatedPath = regressionPath / "Virtex5UnitTest.generated.bit";
00146 boost::filesystem::path referencePath = regressionPath / "Virtex5UnitTest.reference.bit";
00147
00148
00149 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00150 BOOST_REQUIRE(fileStream.good());
00151 Virtex5 bitstream;
00152 bitstream.read(fileStream, false);
00153
00154 std::cout << bitstream << std::endl;
00155
00156 std::string designName = bitstream.getDesignName();
00157 std::string deviceName = bitstream.getDeviceName();
00158 std::string designDate = bitstream.getDesignDate();
00159 std::string designTime = bitstream.getDesignTime();
00160 torc::common::DeviceDesignator deviceDesignator(deviceName);
00161 std::cout << "family of " << deviceName << " is " << deviceDesignator.getFamily() << std::endl;
00162
00163
00164 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00165 BOOST_REQUIRE(outputStream.good());
00166 bitstream.write(outputStream);
00167 outputStream.flush();
00168
00169
00170 BOOST_CHECK(torc::common::fileContentsAreEqual(generatedPath, referencePath));
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 void testVirtex5Device(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00210
00211
00212 BOOST_AUTO_TEST_CASE(Virtex5FarUnitTest) {
00213
00214
00215 int& argc = boost::unit_test::framework::master_test_suite().argc;
00216 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00217
00218 BOOST_REQUIRE(argc >= 1);
00219
00220 torc::common::DirectoryTree directoryTree(argv[0]);
00221
00222
00223 const torc::common::DeviceVector& devices = torc::common::Devices::getVirtex5Devices();
00224 torc::common::DeviceVector::const_iterator dp = devices.begin();
00225 torc::common::DeviceVector::const_iterator de = devices.end();
00226 while(dp < de) {
00227 const std::string& device = *dp++;
00228 if(device.empty()) break;
00229
00230 testVirtex5Device(device, torc::common::DirectoryTree::getWorkingPath());
00231 }
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241 void testVirtex5Device(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00242
00243
00244 boost::filesystem::path debugBitstreamPath = inWorkingPath / "torc" / "bitstream" / "regression";
00245
00246 boost::filesystem::path referencePath = debugBitstreamPath / (inDeviceName + ".debug.bit");
00247 std::cerr << "TRYING TO FIND " << referencePath << std::endl;
00248
00249
00250 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00251 std::cerr << "Trying to read: " << referencePath << std::endl;
00252 BOOST_REQUIRE(fileStream.good());
00253 Virtex5 bitstream;
00254 bitstream.read(fileStream, false);
00255
00256
00257
00258
00259
00260
00261
00262 bitstream.initializeDeviceInfo(inDeviceName);
00263 bitstream.initializeFrameMaps();
00264
00265
00266 Virtex5::FrameAddressToIndex farRemaining = bitstream.mFrameAddressToIndex;
00267 Virtex5::FrameAddressToIndex farVisited;
00268 {
00269 bool first = true;
00270 Virtex5::const_iterator p = bitstream.begin();
00271 Virtex5::const_iterator e = bitstream.end();
00272 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00273 VirtexPacket::eOpcodeWrite, Virtex5::eRegisterLOUT, 1);
00274 while(p < e) {
00275 const VirtexPacket& packet = *p++;
00276 if(packet.getHeader() != header) continue;
00277 if(first) { first = false; continue; }
00278 Virtex5::FrameAddress far = packet[1];
00279 farVisited[far] = 0;
00280 Virtex5::FrameAddressToIndex::iterator found = farRemaining.find(far);
00281 if(found != farRemaining.end()) {
00282 farRemaining.erase(found);
00283 } else {
00284 std::cerr << "missing " << far << " ";
00285 }
00286 }
00287 }
00288
00289 std::cout << "Device: " << inDeviceName << std::endl;
00290 std::cout << "Size of farRemaining: " << farRemaining.size() << std::endl;
00291 std::cout << "Size of farVisited: " << farVisited.size() << std::endl;
00292 BOOST_REQUIRE_EQUAL(bitstream.mFrameAddressToIndex.size(), farVisited.size());
00293 BOOST_REQUIRE_EQUAL(farRemaining.size(), 0u);
00294
00295 return;
00296
00297
00298
00299 for(int half = 0; half < 2; half++) {
00300 for(uint32_t row = 0; row < 2; row++) {
00301 typedef std::map<uint32_t, uint32_t> ColumnMaxFrame;
00302 ColumnMaxFrame maxFrames[Virtex5::eFarBlockTypeCount];
00303 Virtex5::const_iterator p = bitstream.begin();
00304 Virtex5::const_iterator e = bitstream.end();
00305 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00306 VirtexPacket::eOpcodeWrite, Virtex5::eRegisterLOUT, 1);
00307 while(p < e) {
00308 const VirtexPacket& packet = *p++;
00309 if(packet.getHeader() != header) continue;
00310 Virtex5::FrameAddress far = packet[1];
00311
00312
00313 if(far.mTopBottom == half && far.mRow == row) {
00314
00315 ColumnMaxFrame::iterator i = maxFrames[far.mBlockType].find(far.mMajor);
00316 if(i == maxFrames[far.mBlockType].end()) {
00317 maxFrames[far.mBlockType][far.mMajor] = 0;
00318 } else {
00319 if(maxFrames[far.mBlockType][far.mMajor] < far.mMinor)
00320 maxFrames[far.mBlockType][far.mMajor] = far.mMinor;
00321 }
00322 }
00323 }
00324 std::cerr << std::endl;
00325 uint32_t frameCount = 0;
00326 for(uint32_t i = 0; i < Virtex5::eFarBlockTypeCount; i++) {
00327 Virtex5::EFarBlockType blockType = Virtex5::EFarBlockType(i);
00328 uint32_t majorCount = maxFrames[blockType].size();
00329 for(uint32_t major = 0; major < majorCount; major++) {
00330 frameCount += maxFrames[blockType][major] + 1;
00331 std::cerr << blockType << "(" << major << "): "
00332 << (maxFrames[blockType][major] + 1) << " (" << frameCount << ")"
00333 << std::endl;
00334 }
00335 }
00336 }
00337 }
00338
00339 }
00340
00341 void testVirtex5FullMapping(const boost::filesystem::path& inWorkingPath);
00342 void testVirtex5PartialMapping(const boost::filesystem::path& inWorkingPath);
00343
00344
00345 BOOST_AUTO_TEST_CASE(Virtex5MapUnitTest) {
00346
00347 int& argc = boost::unit_test::framework::master_test_suite().argc;
00348 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00349
00350 BOOST_REQUIRE(argc >= 1);
00351
00352 torc::common::DirectoryTree directoryTree(argv[0]);
00353 testVirtex5FullMapping(torc::common::DirectoryTree::getWorkingPath());
00354
00355 }
00356
00357
00358 void testVirtex5FullMapping(const boost::filesystem::path& inWorkingPath) {
00359
00360 boost::filesystem::path regressionPath
00361 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00362 boost::filesystem::path generatedPath = regressionPath / "Virtex5UnitTest.generatedFull.bit";
00363 boost::filesystem::path referencePath = regressionPath / "Virtex5UnitTest.reference.bit";
00364
00365
00366 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00367 BOOST_REQUIRE(fileStream.good());
00368
00369 Virtex5 bitstream;
00370 bitstream.read(fileStream, false);
00371
00372
00373 bitstream.initializeDeviceInfo("xc5vlx20t");
00374 bitstream.initializeFrameMaps();
00375
00376
00377 bitstream.initializeFullFrameBlocks();
00378
00379
00380 uint32_t frameLength = bitstream.getFrameLength();
00381 typedef boost::shared_array<uint32_t> WordSharedArray;
00382 Virtex5::iterator p = bitstream.begin();
00383 Virtex5::iterator e = bitstream.end();
00384 while (p < e) {
00385 const VirtexPacket& packet = *p++;
00386 if (packet.isType2()) {
00387 WordSharedArray words = packet.getWords();
00388 uint32_t* ptr = words.get();
00389 for (uint32_t block = 0; block < 8; block++) {
00390 for (uint32_t frame = 0; frame < bitstream.mBlockFrameIndexBounds[block]; frame++) {
00391 VirtexFrameBlocks::word_t* words = const_cast<VirtexFrameBlocks::word_t*>(bitstream.mFrameBlocks.mBlock[block][frame]->getWords());
00392 for (uint32_t index = 0; index < frameLength; index++) {
00393 *ptr++ = words[index];
00394 }
00395 }
00396 }
00397 }
00398 }
00399
00400 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00401 BOOST_REQUIRE(outputStream.good());
00402 bitstream.write(outputStream);
00403 outputStream.flush();
00404 BOOST_REQUIRE(torc::common::fileContentsAreEqual(referencePath, generatedPath));
00405
00406 return;
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 BOOST_AUTO_TEST_CASE(Virtex5GenerateUnitTest) {
00456
00457 Virtex5 bitstream;
00458 DeviceInfoHelper::buildFamilyDeviceInfo("Virtex5", "Virtex5DeviceInfo.template",
00459 "Virtex5DeviceInfo.cpp", torc::common::Devices::getVirtex5Devices(), bitstream);
00460
00461 }
00462 */
00463
00464 BOOST_AUTO_TEST_SUITE_END()
00465
00466 }
00467 }