00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://torc-isi.svn.sourceforge.net/svnroot/torc-isi/branches/staging/0.9/src/torc/utils/ArchitectureBrowserUnitTest.cpp $ 00003 // $Id: ArchitectureBrowserUnitTest.cpp 10 2011-10-12 18:40:16Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Unit test for the ArchitectureBrowser class. 00018 00019 #include <sstream> 00020 #include <boost/test/unit_test.hpp> 00021 #include "torc/utils/ArchitectureBrowser.hpp" 00022 00023 00024 // for special testing only 00025 #include <iostream> 00026 #include <boost/regex.hpp> 00027 #include <boost/lexical_cast.hpp> 00028 #include <fstream> 00029 #include <set> 00030 00031 00032 namespace torc { 00033 00034 BOOST_AUTO_TEST_SUITE(utils) 00035 00036 /// \brief Unit test for the design diff function. 00037 BOOST_AUTO_TEST_CASE(ArchitectureBrowserUnitTest) { 00038 /* 00039 // setup a database for testing 00040 //architecture::DDB db("torc/devices/xc5vlx30"); 00041 architecture::DDB db("devices/xc5vlx30"); 00042 00043 ArchitectureBrowser ab(db); 00044 00045 ab.browse(); 00046 throw; 00047 00048 boost::regex tileLine("\\s*\\(tile\\s\\d+\\s\\d+\\s(\\S+)\\s(\\S+)\\s\\d+\\s*"); 00049 boost::regex wireLine("\\s*\\(wire\\s(\\S+)\\s(\\d+)\\s*"); 00050 boost::regex connLine("\\s*\\(conn\\s(\\S+)\\s(\\S+)\\)\\s*"); 00051 00052 std::ifstream xdlrcFile("xc5vlx30.xdlrc", std::ifstream::in); 00053 std::string inString; 00054 int z = 0; 00055 int numwires = 0; 00056 char buf[16384]; 00057 00058 std::string currentTile("emptyTile"); 00059 std::string currentTileType("emptyTileType"); 00060 std::string currentWire("emptyWire"); 00061 std::string tilewirestring("emptyTilewire"); 00062 architecture::Tilewire tw; 00063 architecture::Tilewire tw2; 00064 00065 std::set<architecture::Tilewire> allwires; 00066 std::map<architecture::Tilewire, int> currentsegment; 00067 00068 boost::smatch matches; 00069 00070 while (xdlrcFile.getline(buf, 16384)) { 00071 inString = buf; 00072 if (regex_match(inString, matches, tileLine)) { 00073 currentTile = matches[1]; 00074 currentTileType = matches[2]; 00075 std::cout << "TILE: " << currentTile << " " << currentTileType << std::endl; 00076 } 00077 else if (regex_match(inString, matches, wireLine)) { 00078 numwires++; 00079 00080 currentWire = matches[1]; 00081 int segsize = boost::lexical_cast<int>(matches[2]); 00082 00083 tilewirestring = currentWire + "@" + currentTile; 00084 tw = ab.stringToTilewire(tilewirestring); 00085 if (tw == architecture::Tilewire::sInvalid) { 00086 std::cout << "Recovered bad tilewire from " << tilewirestring << std::endl; 00087 throw; 00088 } 00089 00090 std::cout << "\tWIRE: " << tilewirestring << " (" 00091 << currentTileType << ") " << tw << std::endl; 00092 00093 if (allwires.find(tw) != allwires.end()) { 00094 std::cout << "WIRE ALREADY EXISTS! " << tw << " " << tilewirestring << std::endl; 00095 throw; 00096 } else { 00097 allwires.insert(tw); 00098 } 00099 00100 for (int i = 0; i < segsize; i++) { 00101 //std::cout << " READING CONN " << i << std::endl; 00102 xdlrcFile.getline(buf, 16384); 00103 inString = buf; 00104 if (regex_match(inString, matches, connLine)) { 00105 tilewirestring = matches[2] + "@" + matches[1]; 00106 //std::cout << " " << tilewirestring << std::endl; 00107 tw2 = ab.stringToTilewire(tilewirestring); 00108 //std::cout << " " << tw2 << std::endl; 00109 if (tw2 == architecture::Tilewire::sInvalid) { 00110 std::cout << "Bad tilewire as part fo segment " << tilewirestring << std::endl; 00111 throw; 00112 } 00113 std::cout << "\t\tCONN: " << tilewirestring << " " << tw2 << std::endl; 00114 00115 } else { 00116 std::cout << "ERROR, did not match a connection when expected " 00117 << segsize << " " << i << " " << inString << std::endl; 00118 throw; 00119 } 00120 } 00121 00122 } else { 00123 std::cout << "UNUSED: " << inString << std::endl; 00124 } 00125 z++; 00126 } 00127 std::cout << "Processed " << z << " lines" << std::endl; 00128 std::cout << "Found " << numwires << std::endl; 00129 std::cout << "DONE" << std::endl; 00130 00131 */ 00132 00133 00134 00135 } 00136 00137 BOOST_AUTO_TEST_SUITE_END() 00138 00139 } // namespace torc