aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/tests/unit/network_services/helpers/vpp_helpers/test_ndr_pdr_result.py
blob: ea9c39a0360c1a341d14a8c111018bc372d9210a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (c) 2019 Viosoft Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import mock

from yardstick.network_services.helpers.vpp_helpers.ndr_pdr_result import \
    NdrPdrResult
from yardstick.network_services.helpers.vpp_helpers.receive_rate_interval import \
    ReceiveRateInterval
from yardstick.network_services.helpers.vpp_helpers.receive_rate_measurement import \
    ReceiveRateMeasurement


class TestNdrPdrResult(unittest.TestCase):

    def test___init__(self):
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        starting_interval = ReceiveRateInterval(measured_low, measured_high)
        ndrpdr_result = NdrPdrResult(starting_interval, starting_interval)
        self.assertIsInstance(ndrpdr_result.ndr_interval, ReceiveRateInterval)
        self.assertIsInstance(ndrpdr_result.pdr_interval, ReceiveRateInterval)

    def test___init__ndr_error(self):
        starting_interval = mock.MagicMock()
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        end_interval = ReceiveRateInterval(measured_low, measured_high)
        with self.assertRaises(TypeError) as raised:
            NdrPdrResult(starting_interval, end_interval)
        self.assertIn('ndr_interval, is not a ReceiveRateInterval: ',
                      str(raised.exception))

    def test___init__pdr_error(self):
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        starting_interval = ReceiveRateInterval(measured_low, measured_high)
        end_interval = mock.MagicMock()
        with self.assertRaises(TypeError) as raised:
            NdrPdrResult(starting_interval, end_interval)
        self.assertIn('pdr_interval, is not a ReceiveRateInterval: ',
                      str(raised.exception))

    def test_width_in_goals(self):
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        starting_interval = ReceiveRateInterval(measured_low, measured_high)
        ndrpdr_result = NdrPdrResult(starting_interval, starting_interval)
        self.assertEqual('ndr 4.86887; pdr 4.86887',
                         ndrpdr_result.width_in_goals(0.005))

    def test___str__(self):
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        starting_interval = ReceiveRateInterval(measured_low, measured_high)
        ndrpdr_result = NdrPdrResult(starting_interval, starting_interval)
        self.assertEqual(
            'NDR=[d=1.0,Tr=4857361.0,Df=0.01749;d=1.0,Tr=4977343.0,Df=0.0241);'
            'PDR=[d=1.0,Tr=4857361.0,Df=0.01749;d=1.0,Tr=4977343.0,Df=0.0241)',
            ndrpdr_result.__str__())

    def test___repr__(self):
        measured_low = ReceiveRateMeasurement(1, 4857361, 4857339, 84965)
        measured_high = ReceiveRateMeasurement(1, 4977343, 4977320, 119959)
        starting_interval = ReceiveRateInterval(measured_low, measured_high)
        ndrpdr_result = NdrPdrResult(starting_interval, starting_interval)
        self.assertEqual(
            'NdrPdrResult(ndr_interval=ReceiveRateInterval(measured_low=' \
            'ReceiveRateMeasurement(duration=1.0,target_tr=4857361.0,' \
            'transmit_count=4857339,loss_count=84965),measured_high=' \
            'ReceiveRateMeasurement(duration=1.0,target_tr=4977343.0,' \
            'transmit_count=4977320,loss_count=119959)),pdr_interval=' \
            'ReceiveRateInterval(measured_low=ReceiveRateMeasurement' \
            '(duration=1.0,target_tr=4857361.0,transmit_count=4857339,' \
            'loss_count=84965),measured_high=ReceiveRateMeasurement' \
            '(duration=1.0,target_tr=4977343.0,transmit_count=4977320,' \
            'loss_count=119959)))',
            ndrpdr_result.__repr__())