00001 #include <config.h>
00002
00003
00004
00005 #include <cppunit/extensions/HelperMacros.h>
00006 #include <cppunit/Asserter.h>
00007 #include "Asserts.h"
00008 #include "CCAENV1x90.h"
00009 #include "DesignByContract.h"
00010 #include <Iostream.h>
00011
00012 extern long ModuleBase;
00013
00014 class AdjustTests : public CppUnit::TestFixture {
00015 CPPUNIT_TEST_SUITE(AdjustTests);
00016 CPPUNIT_TEST(GlobalOffsetTest);
00017 CPPUNIT_TEST(ChannelOffsetTest);
00018 CPPUNIT_TEST(DelayLineTest);
00019 CPPUNIT_TEST_SUITE_END();
00020
00021
00022 private:
00023 CCAENV1x90* m_pModule;
00024
00025 public:
00026
00027
00028 void setUp() {
00029 m_pModule = new CCAENV1x90(1, 0, ModuleBase);
00030 m_pModule->Reset();
00031 }
00032
00033
00034 void tearDown() {
00035 delete m_pModule;
00036 }
00037 protected:
00038 void GlobalOffsetTest();
00039 void ChannelOffsetTest();
00040 void DelayLineTest();
00041 };
00042
00043 CPPUNIT_TEST_SUITE_REGISTRATION(AdjustTests);
00044
00045
00046
00047
00048
00049 void
00050 AdjustTests::GlobalOffsetTest()
00051 {
00052
00053
00054 for(int nv = 0; nv < 5; nv++) {
00055 for(int nc = 0; nc < 11; nc++) {
00056 unsigned short int coarse, vernier;
00057 m_pModule->SetGlobalOffset((1 << nc) & 0x7ff, (1 << nv) & 0x1f);
00058 m_pModule->ReadGlobalOffset(coarse, vernier);
00059 EQMSG("Coarse", static_cast<unsigned short>((1 << nc) & 0x7ff),
00060 coarse);
00061 EQMSG("Vernier", static_cast<unsigned short>((1 << nv) & 0x1f),
00062 vernier);
00063 }
00064 }
00065
00066
00067
00068 unsigned short coarsein = 0;
00069 unsigned short vernierin = 0;
00070 for(int c = 0; c < 11; c++) {
00071 for(int v =0; v < 5; v++) {
00072 unsigned short coarseout, vernierout;
00073 coarsein |= (1 << c) & 0x7ff;
00074 vernierin |= (1 << v) & 0x1f;
00075 m_pModule->SetGlobalOffset(coarsein, vernierin);
00076 m_pModule->ReadGlobalOffset(coarseout, vernierout);
00077
00078 EQMSG("Coarse", coarsein, coarseout);
00079 EQMSG("Vernier", vernierin, vernierout);
00080
00081 }
00082 }
00083
00084
00085
00086
00087 unsigned short patterns[] = {
00088 0xffff, 0, 0x5a5a, 0xa5a5};
00089
00090 int nPatterns = sizeof(patterns)/sizeof(unsigned short);
00091
00092 for(int c = 0; c < nPatterns; c++) {
00093 for(int v = 0; v < nPatterns; v++) {
00094 unsigned short coarseout;
00095 unsigned short vernierout;
00096
00097 m_pModule->SetGlobalOffset(patterns[c] & 0x7ff, patterns[v] & 0x1f);
00098 m_pModule->ReadGlobalOffset(coarseout, vernierout);
00099
00100 EQMSG("Coarse", static_cast<unsigned short>(patterns[c] & 0x7ff) , coarseout);
00101 EQMSG("Vernier", static_cast<unsigned short>(patterns[v] & 0x1f), vernierout);
00102 }
00103 }
00104 }
00105
00106
00107 void
00108 AdjustTests::ChannelOffsetTest()
00109 {
00110 unsigned int nChannels = m_pModule->getChannelCount();
00111 for(int chan =0; chan < nChannels; chan++) {
00112 for(int value =0; value<=0xff; value++) {
00113 m_pModule->SetChannelOffset(chan, value);
00114 EQ(static_cast<unsigned short>(value), m_pModule->GetChannelOffset(chan));
00115 }
00116 }
00117 }
00118
00119
00120
00121
00122 void
00123 AdjustTests::DelayLineTest()
00124 {
00125 unsigned short nChip = m_pModule->getChipCount();
00126 for(unsigned short i=0; i < nChip; i++) {
00127 for(unsigned short tap1 = 0; tap1 < 8; tap1++) {
00128 for(unsigned short tap2 = 0; tap2 < 8; tap2++) {
00129 for(unsigned short tap3 = 0; tap3 < 8; tap3++) {
00130 for(unsigned short tap4=0; tap4 < 8; tap4++) {
00131 m_pModule->CalibrateDelayLine(i,
00132 tap1, tap2, tap3, tap4);
00133 unsigned short to1, to2, to3, to4;
00134 m_pModule->GetDelayLineCalibration(i,
00135 to1, to2, to3,to4);
00136 EQMSG("Tap1", tap1, to1);
00137 EQMSG("Tap2", tap2, to2);
00138 EQMSG("Tap3", tap3, to3);
00139 EQMSG("Tap4", tap4, to4);
00140 }
00141 }
00142 }
00143 }
00144 }
00145
00146 }