1x90ReadoutModes.cpp

Go to the documentation of this file.
00001 // Template for a test suite.
00002 
00003 #include <config.h>
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include <cppunit/Asserter.h>
00006 #include "Asserts.h"
00007 #include "CCAENV1x90.h"
00008 #include "DesignByContract.h"
00009 #include <vector>
00010 
00011 #ifdef HAVE_STD_NAMESPACE
00012 using namespace std;
00013 #endif
00014 
00015 
00016 using namespace DesignByContract;
00017 
00018 extern long ModuleBase;
00019 
00020 class ReadoutModes : public CppUnit::TestFixture {
00021   CPPUNIT_TEST_SUITE(ReadoutModes);
00022   CPPUNIT_TEST(ChipEncapsulateTest);
00023   CPPUNIT_TEST(MaxHitTest);
00024   CPPUNIT_TEST(ErrorEnableTest);
00025   CPPUNIT_TEST(L1CacheTest);
00026   CPPUNIT_TEST(IndividualEnableTest);
00027   CPPUNIT_TEST(EnableAllTest);
00028   CPPUNIT_TEST(MaskEnableTest);
00029   CPPUNIT_TEST(ChipEnableTest);
00030   CPPUNIT_TEST_SUITE_END();
00031 
00032 
00033 private:
00034   CCAENV1x90* m_pModule;
00035 
00036   bool isEnabled(unsigned int nChannel);
00037   void TestChip(unsigned int nChip); // Test 1 chip's chip enable.
00038 
00039 public:
00040   // Construct a module in powered up condition:
00041 
00042   void setUp() {
00043     m_pModule = new CCAENV1x90(1, 0, ModuleBase);
00044     m_pModule->Reset();
00045   }
00046   // Delete the module to prevent resource leaks.
00047 
00048   void tearDown() {
00049     delete m_pModule;
00050   }
00051 protected:
00052   void ChipEncapsulateTest();
00053   void MaxHitTest();
00054   void ErrorEnableTest();
00055   void L1CacheTest();
00056   void IndividualEnableTest();
00057   void EnableAllTest();
00058   void MaskEnableTest();
00059   void ChipEnableTest();
00060 };
00061 
00062 CPPUNIT_TEST_SUITE_REGISTRATION(ReadoutModes);
00063 
00064 // utility:
00065 
00066 bool 
00067 isSet(vector<unsigned short> masks,unsigned int bit)
00068 {
00069   unsigned int nMask = bit / 16; // 16 bits per mask.
00070   unsigned int nBit  = bit % 16;
00071 
00072   if(nMask >= masks.size()) {
00073     throw string("isSet - bit number too big");
00074   }
00075 
00076   return (masks[nMask] & (1 << nBit)) != 0;
00077 }
00078 
00079 void
00080 Set(vector<unsigned short>& masks, unsigned int bit)
00081 {
00082   unsigned int nMask = bit / 16;
00083   unsigned int nBit  = bit % 16;
00084 
00085   if(nMask >= masks.size()) {
00086     throw string("isSet - bit number too big");
00087   }
00088 
00089   masks[nMask] |= 1 << nBit;
00090   
00091 }
00092 void
00093 Clear(vector<unsigned short>& masks, unsigned int bit)
00094 {
00095   unsigned int nMask = bit / 16;
00096   unsigned int nBit  = bit % 16;
00097 
00098   if(nMask >= masks.size()) {
00099     throw string("isSet - bit number too big");
00100   }
00101   masks[nMask] &= ~(1 << nBit);
00102 
00103 }
00104 
00105 bool
00106 ReadoutModes::isEnabled(unsigned int nChannel)
00107 {
00108   vector<unsigned short> masks;
00109 
00110   m_pModule->GetChannelEnables(masks);
00111   return isSet(masks, nChannel);
00112 }
00113 
00114 // Test ability to turn on/off chip encapsulation:
00115 
00116 void
00117 ReadoutModes::ChipEncapsulateTest()
00118 {
00119   m_pModule->EnableTDCEncapsulation();
00120   ASSERT(m_pModule->isTDCEncapsulationOn());
00121 
00122   m_pModule->DisableTDCEncapsulation();
00123   ASSERT(!m_pModule->isTDCEncapsulationOn());
00124 }
00126 
00127 
00128 static const CCAENV1x90::HitMax hitvalues[] = {
00129   CCAENV1x90::HITS_0,
00130   CCAENV1x90::HITS_1,
00131   CCAENV1x90::HITS_2,
00132   CCAENV1x90::HITS_4,
00133   CCAENV1x90::HITS_8,
00134   CCAENV1x90::HITS_16,
00135   CCAENV1x90::HITS_32,
00136   CCAENV1x90::HITS_64,
00137   CCAENV1x90::HITS_128,
00138   CCAENV1x90::HITS_UNLIMITED };
00139 static const int nHitMaxes = sizeof(hitvalues)/sizeof(CCAENV1x90::HitMax);
00140 
00141 void
00142 ReadoutModes::MaxHitTest()
00143 {
00144   for(int i =0; i < nHitMaxes; i++) {
00145     m_pModule->SetMaxHitsPerEvent(hitvalues[i]);
00146     EQ(hitvalues[i], m_pModule->GetMaxHitsPerEvent());
00147   }
00148 }
00149 
00150 static const unsigned short ErrorPatterns [] = {
00151   CCAENV1x90::ERR_VERNIER,
00152   CCAENV1x90::ERR_SELECT,
00153   CCAENV1x90::ERR_L1PARITY,
00154   CCAENV1x90::ERR_TFIFOPARITY,
00155   CCAENV1x90::ERR_MATCHERROR,
00156   CCAENV1x90::ERR_RFIFOPARITY,
00157   CCAENV1x90::ERR_RDOSTATE,
00158   CCAENV1x90::ERR_SUPPARITY,
00159   CCAENV1x90::ERR_CTLPARITY,
00160   CCAENV1x90::ERR_JTAGPARITY,
00161   CCAENV1x90::ERR_VERNIER    | CCAENV1x90::ERR_L1PARITY    |
00162   CCAENV1x90::ERR_MATCHERROR | CCAENV1x90::ERR_RDOSTATE    |
00163   CCAENV1x90::ERR_CTLPARITY,
00164   CCAENV1x90::ERR_SELECT     | CCAENV1x90::ERR_TFIFOPARITY |
00165   CCAENV1x90::ERR_RFIFOPARITY| CCAENV1x90::ERR_SUPPARITY   |
00166   CCAENV1x90::ERR_JTAGPARITY
00167 };
00168 static const int nErrorPatterns = sizeof(ErrorPatterns)/sizeof(unsigned short);
00169 
00170 void
00171 ReadoutModes::ErrorEnableTest()
00172 {
00173   for(int i =0; i < nErrorPatterns; i++) {
00174     m_pModule->SetErrorEnables(ErrorPatterns[i]);
00175     EQ(ErrorPatterns[i], m_pModule->GetErrorEnables());
00176   }
00177 }
00178 // Test the L1 cache size control functions::
00179 //
00180 static const CCAENV1x90::L1Size l1sizes[] = {
00181   CCAENV1x90::L1_2wds,
00182   CCAENV1x90::L1_4wds,
00183   CCAENV1x90::L1_8wds,
00184   CCAENV1x90::L1_16wds,
00185   CCAENV1x90::L1_32wds,
00186   CCAENV1x90::L1_64wds,
00187   CCAENV1x90::L1_128wds,
00188   CCAENV1x90::L1_256wds };
00189 static const int nL1Sizes = sizeof(l1sizes)/sizeof(CCAENV1x90::L1Size);
00190 
00191 void
00192 ReadoutModes::L1CacheTest() 
00193 {
00194   for(int i = 0; i < nL1Sizes; i++) {
00195     m_pModule->SetL1Size(l1sizes[i]);
00196     EQ(l1sizes[i], m_pModule->GetL1Size());
00197   }
00198 }
00199 
00200 // Test individual channel enables.
00201 
00202 void
00203 ReadoutModes::IndividualEnableTest()
00204 {
00205   unsigned int nChannels = m_pModule->getChannelCount();
00206 
00207   // This runs O(n^2) in the channel count... hopefully not too bad for
00208   // the 128 channel models.
00209 
00210 
00211   m_pModule->DisableAllChannels(); // Nothing on now.
00212 
00213   // Enable one at a time:
00214 
00215   for(unsigned short i =0; i < nChannels; i++) {
00216     m_pModule->EnableChannel(i);
00217     for(unsigned short j = 0; j < nChannels; j++) {
00218       if (j == i) {
00219         ASSERT(isEnabled(j));
00220       } 
00221       else {
00222         ASSERT(!isEnabled(j));
00223       }
00224     }
00225     m_pModule->DisableChannel(i);
00226     for(unsigned short j = 0; j < nChannels; j++) {
00227       ASSERT(!isEnabled(i));
00228     }
00229   }
00230 
00231   // Now enable all one at a time and disable all one at a time.
00232 
00233   for(unsigned short i =0; i < nChannels; i++) {
00234     m_pModule->EnableChannel(i);
00235     for(unsigned short j = 0; j < nChannels; j++) {
00236       if(j <= i) {
00237         ASSERT(isEnabled(j));
00238       } 
00239       else {
00240         ASSERT(!isEnabled(j));
00241       }
00242     }
00243   }
00244   // Bad channels should throw.
00245 
00246   EXCEPTION(m_pModule->EnableChannel(nChannels),
00247             Require);
00248   
00249 }
00250 
00251 // Test global enable.
00252 
00253 void
00254 ReadoutModes::EnableAllTest()
00255 {
00256   m_pModule->DisableAllChannels();
00257   for(int i = 0; i < m_pModule->getChannelCount(); i++) {
00258     ASSERT(!isEnabled(i));
00259   }
00260   m_pModule->EnableAllChannels();
00261   for(int i = 0; i < m_pModule->getChannelCount(); i++) {
00262     ASSERT(isEnabled(i));
00263   }
00264 }
00265 // Test enable/disable via masks:
00266 
00267 void
00268 ReadoutModes::MaskEnableTest()
00269 {
00270   unsigned int nChannels = m_pModule->getChannelCount(); 
00271   vector<unsigned short> mask;
00272 
00273   // Create the channel mask vector... initially all zero.
00274 
00275   for(int i = 0; i < nChannels/16; i++) {
00276     mask.push_back(0);
00277   }
00278   // Now roll a bit through the mask:
00279   
00280   for(int i =0; i < nChannels; i++) {
00281     Set(mask, i);               // Enable the channel.
00282     m_pModule->SetChannelEnables(mask);
00283     for(int j = 0; j < nChannels; j++) {
00284       if(i == j) {
00285         ASSERT(isEnabled(j));
00286       }
00287       else {
00288         ASSERT(!isEnabled(j));
00289       }
00290     }
00291     Clear(mask,i);
00292   }
00293   // Now shift bits into the mask... the prior loops should
00294   // have left all bits in mask clear.
00295 
00296   for(int i=0; i < nChannels; i++) {
00297     Set(mask, i);
00298     m_pModule->SetChannelEnables(mask);
00299     for(int j=0; j < nChannels; j++) {
00300       if(j <= i) {
00301         ASSERT(isEnabled(j));
00302       }
00303       else {
00304         ASSERT(!isEnabled(j));
00305       }
00306     }
00307   }
00308   // All on:
00309 
00310   for(int i=0; i < mask.size(); i++) {
00311     mask[i] = 0xffff;
00312   }
00313   m_pModule->SetChannelEnables(mask);
00314   for(int i =0; i < nChannels; i++) {
00315     ASSERT(isEnabled(i));
00316   }
00317 
00318   // All off:
00319  
00320   for(int i = 0; i < mask.size(); i++) {
00321     mask[i] = 0;
00322   }
00323   m_pModule->SetChannelEnables(mask);
00324   for(int i = 0; i < nChannels; i++) {
00325     ASSERT(!isEnabled(i));
00326   }
00327 
00328   // Even bits on:
00329 
00330   for(int i = 0; i < nChannels; i++) {
00331     if (!(i%2)) {
00332       Set(mask, i);
00333     }
00334     else {
00335       Clear(mask, i);
00336     }
00337   }
00338   m_pModule->SetChannelEnables(mask);
00339 
00340   for(int i =0; i < nChannels; i++) {
00341     if (!(i%2)) {
00342       ASSERT(isEnabled(i));
00343     }
00344     else {
00345       ASSERT(!isEnabled(i));
00346     }
00347   }
00348 
00349   // Odd bits on:
00350 
00351   for(int i =0; i < nChannels; i++) {
00352     if(i%2) {
00353       Set(mask, i);
00354     }
00355     else {
00356       Clear(mask, i);
00357     }
00358   }
00359   m_pModule->SetChannelEnables(mask);
00360 
00361   for(int i = 0; i < nChannels; i++) {
00362     if(i%2) {
00363       ASSERT(isEnabled(i));
00364     }
00365     else {
00366       ASSERT(!isEnabled(i));
00367     }
00368   }
00369   
00370 }
00371 // Utility to check the enables for a single chip:
00372 
00373 void ReadoutModes::TestChip(unsigned int nChip)
00374 {
00375 
00376   // 1 bit at a time.
00377 
00378   for (int i =0; i < 32; i++) {
00379     unsigned int mask = 1 << i;         // Single channel enabled on the chip.
00380     m_pModule->SetChipEnables(nChip, mask);
00381     unsigned int outmask = m_pModule->GetChipEnables(nChip);
00382     EQ(mask, outmask);
00383   }
00384   // Shifting bits in:
00385 
00386   unsigned int mask = 0;
00387   for(int i =0; i < 32; i++) {
00388     mask |= 1 << i;             // Add a channel...
00389     m_pModule->SetChipEnables(nChip, mask);
00390     unsigned int outmask = m_pModule->GetChipEnables(nChip);
00391     EQ(mask, outmask);
00392   }
00393 
00394   // Even channels:
00395 
00396   m_pModule->SetChipEnables(nChip, 0x5a5a5a5a);
00397   EQ(0x5a5a5a5aU, m_pModule->GetChipEnables(nChip));
00398   
00399   // Odd channels.
00400 
00401   m_pModule->SetChipEnables(nChip, 0xa5a5a5a5);
00402   EQ(0xa5a5a5a5U, m_pModule->GetChipEnables(nChip));
00403 
00404   // All on:
00405 
00406   m_pModule->SetChipEnables(nChip, 0xffffffff);
00407   EQ(0xffffffffU, m_pModule->GetChipEnables(nChip));
00408 
00409   // All off:
00410 
00411   m_pModule->SetChipEnables(nChip, 0);
00412   EQ(0U, m_pModule->GetChipEnables(nChip));
00413      
00414 }
00415 //  Test ability to control enables a chip at a time.
00416 //  Note that regardless of the number of channels on the board,
00417 //  Each chip has 32 enables... in the 1290, some are ganged
00418 //  together for 25ps mode, but in 100ps mode, they are not
00419 //  only some are used.  We'll put the  module into 100ps mode
00420 //  and then treat it as if it's an 1190 for the purposes of this test.
00421 //
00422 void
00423 ReadoutModes::ChipEnableTest()
00424 {
00425   unsigned int nChips  = m_pModule->getChipCount();
00426   m_pModule->SetIndividualLSB(CCAENV1x90::Res_100ps);
00427 
00428   for(int i = 0; i < nChips; i++) {
00429     TestChip(i);
00430   }
00431 }

Generated on Wed Sep 17 08:38:09 2008 for NSCL Device support. by  doxygen 1.5.1