Пример #1
0
    def test_dq_period_yero(self):
        p = OutputPort('SW1')
        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 40, 100)

        ret = p.dq_modify_period(True)
        self.assertEqual(p._free_period, 0)
        self.assertEqual(100, p._M_Windows[0][2])
Пример #2
0
    def test_different_period_overlap_later(self):
        switches = {}

        p = OutputPort('port1')
        p.associate_stream_to_queue('tt1', 0, 50, 0)
        p.associate_stream_to_queue('tt2', 0, 65, 1)

        M = np.array([[0, 10, 50], [10, 10, 65]])

        p.set_window(0, 0, 10, 50)
        p.set_window(1, 10, 10, 65)

        self.assertEqual(p.get_occupation_percentage(), 210 / 650)
Пример #3
0
    def test_occupation_percentage_same_period(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

        M = np.array([[0, 10, 100], [10, 60, 100], [60, 70, 100]])

        self.assertEqual(np.array_equal(p._M_Windows, M), True)

        # Test occupation percentage
        self.assertEqual(p.get_occupation_percentage(), 7 / 10)
Пример #4
0
    def test_set_period(self):
        p = OutputPort('SW1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

        p.set_period_for_priority(70, 2)
        self.assertEqual(70, p.get_window(2)[2])

        p.set_period_for_priority(99, 2)
        self.assertEqual(99, p.get_window(2)[2])
Пример #5
0
    def test_set_window_and_period_multiplication(self):
        p = OutputPort('port1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 200

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 1000

        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        self.assertEqual(p._M_Windows.shape[0], 3)

        p.set_window(1, 10, 50, 200)
        p.set_window(0, 0, 10, 100)
        p.set_window(2, 60, 10, 1000)

        M = np.array([[0, 10, 100], [10, 60, 200], [60, 70, 1000]])

        self.assertEqual(np.array_equal(p._M_Windows, M), True)

        M_expected = np.array([[0, 10, 300], [10, 60, 600], [60, 70, 3000]])

        p.multipy_period(3)

        self.assertEqual(np.array_equal(p._M_Windows, M_expected), True)
Пример #6
0
    def test_minimum_period(self):
        p = OutputPort('SW1')

        s1_uid = 'tt1'
        s1_length = 10
        s1_period = 100

        s2_uid = 'tt2'
        s2_length = 50
        s2_period = 100

        s3_uid = 'tt3'
        s3_length = 10
        s3_period = 100

        # Test Queue Association
        self.assertEqual(
            p.associate_stream_to_queue(s1_uid, s1_length, s1_period, 0), True)
        self.assertEqual(
            p.associate_stream_to_queue(s2_uid, s2_length, s2_period, 1), True)
        self.assertEqual(
            p.associate_stream_to_queue(s3_uid, s3_length, s3_period, 2), True)

        # Test initial window creation
        self.assertEqual(p._M_Windows.shape[0], 3)

        # Test window assignment
        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 60, 10, 100)

        self.assertEqual(70, p.get_minimum_period_with_current_windows())

        p.set_window(0, 50, 30, 100)
        p.set_window(1, 10, 20, 100)
        p.set_window(2, 0, 60, 100)

        self.assertEqual(80, p.get_minimum_period_with_current_windows())

        p.set_window(0, 0, 10, 100)
        p.set_window(1, 10, 50, 100)
        p.set_window(2, 80, 10, 100)

        self.assertEqual(90, p.get_minimum_period_with_current_windows())