torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Spartan6UnitTest.cpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 /// \file
17 /// \brief Unit test for the Spartan6 class.
18 
19 #include <boost/test/unit_test.hpp>
26 #include <fstream>
27 #include <iostream>
28 
29 namespace torc {
30 namespace bitstream {
31 
32 BOOST_AUTO_TEST_SUITE(bitstream)
33 
34 /// \brief Unit test for the Spartan6 class.
35 BOOST_AUTO_TEST_CASE(Spartan6UnitTest) {
36 
37  // enums tested:
38  // EPacket
39  // EFar
40  boost::uint16_t mask;
41  // type 1 packet subfield masks
44  BOOST_CHECK_EQUAL(mask, 0xFFFFu);
45  // type 2 packet subfield masks
48  BOOST_CHECK_EQUAL(mask, 0xFFE0u);
49  // frame major address register subfield masks
51  BOOST_CHECK_EQUAL(mask, 0xFFFFu);
52  // frame minor address register subfield masks
54  BOOST_CHECK_EQUAL(mask, 0xC1FFu);
55 
56  // members tested:
57  // Spartan6::sPacketTypeName and EPacketTypeName
58  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[0], "[UNKNOWN TYPE 0]");
59  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[Spartan6::ePacketType1], "TYPE1");
60  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[Spartan6::ePacketType2], "TYPE2");
61  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[3], "[UNKNOWN TYPE 3]");
62  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[4], "[UNKNOWN TYPE 4]");
63  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[5], "[UNKNOWN TYPE 5]");
64  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[6], "[UNKNOWN TYPE 6]");
65  BOOST_CHECK_EQUAL(Spartan6::sPacketTypeName[7], "[UNKNOWN TYPE 7]");
66 
67  // members tested:
68  // Spartan6::sOpcodeName and EOpcode
69  BOOST_CHECK_EQUAL(Spartan6::sOpcodeName[Spartan6::eOpcodeNOP], "NOP");
70  BOOST_CHECK_EQUAL(Spartan6::sOpcodeName[Spartan6::eOpcodeRead], "READ");
71  BOOST_CHECK_EQUAL(Spartan6::sOpcodeName[Spartan6::eOpcodeWrite], "WRITE");
72  BOOST_CHECK_EQUAL(Spartan6::sOpcodeName[Spartan6::eOpcodeReserved], "RESERVED");
73 
74  // members tested:
75  // Spartan6::sRegisterName and ERegister
76  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCRC], "CRC");
77  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterFARMAJ], "FARMAJ");
78  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterFARMIN], "FARMIN");
79  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterFDRI], "FDRI");
80  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterFDRO], "FDRO");
81  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCMD], "CMD");
82  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCTL], "CTL");
83  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterMASK], "MASK");
84  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterSTAT], "STAT");
85  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterLOUT], "LOUT");
86  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCOR1], "COR1");
87  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCOR2], "COR2");
88  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterPWRDN_REG],"PWRDN_REG");
89  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterFLR], "FLR");
90  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterIDCODE], "IDCODE");
91  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCWDT], "CWDT");
92  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterHC_OPT_REG],"HC_OPT_REG");
93  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCSBO], "CSBO");
94  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterGENERAL1], "GENERAL1");
95  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterGENERAL2], "GENERAL2");
96  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterGENERAL3], "GENERAL3");
97  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterGENERAL4], "GENERAL4");
98  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterGENERAL5], "GENERAL5");
99  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterMODE_REG], "MODE_REG");
100  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterPU_GWE], "PU_GWE");
101  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterPU_GTS], "PU_GTS");
102  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterMFWR], "MFWR");
103  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCCLK_FREQ],"CCLK_FREQ");
104  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterSEU_OPT], "SEU_OPT");
105  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterEXP_SIGN], "EXP_SIGN");
106  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterRDBK_SIGN],"RDBK_SIGN");
107  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterBOOSTS], "BOOSTS");
108  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterEYE_MASK], "EYE_MASK");
109  BOOST_CHECK_EQUAL(Spartan6::sRegisterName[Spartan6::eRegisterCBC_REG], "CBC_REG");
110 
111  // members tested:
112  // Spartan6::sCommandName and ECommand
113  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandNULL], "NULL");
114  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandWCFG], "WCFG");
115  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandMFW], "MFW");
116  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandLFRM], "LFRM");
117  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandRCFG], "RCFG");
118  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandSTART], "START");
119  BOOST_CHECK_EQUAL(Spartan6::sCommandName[6], "[UNKNOWN COMMAND 6]");
120  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandRCRC], "RCRC");
121  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandAGHIGH], "AGHIGH");
122  BOOST_CHECK_EQUAL(Spartan6::sCommandName[9], "[UNKNOWN COMMAND 9]");
123  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandGRESTORE], "GRESTORE");
124  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandSHUTDOWN], "SHUTDOWN");
125  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandDESYNC], "DESYNC");
126  BOOST_CHECK_EQUAL(Spartan6::sCommandName[Spartan6::eCommandIPROG], "IPROG");
127 
128  // build the file paths
130  / "torc" / "bitstream" / "Spartan6UnitTest.reference.bit";
132  / "regression" / "Spartan6UnitTest.generated.bit";
133 
134  // read the bitstream
135  std::fstream fileStream(referencePath.string().c_str(), std::ios::binary | std::ios::in);
136  //std::fstream fileStream(generatedPath.string().c_str(), std::ios::binary | std::ios::in);
137  BOOST_REQUIRE(fileStream.good());
138  Spartan6 bitstream;
139  bitstream.read(fileStream, false);
140  // write the bitstream digest to the console
141  //std::cout << bitstream << std::endl;
142 
143  std::string designName = bitstream.getDesignName();
144  std::string deviceName = bitstream.getDeviceName();
145  std::string designDate = bitstream.getDesignDate();
146  std::string designTime = bitstream.getDesignTime();
147  torc::common::DeviceDesignator deviceDesignator(deviceName);
148  std::cout << "family of " << deviceName << " is " << deviceDesignator.getFamily() << std::endl;
149 
150  // write the bitstream back out
151  std::fstream outputStream(generatedPath.string().c_str(), std::ios::binary | std::ios::out);
152  BOOST_REQUIRE(outputStream.good());
153  bitstream.write(outputStream);
154  outputStream.flush();
155 
156  // compare the reference and generated XDL
157  BOOST_CHECK(torc::common::fileContentsAreEqual(generatedPath, referencePath));
158 }
159 
160 BOOST_AUTO_TEST_SUITE_END()
161 
162 } // namespace bitstream
163 } // namespace torc
Header for torc::bitstream output stream helpers.
static const char * sCommandName[eCommandCount]
Configuration command names.
Definition: Spartan6.hpp:94
static const char * sOpcodeName[eOpcodeCount]
Packet opcode names.
Definition: Spartan6.hpp:90
Encapsulation of a device designator and its constituent elements.
const EFamily & getFamily(void) const
Returns the device family.
Header for the DirectoryTree class.
Header for the DeviceDesignator class.
std::string string
Header for Boost.Test helper functions.
Header for the Spartan6 class.
static const char * sRegisterName[eRegisterCount]
Configuration register names.
Definition: Spartan6.hpp:92
static const char * sPacketTypeName[ePacketTypeCount]
Packet type names.
Definition: Spartan6.hpp:88
boost::filesystem::path path
Spartan6 bitstream.
Definition: Spartan6.hpp:31
Header for the DDB class.
bool fileContentsAreEqual(const boost::filesystem::path &inA, const boost::filesystem::path &inB)
Compare the raw contents of two files to determine whether they are identical.
BOOST_AUTO_TEST_CASE(hexCharacterToDec)
virtual void read(std::istream &inStream, bool inCleanDateAndTime=true)
Read the bitstream header and packets from a stream.
static const boost::filesystem::path & getExecutablePath(void)
Returns the absolute path to the executable directory.