sis3600tests.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 "CSIS3600.h"
00008 #ifdef HAVE_STD_NAMESPACE
00009 using namespace std;
00010 #endif
00011 
00012 class sis3600tests : public CppUnit::TestFixture {
00013   CPPUNIT_TEST_SUITE(sis3600tests);
00014   CPPUNIT_TEST(Construction);
00015   CPPUNIT_TEST(LED);
00016   CPPUNIT_TEST(LatchMode);
00017   CPPUNIT_TEST(ExternalClear);
00018   CPPUNIT_TEST(FClearWindow);
00019   CPPUNIT_TEST(LatchTest);
00020   CPPUNIT_TEST(FIFOClear);
00021   CPPUNIT_TEST(Read1);
00022   CPPUNIT_TEST(Read);
00023   CPPUNIT_TEST_SUITE_END();
00024 
00025 
00026 private:
00027   CSIS3600* m_pModule;
00028 public:
00029   void setUp() {
00030     m_pModule = new CSIS3600(0x38383800);
00031   }
00032   void tearDown() {
00033     delete m_pModule;
00034   }
00035 protected:
00036   void Construction();
00037   void LED();
00038   void LatchMode();
00039   void ExternalClear();
00040   void FClearWindow();
00041   void LatchTest();
00042   void Read1();
00043   void Read();
00044   void FIFOClear();
00045 
00046 private:
00047   void LatchEvent();
00048 };
00049 
00050 CPPUNIT_TEST_SUITE_REGISTRATION(sis3600tests);
00051 
00052 // Test construction:
00053 //    Constructing a module at 0x38383800 (default address)
00054 //    should work but constructing one at 0x10000000 should fail.
00055 //
00056 void sis3600tests::Construction()
00057 {
00058   // Should work without exceptions:
00059 
00060   try {
00061     CSIS3600 module(0x38383800); // Crate = 0
00062   }
00063   catch (...) {                 // Should not catch here.
00064     FAIL("Exception on construction of valid module!!");
00065   }
00066 
00067   // This should throw a string exception:
00068 
00069   bool failed = true;
00070   try {
00071     CSIS3600 module(0x10000000);
00072   }
00073   catch (string msg) {          //  Correct exception.
00074     failed = false;
00075   }
00076   catch (...) {                 // Incorrect exception.
00077     FAIL("Bad construction threw wrong type of exception.");
00078   }
00079   if(failed) {
00080     FAIL("Construction of bad moudule did not throw an exception");
00081   }
00082   // Success.
00083 
00084 }
00085 /*
00086   Test that the led can be turned on and off and that
00087   the status register reflects this (assume that if this is consistent
00088   the led actually will go on/off)
00089 */
00090 void
00091 sis3600tests::LED()
00092 {
00093   m_pModule->LightLed();
00094   ASSERT(m_pModule->isLedLit());
00095 
00096 
00097   m_pModule->ClearLed();
00098   ASSERT(!m_pModule->isLedLit());
00099 }
00100 /*
00101    Test that the module can be put in latch (not coincidence
00102    mode.
00103 */
00104 void
00105 sis3600tests::LatchMode()
00106 {
00107   m_pModule->SetLatchMode();
00108   ASSERT(m_pModule->isLatchMode());
00109 
00110   m_pModule->SetCoincidenceMode();
00111   ASSERT(!m_pModule->isLatchMode());
00112 }
00113 /*
00114    Test the ability to enable external clears:
00115 */
00116 void
00117 sis3600tests::ExternalClear()
00118 {
00119   m_pModule->EnableExternalClear();
00120   ASSERT(m_pModule->ExternalClearEnabled());
00121   
00122   m_pModule->DisableExternalClear();
00123   ASSERT(!m_pModule->ExternalClearEnabled());
00124   
00125 }
00126 /*
00127   Test the fast clear window setting:
00128 */
00129 void 
00130 sis3600tests::FClearWindow()
00131 {
00132   // First test the legal window values:
00133   // these should:
00134   // - Not throw exceptions.
00135   // - Return values identical to what was set.
00136   // Note valid values are in the range [220 - 25720 ns].
00137 
00138   int i;
00139   for(i = 220; i <= 25720; i+=100 ) {
00140     try {
00141       m_pModule->SetFastClearWindow(i);
00142       EQ(i, m_pModule->GetFastClearWindow());
00143     }
00144     catch (string msg) {
00145       FAIL("Valid fast clear window set -> Exception");
00146     }
00147   }
00148   // Now test illegal window valuues:
00149   //  - too low
00150   //  - too high.
00151   //
00152   bool failed;
00153   try {
00154     failed = true;
00155     m_pModule->SetFastClearWindow(169); // Above this rounds to ok.
00156   }
00157   catch (string msg) {
00158     failed = false;
00159   }
00160   catch (...) {
00161     FAIL("Invalid fast clear window threw wrong exception type");
00162   }
00163   if(failed) {
00164     FAIL("Invalid fast clear window set succeeded !!!");
00165   }
00166 
00167   try {
00168     failed = true; 
00169     m_pModule->SetFastClearWindow(25771); // Lower rounds down to ok.
00170 
00171   }
00172   catch(string msg) {
00173     failed = false;
00174   }
00175   catch(...) {
00176     FAIL("Invalid fast clear window set threw wrong exception type");
00177   }
00178   if(failed) {
00179     FAIL("Invalid fast clear window set succeeded!!");
00180   }
00181   // Resetting the module should reset the fast clear window to 220:
00182 
00183   m_pModule->Reset();
00184   EQ(220, m_pModule->GetFastClearWindow());
00185 
00186 }
00187 /* Utility to latch an event:
00188  */
00189 void sis3600tests::LatchEvent()
00190 {
00191   m_pModule->StartLatch();
00192   m_pModule->EndLatch();
00193   m_pModule->Clock();
00194 }
00195 /*
00196   Ensure that the software latch can make the fifo not empty.
00197 */
00198 void
00199 sis3600tests::LatchTest()
00200 {
00201   ASSERT(!(m_pModule->DataReady())); // I think reset should clear
00202 
00203   m_pModule->SetCoincidenceMode();              // Take all transitions.
00204   m_pModule->Enable();
00205   LatchEvent();
00206 
00207   ASSERT(m_pModule->DataReady());       // Now there should be data. 
00208 }
00209 /*  
00210   Ensure that clearing the fifo leaves the module with
00211   a fifo empty configuration.
00212 */
00213 
00214 void
00215 sis3600tests::FIFOClear()
00216 {
00217   LatchTest();                  // There's now data in the fifo.
00218 
00219   m_pModule->ClearData();       // Clear the fifo.
00220 
00221   ASSERT(!(m_pModule->DataReady()));
00222 }
00223 /*
00224   Test ability to read a single event.  Note
00225   that a single event consists of a longword of data
00226   containing the bits of a single latch transfer.
00227   
00228 */
00229 void
00230 sis3600tests::Read1()
00231 {
00232   // First latch two words of test data:
00233 
00234   m_pModule->Reset();
00235   m_pModule->SetCoincidenceMode();
00236   m_pModule->Enable();
00237 
00238   for(int i =0; i < 2; i++) {   // The body of this loop
00239     LatchEvent();
00240   }
00241 
00242   unsigned long data;
00243   try {
00244     ASSERT(m_pModule->DataReady()); // data should be ready.
00245     
00246     data = m_pModule->Read();   // Read an event..
00247     
00248     ASSERT(m_pModule->DataReady()); // Should be another event..
00249     
00250     data = m_pModule->Read();
00251     ASSERT(!m_pModule->DataReady()); // no more data.
00252   }
00253   catch (string msg) {          // Should not fire.
00254     FAIL("Read threw exception even with data!");
00255   }
00256 
00257   // The next read should throw an exception:
00258 
00259   bool failed = true;
00260   try {
00261     data = m_pModule->Read();
00262   }
00263   catch (string msg) {
00264     failed = false;
00265   }
00266   catch (...) {
00267     FAIL("Empty read threw wrong exception type");
00268   }
00269   if(failed) {
00270     FAIL("Empty read did not throw an exception");
00271   }
00272   // passed!
00273 
00274 }
00275 /*
00276    Test multievent read
00277 */
00278 void
00279 sis3600tests::Read()
00280 {
00281   m_pModule->Reset();
00282   m_pModule->SetCoincidenceMode();
00283   m_pModule->Enable();
00284 
00285   // Now 100 events:
00286 
00287   for(int i = 0; i < 100; i ++) {
00288     LatchEvent();
00289   }
00290   unsigned long data[30];
00291   unsigned int  nread;
00292 
00293   nread = m_pModule->Read(data, 30);    // Read 30 events.
00294   EQMSG("First 30", 30U, nread);
00295 
00296   nread = m_pModule->Read(data, 30);    // 30 more -> 60...
00297   EQMSG("Second 30", 30U, nread);
00298 
00299   nread = m_pModule->Read(data, 30);    // 30 more -> 90...
00300   EQMSG("Last full 30", 30U, nread);
00301 
00302   nread = m_pModule->Read(data, 30);    // can only read 10
00303   EQMSG("Partial read", 10U, nread);
00304 }

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