1x90ReadTests.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 "CCAENV1x90Data.h"
00009 #include "DesignByContract.h"
00010 #include <unistd.h>
00011 
00012 #ifdef HAVE_STD_NAMESPACE
00013 using namespace std;
00014 #endif
00015 
00016 
00017 using namespace CCAENV1x90Data;
00018 
00019 extern long ModuleBase;
00020 
00021 class ReadTests : public CppUnit::TestFixture {
00022   CPPUNIT_TEST_SUITE(ReadTests);
00023   CPPUNIT_TEST(FIFOTest);
00024   CPPUNIT_TEST(TestReadNoHeaders);
00025   CPPUNIT_TEST(TestReadHeaders);
00026   CPPUNIT_TEST_SUITE_END();
00027 
00028 
00029 private:
00030   CCAENV1x90* m_pModule;
00031 
00032 public:
00033   // Construct a module in powered up condition:
00034 
00035   void setUp() {
00036     m_pModule = new CCAENV1x90(1, 0, ModuleBase);
00037     m_pModule->Reset();
00038   
00039   }
00040   // Delete the module to prevent resource leaks.
00041 
00042   void tearDown() {
00043     delete m_pModule;
00044   }
00045 protected:
00046   void FIFOTest();
00047   void TestReadNoHeaders();
00048   void TestReadHeaders();
00049 };
00050 
00051 CPPUNIT_TEST_SUITE_REGISTRATION(ReadTests);
00052 
00053 /*
00054 
00055 Test procedure:
00056 
00057 1.      Limit event size to 1 hit.
00058 2.      Set triggger matching mode
00059 3.      Set test mode with appropriate data word.\
00060 4.      Do 16 SW triggers.
00061 5.      Check FIFO for correctness
00062 */
00063 
00064 void 
00065 ReadTests::FIFOTest()
00066 {
00067   m_pModule->SetMaxHitsPerEvent(CCAENV1x90::HITS_1);
00068   m_pModule->TriggerMatchMode();
00069   m_pModule->EnableTestMode( 0x123456U ); // Nice easy pattern.
00070 
00071   for(int i =0; i < 16; i++) {
00072     m_pModule->Trigger();       // Trigger the module for test data.
00073     usleep(100);
00074   }
00075   /*
00076     1.  FIFO status shows fifo ready , fifo not full.
00077     2.  FIFO count shows 16 events stored.
00078     3.  Event fifo can be read 16 times, 
00079         and event count field will increment between each read.
00080     4.  After 16 reads, fifo ready is clear, fifo count is zero.
00081    */
00082   ASSERT(m_pModule->isEventFIFOReady());
00083   ASSERT(!m_pModule->isEventFIFOFull());
00084 
00085   EQMSG("FIFO COunt", static_cast<unsigned short>(16), 
00086                       m_pModule->EventFIFOCount());
00087 
00088   // Get the first value:
00089 
00090   unsigned long  fifo       = m_pModule->ReadEventFIFO();
00091   unsigned short lastevent  = m_pModule->FIFOEventNumber(fifo);
00092   for(int i = 0; i < 15; i++) { // only 15 entries left now:
00093     fifo = m_pModule->ReadEventFIFO();
00094     EQMSG("Event Number", ++lastevent, m_pModule->FIFOEventNumber(fifo));
00095   }
00096   ASSERT(!m_pModule->isEventFIFOReady());
00097 }
00098 // See if we can read an event in test mode.
00099 
00100 static const CCAENV1x90::HitMax hitcode[] = {
00101   CCAENV1x90::HITS_1,
00102   CCAENV1x90::HITS_2,
00103   CCAENV1x90::HITS_4,
00104   CCAENV1x90::HITS_8,
00105   CCAENV1x90::HITS_16,
00106   CCAENV1x90::HITS_32,
00107   CCAENV1x90::HITS_64,
00108   CCAENV1x90::HITS_128
00109 };
00110 static const int hitwords[] = {
00111   1,2,4,8,16,32,64,128
00112 };
00113 
00114 static const int nHitvalues = sizeof(hitwords)/sizeof(int);
00115 
00116 void 
00117 ReadTests::TestReadNoHeaders()
00118 {
00119   unsigned short nChips = m_pModule->getChipCount();
00120 
00121   m_pModule->TriggerMatchMode();
00122   m_pModule->EnableTestMode( 0x123456U ); // Nice easy pattern.
00123   m_pModule->DisableTDCEncapsulation();
00124 
00125   for(int i =0; i < nHitvalues; i++) {
00126 
00127     m_pModule->SetMaxHitsPerEvent(hitcode[i]);
00128     int nWords    = hitwords[i];
00129     unsigned long 
00130       nEventSize = nWords * nChips + 2; // hitwords/chip + header + trailer
00131 
00132 
00133     m_pModule->Trigger();       // Trigger the module for test data.
00134     usleep(nWords);             // Allow time for buffer transfer.
00135 
00136     // The fifo should be ready, but not full.
00137     
00138     ASSERT(m_pModule->isEventFIFOReady());
00139     ASSERT(!m_pModule->isEventFIFOFull());
00140     
00141   // The fifo should indicate an event with # hits * chips.+2.
00142     
00143     unsigned long fifo = m_pModule->ReadEventFIFO();
00144     EQMSG("event size",
00145           nEventSize, 
00146           static_cast<unsigned long>(m_pModule->FIFOWordCount(fifo)));
00147     ASSERT(m_pModule->DataReady()); // Data must be present.
00148 
00149     unsigned long *words = new unsigned long[nEventSize];
00150     m_pModule->ReadData(words, nEventSize);
00151 
00152     // Now check the format:
00153 
00154 
00155     // Global header for GEO 1.
00156     
00157     ASSERT(isGlobalHeader(words[0]));
00158     EQMSG("Slot h", 1U, BoardNumber(words[0]));
00159     
00160 
00161     // For each chip...
00162 
00163     unsigned long*p = &(words[1]);
00164     for(unsigned long chip =0; chip < nChips; chip++) {
00165       for(unsigned long word = 0; word < nWords; word++) { 
00166         ASSERT((*p & 0xf8000000) == 0x20000000); // Test output.
00167         EQMSG("chip", chip,
00168               (*p >> 24) & 0x3);
00169         EQMSG("Data", 0x123456UL, (*p & 0xffffff));
00170         p++;
00171       } 
00172     }
00173       
00174 
00175     
00176     // Global trailer.
00177 
00178     ASSERT(isGlobalTrailer(words[nEventSize-1]));
00179     EQMSG("Size ",  nEventSize, EventSize(words[nEventSize-1]));
00180     EQMSG("Slot t", 1U, BoardNumber(words[nEventSize-1]));
00181 
00182     delete []words;
00183   }
00184 }
00185 
00186 // Same as above, but TDC headers are on.
00187 
00188 void
00189 ReadTests::TestReadHeaders()
00190 {
00191   unsigned short nChips = m_pModule->getChipCount();
00192 
00193   m_pModule->TriggerMatchMode();
00194   m_pModule->EnableTestMode( 0x123456U ); // Nice easy pattern.
00195   m_pModule->EnableTDCEncapsulation();
00196 
00197   for(int i =0; i < nHitvalues; i++) {
00198 
00199     m_pModule->SetMaxHitsPerEvent(hitcode[i]);
00200     int nWords    = hitwords[i];
00201 
00202     // (Hitwords+chiphead+chiptrail)*nchips + global header + global trailer.
00203     unsigned long 
00204       nEventSize = (nWords+2) * nChips + 2;
00205 
00206     m_pModule->Trigger();       // Trigger the module for test data.
00207     usleep(nWords);             // Allow time for buffer transfer.
00208 
00209     // The fifo should be ready, but not full.
00210     
00211     ASSERT(m_pModule->isEventFIFOReady());
00212     ASSERT(!m_pModule->isEventFIFOFull());
00213     
00214   // The fifo should indicate an event with # hits * chips.+2.
00215     
00216     unsigned long fifo = m_pModule->ReadEventFIFO();
00217     EQMSG("event size",
00218           nEventSize, 
00219           static_cast<unsigned long>(m_pModule->FIFOWordCount(fifo)));
00220     ASSERT(m_pModule->DataReady()); // Data must be present.
00221 
00222     unsigned long *words = new unsigned long[nEventSize];
00223     m_pModule->ReadData(words, nEventSize);
00224 
00225     // Now check the format:
00226 
00227 
00228     // Global header for GEO 1.
00229     
00230     ASSERT(isGlobalHeader(words[0]));
00231     EQMSG("Slot h", 1U, BoardNumber(words[0]));
00232     
00233 
00234     // For each chip...
00235 
00236     unsigned long*p = &(words[1]);
00237 
00238 
00239     for(unsigned long chip =0; chip < nChips; chip++) {
00240       // TDC Header
00241       
00242       ASSERT(isTDCHeader(*p));
00243       EQMSG("Chip#", static_cast<unsigned int>(chip), TDCChip(*p));
00244       p++;
00245       
00246       // Test data
00247 
00248       for(unsigned long word = 0; word < nWords; word++) { 
00249         ASSERT((*p & 0xf8000000) == 0x20000000); // Test output.
00250         EQMSG("chip", chip,
00251               (*p >> 24) & 0x3);
00252         EQMSG("Data", 0x123456UL, (*p & 0xffffff));
00253         p++;
00254       } 
00255       // TDC Trailer.
00256 
00257       ASSERT(isTDCTrailer(*p));
00258       EQMSG("Chip#", static_cast<unsigned int>(chip), TDCChip(*p));
00259       EQMSG("Size ", static_cast<short>(nWords+2), TDCWordCount(*p));
00260       p++;
00261 
00262     }
00263 
00264     
00265     // Global trailer.
00266 
00267     ASSERT(isGlobalTrailer(words[nEventSize-1]));
00268     EQMSG("Size ",  nEventSize, EventSize(words[nEventSize-1]));
00269     EQMSG("Slot t", 1U, BoardNumber(words[nEventSize-1]));
00270 
00271     delete []words;
00272   }
00273 }

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