Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:25

0001 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0002 #include "cppunit/extensions/HelperMacros.h"
0003 
0004 #include "L1Trigger/L1TMuonEndCap/interface/PhiMemoryImage.h"
0005 
0006 class TestPhiMemoryImage : public CppUnit::TestFixture {
0007   CPPUNIT_TEST_SUITE(TestPhiMemoryImage);
0008   CPPUNIT_TEST(test_bitset);
0009   CPPUNIT_TEST(test_rotation);
0010   CPPUNIT_TEST(test_out_of_range);
0011   CPPUNIT_TEST(test_z130);
0012   CPPUNIT_TEST_SUITE_END();
0013 
0014 public:
0015   TestPhiMemoryImage() {}
0016   ~TestPhiMemoryImage() {}
0017   void setUp() {}
0018   void tearDown() {}
0019 
0020   void test_bitset();
0021   void test_rotation();
0022   void test_out_of_range();
0023   void test_z130();
0024 };
0025 
0026 ///registration of the test so that the runner can find it
0027 CPPUNIT_TEST_SUITE_REGISTRATION(TestPhiMemoryImage);
0028 
0029 void TestPhiMemoryImage::test_bitset() {
0030   PhiMemoryImage image;
0031 
0032   image.set_bit(1, 31);
0033   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31), true);
0034   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 0), 1ul << 31);
0035 
0036   image.clear_bit(1, 31);
0037   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31), false);
0038   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 0), 0ul);
0039 
0040   image.set_bit(1, 31 + 64);
0041   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31 + 64), true);
0042   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 1), 1ul << 31);
0043 
0044   image.clear_bit(1, 31 + 64);
0045   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31 + 64), false);
0046   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 1), 0ul);
0047 
0048   image.set_bit(1, 31 + 128);
0049   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31 + 128), true);
0050   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 2), 1ul << 31);
0051 
0052   image.clear_bit(1, 31 + 128);
0053   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 31 + 128), false);
0054   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 2), 0ul);
0055 
0056   image.set_bit(1, 57 + 64);
0057   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 57 + 64), true);
0058   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 1), 1ul << 57);
0059 
0060   image.clear_bit(1, 57 + 64);
0061   CPPUNIT_ASSERT_EQUAL(image.test_bit(1, 57 + 64), false);
0062   CPPUNIT_ASSERT_EQUAL(image.get_word(1, 1), 0ul);
0063 
0064   image.set_bit(3, 99);
0065   image.reset();
0066   CPPUNIT_ASSERT_EQUAL(image.test_bit(3, 99), false);
0067 }
0068 
0069 void TestPhiMemoryImage::test_rotation() {
0070   PhiMemoryImage image;
0071 
0072   uint64_t word0 = 0x0000000011111111;
0073   uint64_t word1 = 0x2222222233333333;
0074   uint64_t word2 = 0x4444444455555555;
0075   uint64_t word3 = 0x6666666677777777;
0076   uint64_t word4 = 0x8888888899999999;
0077   uint64_t word5 = 0xAAAAAAAABBBBBBBB;
0078   uint64_t word6 = 0xCCCCCCCCDDDDDDDD;
0079   uint64_t word7 = 0xEEEEEEEEFFFFFFFF;
0080   uint64_t word8 = 0x0;
0081   image.set_word(0, 0, word0);
0082   image.set_word(0, 1, word1);
0083   image.set_word(0, 2, word2);
0084   image.set_word(1, 0, word3);
0085   image.set_word(1, 1, word4);
0086   image.set_word(1, 2, word5);
0087   image.set_word(2, 0, word6);
0088   image.set_word(2, 1, word7);
0089   image.set_word(2, 2, word8);
0090 
0091   for (int i = 0; i < 200; ++i) {
0092     image.rotl(i);
0093 
0094     if (i == 0)
0095       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word0 << i));
0096     else if (i < 64)
0097       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word0 << i) | (word2 >> (64 - i)));
0098     else if (i == 64)
0099       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word2 << (i - 64)));
0100     else if (i < 128)
0101       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word2 << (i - 64)) | (word1 >> (128 - i)));
0102     else if (i == 128)
0103       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word1 << (i - 128)));
0104     else if (i < 192)
0105       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word1 << (i - 128)) | (word0 >> (192 - i)));
0106     else
0107       CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), (word0));
0108 
0109     image.rotr(i);
0110 
0111     CPPUNIT_ASSERT_EQUAL(image.get_word(0, 0), word0);
0112     CPPUNIT_ASSERT_EQUAL(image.get_word(0, 1), word1);
0113     CPPUNIT_ASSERT_EQUAL(image.get_word(0, 2), word2);
0114     CPPUNIT_ASSERT_EQUAL(image.get_word(1, 0), word3);
0115     CPPUNIT_ASSERT_EQUAL(image.get_word(1, 1), word4);
0116     CPPUNIT_ASSERT_EQUAL(image.get_word(1, 2), word5);
0117     CPPUNIT_ASSERT_EQUAL(image.get_word(2, 0), word6);
0118     CPPUNIT_ASSERT_EQUAL(image.get_word(2, 1), word7);
0119     CPPUNIT_ASSERT_EQUAL(image.get_word(2, 2), word8);
0120     CPPUNIT_ASSERT_EQUAL(image.get_word(3, 0), word8);
0121     CPPUNIT_ASSERT_EQUAL(image.get_word(3, 1), word8);
0122     CPPUNIT_ASSERT_EQUAL(image.get_word(3, 2), word8);
0123   }
0124 }
0125 
0126 void TestPhiMemoryImage::test_out_of_range() {
0127   PhiMemoryImage image;
0128 
0129   CPPUNIT_ASSERT_THROW(image.set_word(0, 3, 0x0), std::out_of_range);
0130   CPPUNIT_ASSERT_THROW(image.get_word(1, 4), std::out_of_range);
0131   CPPUNIT_ASSERT_THROW(image.set_bit(5, 0), std::out_of_range);
0132   CPPUNIT_ASSERT_THROW(image.test_bit(5, 4), std::out_of_range);
0133 }
0134 
0135 void TestPhiMemoryImage::test_z130() {
0136   PhiMemoryImage image;
0137   PhiMemoryImage pattern;
0138 
0139   // Set pattern
0140   int i = 0;
0141   pattern.set_straightness(0);
0142 
0143   for (i = 0; i <= 7; ++i)
0144     pattern.set_bit(0, i);
0145   for (i = 7 + 8; i <= 7 + 8; ++i)
0146     pattern.set_bit(1, i);
0147   for (i = 7 + 8; i <= 14 + 8; ++i)
0148     pattern.set_bit(2, i);
0149   for (i = 7 + 8; i <= 14 + 8; ++i)
0150     pattern.set_bit(3, i);
0151   pattern.rotr(8);
0152 
0153   // Set image
0154   image.set_bit(0, 115);
0155   image.set_bit(1, 133);
0156   image.set_bit(2, 136);
0157   image.set_bit(3, 131);
0158   image.rotl(7);
0159   image.rotr(130);
0160 
0161   int code = pattern.op_and(image);  // AND operation
0162 
0163   //std::cout << "pattern:\n" << pattern << std::endl;
0164   //std::cout << "image:\n" << image << std::endl;
0165   //std::cout << "code: " << code << std::endl;
0166   CPPUNIT_ASSERT_EQUAL(code, 0b101);
0167 }