示例#1
0
    def test_three_args(self):
        """Test only using the first three arguments
        """
        self.connect()

        data = ' '*96
        instrs = [makeReplace(self.hw_fifos[0], 0, 16),
                  makeReplace(self.hw_fifos[1], 32, 16),
                  makeReplace(self.hw_fifos[2], 64, 16)]
        self.assertMalloc(id=0, data_size=256, instr_size=16)
        self.assertFalse(upload(self.csre_manager,
                                collection_id=0,
                                session=0,
                                data=data,
                                instructions=instrs))

        arg0 = "0123456789abcdef"
        arg1 = "ghijklmnopqrstuv"
        arg2 = "wxyzABCDEFGHIJKL"
        self.assertFalse(self.sa_trigger.trigger(0,
                                                 str_to_arg(arg0),
                                                 str_to_arg(arg1),
                                                 str_to_arg(arg2)))

        expected_data = arg0  + ' '*16 + arg1 + ' '*16 + arg2 + ' '*16

        self.reader.wait_for(1)
        self.at_reader.wait_for(1)

        self.expect_updated_message(collection_id=0, session_id=0)
        self.expected_audit_trail_sent(session_id=0, data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
示例#2
0
    def test_disabled_collection_id(self):
        """Triggering a disabled collection and then an enabled.
        """
        self.connect()
        self.assertMalloc(id=0, data_size=256, instr_size=16)
        self.assertMalloc(id=1, data_size=256, instr_size=16)

        data = ['X' * 160, ' ' * 160]
        instrs = [
            makeReplace(self.hw_fifos[0], 0, 16),
            makeReplace(self.hw_fifos[1], 32, 16),
            makeReplace(self.hw_fifos[2], 64, 16),
            makeReplace(self.hw_fifos[3], 96, 16),
            makeReplace(self.hw_fifos[4], 128, 16)
        ]

        self.assertFalse(
            upload(self.csre_manager,
                   collection_id=0,
                   session=0,
                   data_mode=CSREManager.CollectionMode_deactivated,
                   data=data[0],
                   instructions=instrs))

        self.assertFalse(
            upload(self.csre_manager,
                   collection_id=1,
                   session=0,
                   data_mode=CSREManager.CollectionMode_triggerOnce,
                   data=data[1],
                   instructions=instrs))

        args = [['0' * 16, '1' * 16, '2' * 16, '3' * 16, '4' * 16],
                ['5' * 16, '6' * 16, '7' * 16, '8' * 16, '9' * 16]]
        for coll_id in range(2):
            self.assertFalse(
                self.sa_trigger.trigger(coll_id, str_to_arg(args[coll_id][0]),
                                        str_to_arg(args[coll_id][1]),
                                        str_to_arg(args[coll_id][2]),
                                        str_to_arg(args[coll_id][3]),
                                        str_to_arg(args[coll_id][4])))

        self.reader.wait_for(1, 2)
        self.at_reader.wait_for(1, 2)

        self.assertEqual(
            (len(self.reader.messages), len(self.at_reader.messages)), (1, 1))

        self.expect_updated_message(collection_id=1, session_id=0)
        last_coll_id = 1  # coll_id = [0, 1]
        expected_data = args[last_coll_id][0] + ' ' * 16 + \
                        args[last_coll_id][1] + ' ' * 16 + \
                        args[last_coll_id][2] + ' ' * 16 + \
                        args[last_coll_id][3] + ' ' * 16 + \
                        args[last_coll_id][4] + ' ' * 16
        self.expected_audit_trail_sent(session_id=0,
                                       data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
示例#3
0
    def test_all_args_different_size_random(self):
        """Test only using all arguments with different sizes.
        """
        self.connect()
        nb_of_test_vector = 128

        test_vector = [[{
            "data": generate_random_str(16),
            "size": randint(1, 16)
        } for _ in range(5)] for i in range(nb_of_test_vector)]

        for coll_id, vector in enumerate(test_vector):
            self.assertMalloc(id=coll_id, data_size=128, instr_size=16)

        for coll_id, vector in enumerate(test_vector):
            data = ' ' * 80
            instrs = [
                makeReplace(self.hw_fifos[0], 0, vector[0]["size"]),
                makeReplace(self.hw_fifos[1], 16, vector[1]["size"]),
                makeReplace(self.hw_fifos[2], 32, vector[2]["size"]),
                makeReplace(self.hw_fifos[3], 48, vector[3]["size"]),
                makeReplace(self.hw_fifos[4], 64, vector[4]["size"]),
            ]
            self.assertFalse(
                upload(self.csre_manager,
                       collection_id=coll_id,
                       session=0,
                       data=data,
                       instructions=instrs))

            self.assertFalse(
                self.sa_trigger.trigger(coll_id, str_to_arg(vector[0]["data"]),
                                        str_to_arg(vector[1]["data"]),
                                        str_to_arg(vector[2]["data"]),
                                        str_to_arg(vector[3]["data"]),
                                        str_to_arg(vector[4]["data"])))

        self.reader.wait_for(len(test_vector), 10)
        self.at_reader.wait_for(len(test_vector), 10)
        self.assertEqual(len(self.reader.messages), len(test_vector))
        self.assertEqual(len(self.at_reader.messages), len(test_vector))

        for coll_id, vector in enumerate(test_vector):
            self.expect_updated_message(collection_id=coll_id, session_id=0)
            expected_data = vector[0]["data"][:vector[0]["size"]] + ' '*(16 - vector[0]["size"]) + \
                            vector[1]["data"][:vector[1]["size"]] + ' '*(16 - vector[1]["size"]) + \
                            vector[2]["data"][:vector[2]["size"]] + ' '*(16 - vector[2]["size"]) + \
                            vector[3]["data"][:vector[3]["size"]] + ' '*(16 - vector[3]["size"]) + \
                            vector[4]["data"][:vector[4]["size"]] + ' '*(16 - vector[4]["size"])
            self.expected_audit_trail_sent(session_id=0,
                                           data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
示例#4
0
    def test_all_args_different_size(self):
        """Test only using all arguments with different sizes.
        """
        self.connect()

        data = ' ' * 256
        instrs = [
            makeReplace(self.hw_fifos[0], 0, 1),
            makeReplace(self.hw_fifos[1], 32, 2),
            makeReplace(self.hw_fifos[2], 64, 3),
            makeReplace(self.hw_fifos[3], 96, 4),
            makeReplace(self.hw_fifos[4], 128, 5),
        ]
        self.assertMalloc(id=0, data_size=256, instr_size=16)
        self.assertFalse(
            upload(self.csre_manager,
                   collection_id=0,
                   session=0,
                   data=data,
                   instructions=instrs))

        arg0 = "0123456789abcdef"
        arg1 = "ghijklmnopqrstuv"
        arg2 = "wxyzABCDEFGHIJKL"
        arg3 = "MNOPQRSTUVWXYZ,."
        arg4 = "<>!?;/:%*+=-_#]["
        self.assertFalse(
            self.sa_trigger.trigger(0, str_to_arg(arg0[:1]),
                                    str_to_arg(arg1[:2]), str_to_arg(arg2[:3]),
                                    str_to_arg(arg3[:4]),
                                    str_to_arg(arg4[:5])))

        expected_data = arg0[:1] + ' ' * (16 + 15) + \
                        arg1[:2] + ' ' * (16 + 14) + \
                        arg2[:3] + ' ' * (16 + 13) + \
                        arg3[:4] + ' ' * (16 + 12) + \
                        arg4[:5] + ' ' * (16 + 11 + 96)

        self.reader.wait_for(1)
        self.at_reader.wait_for(1)
        self.assertEqual(len(self.reader.messages), 1)
        self.assertEqual(len(self.at_reader.messages), 1)

        self.expect_updated_message(collection_id=0, session_id=0)
        self.expected_audit_trail_sent(session_id=0,
                                       data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
示例#5
0
    def test_first_arg(self):
        """Test only using the first argument
        """
        self.connect()

        data = ' '*64
        instrs = [makeReplace(self.hw_fifos[0], 0, 16)]
        self.assertMalloc(id=0, data_size=256, instr_size=16)
        self.assertFalse(upload(self.csre_manager,
                                collection_id=0,
                                session=0,
                                data=data,
                                instructions=instrs))

        arg0 = "0123456789abcdef"
        self.assertFalse(self.sa_trigger.trigger(0, str_to_arg(arg0)))
        expected_data = arg0  + ' '* (64 - len(arg0))

        self.reader.wait_for(1)
        self.at_reader.wait_for(1)

        self.expect_updated_message(collection_id=0, session_id=0)
        self.expected_audit_trail_sent(session_id=0, data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
示例#6
0
    def test_different_collection_id(self):
        """Test trigger with different collection id
        """
        self.connect()

        _firmware_max_collections = self.csre_manager.maxCollectionNumber()
        collection_ids = range(_firmware_max_collections)

        for coll_id in collection_ids:
            self.assertMalloc(id=coll_id, data_size=16, instr_size=1)

        data = 'X' * 16
        instrs = [makeReplace(self.hw_fifos[0], 0, 16)]

        for coll_id in collection_ids:
            self.assertFalse(
                upload(self.csre_manager,
                       collection_id=coll_id,
                       session=0,
                       data=data,
                       instructions=instrs))

        for coll_id in collection_ids:

            def trigger():
                self.sa_trigger.trigger(coll_id,
                                        str_to_arg(str(coll_id).rjust(16)))

            self.assertFalse(retry_with_timeout(cmd=trigger, timeout=1))

        self.reader.wait_for(len(collection_ids), 10)
        self.at_reader.wait_for(len(collection_ids), 10)

        self.assertEqual(
            (len(self.reader.messages), len(self.at_reader.messages)),
            (len(collection_ids), len(collection_ids)))

        for coll_id in collection_ids:
            self.expect_updated_message(collection_id=coll_id, session_id=0)
            expected_data = str(coll_id).rjust(16)
            self.expected_audit_trail_sent(session_id=0,
                                           data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)
    def test_missing_instructions(self):
        """Triggering a collection without instruction and then with instruction.
        """
        self.connect()
        self.assertMalloc(id=0, data_size=256, instr_size=16)
        self.assertMalloc(id=1, data_size=256, instr_size=16)

        data = ['X' * 160, ' ' * 160]
        instrs = [
            makeReplace(self.hw_fifos[0], 0, 16),
            makeReplace(self.hw_fifos[1], 32, 16),
            makeReplace(self.hw_fifos[2], 64, 16),
            makeReplace(self.hw_fifos[3], 96, 16),
            makeReplace(self.hw_fifos[4], 128, 16)
        ]

        self.assertFalse(
            upload(self.csre_manager,
                   collection_id=0,
                   session=0,
                   data=data[0],
                   instructions=[]))

        self.assertFalse(
            upload(self.csre_manager,
                   collection_id=1,
                   session=0,
                   data=data[1],
                   instructions=instrs))

        args = [['0' * 16, '1' * 16, '2' * 16, '3' * 16, '4' * 16],
                ['5' * 16, '6' * 16, '7' * 16, '8' * 16, '9' * 16]]
        for coll_id in range(2):
            self.assertFalse(
                self.sa_trigger.trigger(coll_id, str_to_arg(args[coll_id][0]),
                                        str_to_arg(args[coll_id][1]),
                                        str_to_arg(args[coll_id][2]),
                                        str_to_arg(args[coll_id][3]),
                                        str_to_arg(args[coll_id][4])))

        self.reader.wait_for(2, 2)
        self.at_reader.wait_for(2, 2)

        self.assertEqual(
            (len(self.reader.messages), len(self.at_reader.messages)), (2, 2))

        self.expect_updated_message(collection_id=0, session_id=0)
        self.expect_updated_message(collection_id=1, session_id=0)

        self.expected_audit_trail_sent(session_id=0,
                                       data=("X" * 160).encode('utf-8'))
        expected_data = args[0][0] + ' '*16 + \
                        args[0][1] + ' '*16 + \
                        args[0][2] + ' '*16 + \
                        args[0][3] + ' '*16 + \
                        args[0][4] + ' '*16
        self.expected_audit_trail_sent(session_id=0,
                                       data=expected_data.encode('utf-8'))

        self.assertEqual(len(self.reader.messages), 0)
        self.assertEqual(len(self.at_reader.messages), 0)