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/Virtex2.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(Virtex2CrcUnitTest) {
00039 std::fstream fileStream("Virtex2UnitTest.reference.bit", std::ios::binary | std::ios::in);
00040 Virtex2 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(Virtex2UnitTest) {
00049
00050
00051
00052
00053 boost::uint32_t mask;
00054
00055 mask = Virtex2::ePacketMaskType + Virtex2::ePacketMaskOpcode
00056 + Virtex2::ePacketMaskType1Address + Virtex2::ePacketMaskType1Reserved
00057 + Virtex2::ePacketMaskType1Count;
00058 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00059
00060 mask = Virtex2::ePacketMaskType + Virtex2::ePacketMaskOpcode
00061 + Virtex2::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(Virtex2::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
00070 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[Virtex2::ePacketType1], "TYPE1");
00071 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[Virtex2::ePacketType2], "TYPE2");
00072 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
00073 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
00074 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
00075 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
00076 BOOST_CHECK_EQUAL(Virtex2::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
00077
00078
00079
00080 BOOST_CHECK_EQUAL(Virtex2::sOpcodeName[Virtex2::eOpcodeNOP], "NOP");
00081 BOOST_CHECK_EQUAL(Virtex2::sOpcodeName[Virtex2::eOpcodeRead], "READ");
00082 BOOST_CHECK_EQUAL(Virtex2::sOpcodeName[Virtex2::eOpcodeWrite], "WRITE");
00083 BOOST_CHECK_EQUAL(Virtex2::sOpcodeName[Virtex2::eOpcodeReserved], "RESERVED");
00084
00085
00086
00087 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterCRC], "CRC");
00088 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterFAR], "FAR");
00089 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterFDRI], "FDRI");
00090 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterFDRO], "FDRO");
00091 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterCMD], "CMD");
00092 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterCTL], "CTL");
00093 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterMASK], "MASK");
00094 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterSTAT], "STAT");
00095 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterLOUT], "LOUT");
00096 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterCOR], "COR");
00097 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterMFWR], "MFWR");
00098 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterFLR], "FLR");
00099 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterKEY], "KEY");
00100 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterCBC], "CBC");
00101 BOOST_CHECK_EQUAL(Virtex2::sRegisterName[Virtex2::eRegisterIDCODE], "IDCODE");
00102
00103
00104
00105 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandWCFG], "WCFG");
00106 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandMFWR], "MFWR");
00107 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandLFRM], "LFRM");
00108 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandRCFG], "RCFG");
00109 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandSTART], "START");
00110 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandRCAP], "RCAP");
00111 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandRCRC], "RCRC");
00112 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandAGHIGH], "AGHIGH");
00113 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandSWITCH], "SWITCH");
00114 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandGRESTORE], "GRESTORE");
00115 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandSHUTDOWN], "SHUTDOWN");
00116 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandGCAPTURE], "GCAPTURE");
00117 BOOST_CHECK_EQUAL(Virtex2::sCommandName[Virtex2::eCommandDESYNCH], "DESYNCH");
00118
00119
00120 boost::filesystem::path regressionPath
00121 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00122 boost::filesystem::path generatedPath = regressionPath / "Virtex2UnitTest.generated.bit";
00123 boost::filesystem::path referencePath = regressionPath / "Virtex2UnitTest.reference.bit";
00124
00125
00126 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00127 BOOST_REQUIRE(fileStream.good());
00128 Virtex2 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 testVirtex2Device(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00190
00191
00192 BOOST_AUTO_TEST_CASE(Virtex2FarUnitTest) {
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::getVirtex2Devices();
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 testVirtex2Device(device, torc::common::DirectoryTree::getWorkingPath());
00211 }
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 void testVirtex2Device(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00230
00231
00232 boost::filesystem::path debugBitstreamPath = inWorkingPath / "torc" / "bitstream" / "regression";
00233
00234 boost::filesystem::path referencePath = debugBitstreamPath / (inDeviceName + ".debug.bit");
00235 std::cerr << "TRYING TO FIND " << referencePath << std::endl;
00236
00237
00238 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00239 std::cerr << "Trying to read: " << referencePath << std::endl;
00240 BOOST_REQUIRE(fileStream.good());
00241 Virtex2 bitstream;
00242 bitstream.read(fileStream, false);
00243
00244
00245
00246
00247
00248
00249
00250 bitstream.initializeDeviceInfo(inDeviceName);
00251 bitstream.initializeFrameMaps();
00252
00253
00254 Virtex2::FrameAddressToIndex farRemaining = bitstream.mFrameAddressToIndex;
00255 Virtex2::FrameAddressToIndex farVisited;
00256 {
00257 bool first = true;
00258 Virtex2::const_iterator p = bitstream.begin();
00259 Virtex2::const_iterator e = bitstream.end();
00260 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00261 VirtexPacket::eOpcodeWrite, Virtex2::eRegisterLOUT, 1);
00262 while(p < e) {
00263 const VirtexPacket& packet = *p++;
00264 if(packet.getHeader() != header) continue;
00265 if(first) { first = false; continue; }
00266 Virtex2::FrameAddress far = packet[1];
00267
00268 farVisited[far] = 0;
00269 Virtex2::FrameAddressToIndex::iterator found = farRemaining.find(far);
00270 if(found != farRemaining.end()) {
00271 farRemaining.erase(found);
00272 } else {
00273 std::cerr << "missing " << far << " ";
00274 }
00275 }
00276 }
00277
00278 std::cout << "Device: " << inDeviceName << std::endl;
00279 std::cout << "Size of farRemaining: " << farRemaining.size() << std::endl;
00280 std::cout << "Size of farVisited: " << farVisited.size() << std::endl;
00281 BOOST_REQUIRE_EQUAL(bitstream.mFrameAddressToIndex.size(), farVisited.size());
00282 BOOST_REQUIRE_EQUAL(farRemaining.size(), 0u);
00283
00284 return;
00285 }
00286
00287
00288 void testVirtex2FullMapping(const boost::filesystem::path& inWorkingPath);
00289
00290
00291 BOOST_AUTO_TEST_CASE(Virtex2MapUnitTest) {
00292
00293 int& argc = boost::unit_test::framework::master_test_suite().argc;
00294 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00295
00296 BOOST_REQUIRE(argc >= 1);
00297
00298 torc::common::DirectoryTree directoryTree(argv[0]);
00299 testVirtex2FullMapping(torc::common::DirectoryTree::getWorkingPath());
00300 }
00301
00302
00303 void testVirtex2FullMapping(const boost::filesystem::path& inWorkingPath) {
00304
00305 boost::filesystem::path regressionPath
00306 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00307 boost::filesystem::path generatedPath = regressionPath / "Virtex2UnitTest.generatedFull.bit";
00308 boost::filesystem::path referencePath = regressionPath / "Virtex2UnitTest.reference.bit";
00309
00310
00311 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00312 BOOST_REQUIRE(fileStream.good());
00313
00314 Virtex2 bitstream;
00315 bitstream.read(fileStream, false);
00316
00317
00318 bitstream.initializeDeviceInfo("xc2v40");
00319 bitstream.initializeFrameMaps();
00320
00321
00322 bitstream.initializeFullFrameBlocks();
00323
00324
00325 uint32_t frameLength = bitstream.getFrameLength();
00326 typedef boost::shared_array<uint32_t> WordSharedArray;
00327 Virtex2::iterator p = bitstream.begin();
00328 Virtex2::iterator e = bitstream.end();
00329 while (p < e) {
00330 const VirtexPacket& packet = *p++;
00331 if (packet.isType2()) {
00332 WordSharedArray words = packet.getWords();
00333 uint32_t* ptr = words.get();
00334 for (uint32_t block = 0; block < 8; block++) {
00335 for (uint32_t frame = 0; frame < bitstream.mBlockFrameIndexBounds[block]; frame++) {
00336 VirtexFrameBlocks::word_t* words = const_cast<VirtexFrameBlocks::word_t*>(bitstream.mFrameBlocks.mBlock[block][frame]->getWords());
00337 for (uint32_t index = 0; index < frameLength; index++) {
00338 *ptr++ = words[index];
00339 }
00340 }
00341 }
00342 }
00343 }
00344
00345 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00346 BOOST_REQUIRE(outputStream.good());
00347 bitstream.write(outputStream);
00348 outputStream.flush();
00349 BOOST_REQUIRE(torc::common::fileContentsAreEqual(referencePath, generatedPath));
00350
00351 return;
00352 }
00353
00354
00355
00356
00357
00358
00359
00360 BOOST_AUTO_TEST_CASE(Virtex2GenerateUnitTest) {
00361
00362 Virtex2 bitstream;
00363 DeviceInfoHelper::buildFamilyDeviceInfo("Virtex2", "Virtex2DeviceInfo.template",
00364 "Virtex2DeviceInfo.cpp", torc::common::Devices::getVirtex2Devices(), bitstream);
00365
00366 }
00367 */
00368
00369 BOOST_AUTO_TEST_SUITE_END()
00370
00371 }
00372 }