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/VirtexE.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(VirtexEUnitTest) {
00040
00041
00042
00043
00044 boost::uint32_t mask;
00045
00046 mask = VirtexE::ePacketMaskType + VirtexE::ePacketMaskOpcode
00047 + VirtexE::ePacketMaskType1Address + VirtexE::ePacketMaskType1Reserved
00048 + VirtexE::ePacketMaskType1Count;
00049 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00050
00051 mask = VirtexE::ePacketMaskType + VirtexE::ePacketMaskOpcode
00052 + VirtexE::ePacketMaskType2Count;
00053 BOOST_CHECK_EQUAL(mask, 0xFFFFFFFFu);
00054
00055 mask = VirtexE::eFarMaskBlockType+ VirtexE::eFarMaskMajor +
00056 VirtexE::eFarMaskMinor;
00057 BOOST_CHECK_EQUAL(mask, 0x07FFFE00u);
00058
00059
00060
00061 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
00062 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[VirtexE::ePacketType1], "TYPE1");
00063 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[VirtexE::ePacketType2], "TYPE2");
00064 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
00065 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
00066 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
00067 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
00068 BOOST_CHECK_EQUAL(VirtexE::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
00069
00070
00071
00072 BOOST_CHECK_EQUAL(VirtexE::sOpcodeName[VirtexE::eOpcodeRead], "READ");
00073 BOOST_CHECK_EQUAL(VirtexE::sOpcodeName[VirtexE::eOpcodeWrite], "WRITE");
00074
00075
00076
00077 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterCRC], "CRC");
00078 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterFAR], "FAR");
00079 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterFDRI], "FDRI");
00080 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterFDRO], "FDRO");
00081 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterCMD], "CMD");
00082 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterCTL], "CTL");
00083 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterMASK], "MASK");
00084 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterSTAT], "STAT");
00085 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterLOUT], "LOUT");
00086 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterCOR], "COR");
00087 BOOST_CHECK_EQUAL(VirtexE::sRegisterName[VirtexE::eRegisterFLR], "FLR");
00088
00089
00090
00091 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandWCFG], "WCFG");
00092 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandLFRM], "LFRM");
00093 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandRCFG], "RCFG");
00094 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandSTART], "START");
00095 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandRCAP], "RCAP");
00096 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandRCRC], "RCRC");
00097 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandAGHIGH], "AGHIGH");
00098 BOOST_CHECK_EQUAL(VirtexE::sCommandName[VirtexE::eCommandSWITCH], "SWITCH");
00099
00100
00101 boost::filesystem::path regressionPath
00102 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00103 boost::filesystem::path generatedPath = regressionPath / "VirtexEUnitTest.generated.bit";
00104 boost::filesystem::path referencePath = regressionPath / "VirtexEUnitTest.reference.bit";
00105
00106
00107 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00108 BOOST_REQUIRE(fileStream.good());
00109 VirtexE bitstream;
00110 bitstream.read(fileStream, false);
00111
00112 std::cout << bitstream << std::endl;
00113
00114 std::string designName = bitstream.getDesignName();
00115 std::string deviceName = bitstream.getDeviceName();
00116 std::string designDate = bitstream.getDesignDate();
00117 std::string designTime = bitstream.getDesignTime();
00118 torc::common::DeviceDesignator deviceDesignator(deviceName);
00119 std::cout << "family of " << deviceName << " is " << deviceDesignator.getFamily() << std::endl;
00120
00121
00122 std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
00123 BOOST_REQUIRE(outputStream.good());
00124 bitstream.write(outputStream);
00125 outputStream.flush();
00126
00127
00128 BOOST_CHECK(torc::common::fileContentsAreEqual(generatedPath, referencePath));
00129 }
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 void testVirtexEDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath);
00171
00172
00173 BOOST_AUTO_TEST_CASE(VirtexEFarUnitTest) {
00174
00175
00176 int& argc = boost::unit_test::framework::master_test_suite().argc;
00177 char**& argv = boost::unit_test::framework::master_test_suite().argv;
00178
00179 BOOST_REQUIRE(argc >= 1);
00180
00181 torc::common::DirectoryTree directoryTree(argv[0]);
00182
00183
00184 const torc::common::DeviceVector& devices = torc::common::Devices::getVirtexEDevices();
00185 torc::common::DeviceVector::const_iterator dp = devices.begin();
00186 torc::common::DeviceVector::const_iterator de = devices.end();
00187 while(dp < de) {
00188 const std::string& device = *dp++;
00189 if(device.empty()) break;
00190
00191 testVirtexEDevice(device, torc::common::DirectoryTree::getWorkingPath());
00192 }
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 extern std::ostream& operator<< (std::ostream& os, const Virtex::FrameAddress& rhs);
00211
00212
00213
00214
00215 void testVirtexEDevice(const std::string& inDeviceName, const boost::filesystem::path& inWorkingPath) {
00216
00217
00218 boost::filesystem::path debugBitstreamPath = inWorkingPath / "torc" / "bitstream" / "regression";
00219
00220 boost::filesystem::path referencePath = debugBitstreamPath / (inDeviceName + ".debug.bit");
00221 std::cerr << "TRYING TO FIND " << referencePath << std::endl;
00222
00223
00224 std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
00225 std::cerr << "Trying to read: " << referencePath << std::endl;
00226 BOOST_REQUIRE(fileStream.good());
00227 VirtexE bitstream;
00228 bitstream.read(fileStream, false);
00229
00230
00231
00232
00233
00234
00235
00236 bitstream.initializeDeviceInfo(inDeviceName);
00237 bitstream.initializeFrameMaps();
00238
00239
00240 VirtexE::FrameAddressToIndex farRemaining = bitstream.mFrameAddressToIndex;
00241 VirtexE::FrameAddressToIndex farVisited;
00242 {
00243 bool first = true;
00244 VirtexE::const_iterator p = bitstream.begin();
00245 VirtexE::const_iterator e = bitstream.end();
00246 uint32_t header = VirtexPacket::makeHeader(VirtexPacket::ePacketType1,
00247 VirtexPacket::eOpcodeWrite, VirtexE::eRegisterLOUT, 1);
00248 while(p < e) {
00249 const VirtexPacket& packet = *p++;
00250 if(packet.getHeader() != header) continue;
00251 if(first) { first = false; continue; }
00252 VirtexE::FrameAddress far = packet[1];
00253
00254 farVisited[far] = 0;
00255 VirtexE::FrameAddressToIndex::iterator found = farRemaining.find(far);
00256 if(found != farRemaining.end()) {
00257 farRemaining.erase(found);
00258 } else {
00259 std::cerr << "missing " << far << " ";
00260 }
00261 }
00262 }
00263
00264 std::cout << "Device: " << inDeviceName << std::endl;
00265 std::cout << "Size of farRemaining: " << farRemaining.size() << std::endl;
00266 std::cout << "Size of farVisited: " << farVisited.size() << std::endl;
00267 BOOST_REQUIRE_EQUAL(bitstream.mFrameAddressToIndex.size(), farVisited.size());
00268 BOOST_REQUIRE_EQUAL(farRemaining.size(), 0u);
00269
00270 return;
00271 }
00272
00273 void testVirtexEFullMapping(const boost::filesystem::path& inWorkingPath);
00274
00275
00276 BOOST_AUTO_TEST_CASE(VirtexEMapUnitTest) {
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 testVirtexEFullMapping(torc::common::DirectoryTree::getWorkingPath());
00285 }
00286
00287
00288 void testVirtexEFullMapping(const boost::filesystem::path& inWorkingPath) {
00289
00290 boost::filesystem::path regressionPath
00291 = torc::common::DirectoryTree::getExecutablePath() / "regression";
00292 boost::filesystem::path generatedPath = regressionPath / "VirtexEUnitTest.generatedFull.bit";
00293 boost::filesystem::path referencePath = regressionPath / "VirtexEUnitTest.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 VirtexE bitstream;
00300 bitstream.read(fileStream, false);
00301
00302
00303 bitstream.initializeDeviceInfo("xcv50e");
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 VirtexE::iterator p = bitstream.begin();
00313 VirtexE::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
00343
00344 BOOST_AUTO_TEST_CASE(VirtexEGenerateUnitTest) {
00345
00346 VirtexE bitstream;
00347 DeviceInfoHelper::buildFamilyDeviceInfo("VirtexE", "VirtexEDeviceInfo.template",
00348 "VirtexEDeviceInfo.cpp", torc::common::Devices::getVirtexEDevices(), bitstream);
00349
00350 }
00351 */
00352
00353 BOOST_AUTO_TEST_SUITE_END()
00354
00355 }
00356 }