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/Virtex2P.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(Virtex2PCrcUnitTest) {
00039 std::fstream fileStream("Virtex2PUnitTest.reference.bit", std::ios::binary | std::ios::in);
00040 Virtex2P 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(Virtex2PUnitTest) {
00049
00050
00051
00052
00053 boost::uint32_t mask;
00054
00055 mask = Virtex2P::ePacketMaskType + Virtex2P::ePacketMaskOpcode
00056 + Virtex2P::ePacketMaskType1Address + Virtex2P::ePacketMaskType1Reserved
00057 + Virtex2P::ePacketMaskType1Count;
00058 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00059
00060 mask = Virtex2P::ePacketMaskType + Virtex2P::ePacketMaskOpcode
00061 + Virtex2P::ePacketMaskType2Count;
00062 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00063
00064 mask = Virtex2::eFarMaskBlockType + Virtex2::eFarMaskMajor + Virtex2::eFarMaskMinor;
00065 BOOST_CHECK_EQUAL(mask, 0x07FFFE00u);
00066
00067
00068
00069 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
00070 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[Virtex2P::ePacketType1], "TYPE1");
00071 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[Virtex2P::ePacketType2], "TYPE2");
00072 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
00073 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
00074 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
00075 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
00076 BOOST_CHECK_EQUAL(Virtex2P::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
00077
00078
00079
00080 BOOST_CHECK_EQUAL(Virtex2P::sOpcodeName[Virtex2P::eOpcodeNOP], "NOP");
00081 BOOST_CHECK_EQUAL(Virtex2P::sOpcodeName[Virtex2P::eOpcodeRead], "READ");
00082 BOOST_CHECK_EQUAL(Virtex2P::sOpcodeName[Virtex2P::eOpcodeWrite], "WRITE");
00083 BOOST_CHECK_EQUAL(Virtex2P::sOpcodeName[Virtex2P::eOpcodeReserved], "RESERVED");
00084
00085
00086
00087 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterCRC], "CRC");
00088 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterFAR], "FAR");
00089 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterFDRI], "FDRI");
00090 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterFDRO], "FDRO");
00091 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterCMD], "CMD");
00092 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterCTL], "CTL");
00093 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterMASK], "MASK");
00094 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterSTAT], "STAT");
00095 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterLOUT], "LOUT");
00096 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterCOR], "COR");
00097 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterMFWR], "MFWR");
00098 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterFLR], "FLR");
00099 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterKEY], "KEY");
00100 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterCBC], "CBC");
00101 BOOST_CHECK_EQUAL(Virtex2P::sRegisterName[Virtex2P::eRegisterIDCODE], "IDCODE");
00102
00103
00104
00105 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandWCFG], "WCFG");
00106 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandMFWR], "MFWR");
00107 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandLFRM], "LFRM");
00108 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandRCFG], "RCFG");
00109 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandSTART], "START");
00110 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandRCAP], "RCAP");
00111 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandRCRC], "RCRC");
00112 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandAGHIGH], "AGHIGH");
00113 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandSWITCH], "SWITCH");
00114 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandGRESTORE], "GRESTORE");
00115 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandSHUTDOWN], "SHUTDOWN");
00116 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandGCAPTURE], "GCAPTURE");
00117 BOOST_CHECK_EQUAL(Virtex2P::sCommandName[Virtex2P::eCommandDESYNCH], "DESYNCH");
00118
00119
00120 boost::filesystem::path regressionPath
00121 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00122 boost::filesystem::path generatedPath = regressionPath / "Virtex2PUnitTest.generated.bit";
00123 boost::filesystem::path referencePath = regressionPath / "Virtex2PUnitTest.reference.bit";
00124
00125
00126 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00127 BOOST_REQUIRE(fileStream.good());
00128 Virtex2P bitstream;
00129 bitstream.read(fileStream, false);
00130
00131 std::cout << bitstream << std::endl;
00132
00133 std::string designName = bitstream.getDesignName();
00134 std::string deviceName = bitstream.getDeviceName();
00135 std::string designDate = bitstream.getDesignDate();
00136 std::string designTime = bitstream.getDesignTime();
00137 torc::common::DeviceDesignator deviceDesignator(deviceName);
00138 std::cout << "family of " << deviceName << " is " << deviceDesignator.getFamily() << std::endl;
00139
00140
00141 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00142 BOOST_REQUIRE(outputStream.good());
00143 bitstream.write(outputStream);
00144 outputStream.flush();
00145
00146
00147 BOOST_CHECK(torc::common::fileContentsAreEqual(generatedPath, referencePath));
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
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 void testVirtex2PDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00190
00191
00192 BOOST_AUTO_TEST_CASE(Virtex2PFarUnitTest) {
00193
00194
00195 int& argc = boost::unit_test::framework::master_test_suite().argc;
00196 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00197
00198 BOOST_REQUIRE(argc >= 1);
00199
00200 torc::common::DirectoryTree directoryTree(argv[0]);
00201
00202
00203 const torc::common::DeviceVector& devices = torc::common::Devices::getVirtex2PDevices();
00204 torc::common::DeviceVector::const_iterator dp = devices.begin();
00205 torc::common::DeviceVector::const_iterator de = devices.end();
00206 while(dp < de) {
00207 const std::string& device = *dp++;
00208 if(device.empty()) break;
00209
00210 testVirtex2PDevice(device, torc::common::DirectoryTree::getWorkingPath());
00211 }
00212 }
00213
00214 void testVirtex2PDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00215
00216
00217 boost::filesystem::path debugBitstreamPath = inWorkingPath / "torc" / "bitstream" / "regression";
00218
00219 boost::filesystem::path referencePath = debugBitstreamPath / (inDeviceName + ".debug.bit");
00220 std::cerr << "TRYING TO FIND " << referencePath << std::endl;
00221
00222
00223 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00224 std::cerr << "Trying to read: " << referencePath << std::endl;
00225 BOOST_REQUIRE(fileStream.good());
00226 Virtex2P bitstream;
00227 bitstream.read(fileStream, false);
00228
00229
00230
00231
00232
00233
00234
00235 bitstream.initializeDeviceInfo(inDeviceName);
00236 bitstream.initializeFrameMaps();
00237
00238
00239 Virtex2P::FrameAddressToIndex farRemaining = bitstream.mFrameAddressToIndex;
00240 Virtex2P::FrameAddressToIndex farVisited;
00241 {
00242 bool first = true;
00243 Virtex2P::const_iterator p = bitstream.begin();
00244 Virtex2P::const_iterator e = bitstream.end();
00245 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00246 VirtexPacket::eOpcodeWrite, Virtex2P::eRegisterLOUT, 1);
00247 while(p < e) {
00248 const VirtexPacket& packet = *p++;
00249 if(packet.getHeader() != header) continue;
00250 if(first) { first = false; continue; }
00251 Virtex2P::FrameAddress far = packet[1];
00252
00253 farVisited[far] = 0;
00254 Virtex2P::FrameAddressToIndex::iterator found = farRemaining.find(far);
00255 if(found != farRemaining.end()) {
00256 farRemaining.erase(found);
00257 } else {
00258 std::cerr << "missing " << far << " ";
00259 }
00260 }
00261 }
00262
00263 std::cout << "Device: " << inDeviceName << std::endl;
00264 std::cout << "Size of farRemaining: " << farRemaining.size() << std::endl;
00265 std::cout << "Size of farVisited: " << farVisited.size() << std::endl;
00266 BOOST_REQUIRE_EQUAL(bitstream.mFrameAddressToIndex.size(), farVisited.size());
00267 BOOST_REQUIRE_EQUAL(farRemaining.size(), 0u);
00268
00269 return;
00270
00271 }
00272
00273 void testVirtex2PFullMapping(const boost::filesystem::path& inWorkingPath);
00274
00275
00276 BOOST_AUTO_TEST_CASE(Virtex2PMapUnitTest) {
00277
00278 int& argc = boost::unit_test::framework::master_test_suite().argc;
00279 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00280
00281 BOOST_REQUIRE(argc >= 1);
00282
00283 torc::common::DirectoryTree directoryTree(argv[0]);
00284 testVirtex2PFullMapping(torc::common::DirectoryTree::getWorkingPath());
00285 }
00286
00287
00288 void testVirtex2PFullMapping(const boost::filesystem::path& inWorkingPath) {
00289
00290 boost::filesystem::path regressionPath
00291 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00292 boost::filesystem::path generatedPath = regressionPath / "Virtex2PUnitTest.generatedFull.bit";
00293 boost::filesystem::path referencePath = regressionPath / "Virtex2PUnitTest.reference.bit";
00294
00295
00296 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00297 BOOST_REQUIRE(fileStream.good());
00298
00299 Virtex2P bitstream;
00300 bitstream.read(fileStream, false);
00301
00302
00303 bitstream.initializeDeviceInfo("xc2vp20");
00304 bitstream.initializeFrameMaps();
00305
00306
00307 bitstream.initializeFullFrameBlocks();
00308
00309
00310 uint32_t frameLength = bitstream.getFrameLength();
00311 typedef boost::shared_array<uint32_t> WordSharedArray;
00312 Virtex2P::iterator p = bitstream.begin();
00313 Virtex2P::iterator e = bitstream.end();
00314 while (p < e) {
00315 const VirtexPacket& packet = *p++;
00316 if (packet.isType2()) {
00317 WordSharedArray words = packet.getWords();
00318 uint32_t* ptr = words.get();
00319 for (uint32_t block = 0; block < 8; block++) {
00320 for (uint32_t frame = 0; frame < bitstream.mBlockFrameIndexBounds[block]; frame++) {
00321 VirtexFrameBlocks::word_t* words = const_cast<VirtexFrameBlocks::word_t*>(bitstream.mFrameBlocks.mBlock[block][frame]->getWords());
00322 for (uint32_t index = 0; index < frameLength; index++) {
00323 *ptr++ = words[index];
00324 }
00325 }
00326 }
00327 }
00328 }
00329
00330 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00331 BOOST_REQUIRE(outputStream.good());
00332 bitstream.write(outputStream);
00333 outputStream.flush();
00334 BOOST_REQUIRE(torc::common::fileContentsAreEqual(referencePath, generatedPath));
00335
00336 return;
00337 }
00338
00339
00340
00341
00342 BOOST_AUTO_TEST_CASE(Virtex2PGenerateUnitTest) {
00343
00344 Virtex2P bitstream;
00345 DeviceInfoHelper::buildFamilyDeviceInfo("Virtex2P", "Virtex2PDeviceInfo.template",
00346 "Virtex2PDeviceInfo.cpp", torc::common::Devices::getVirtex2PDevices(), bitstream);
00347
00348 }
00349 */
00350
00351 BOOST_AUTO_TEST_SUITE_END()
00352
00353 }
00354 }