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