Reporting test details for all tests
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / rapid_irqtest.py
1 #!/usr/bin/python
2
3 ##
4 ## Copyright (c) 2020 Intel Corporation
5 ##
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
9 ##
10 ##
11 ##     http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19
20 from past.utils import old_div
21 import sys
22 import time
23 import requests
24 from rapid_log import RapidLog
25 from rapid_test import RapidTest
26
27 class IrqTest(RapidTest):
28     """
29     Class to manage the irq testing
30     """
31     def __init__(self, test_param, runtime, testname, environment_file,
32             machines):
33         super().__init__(test_param, runtime, testname, environment_file)
34         self.machines = machines
35
36     def run(self):
37         RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------")
38         RapidLog.info("| Measuring time probably spent dealing with an interrupt. Interrupting DPDK cores for more than 50us might be problematic   ")
39         RapidLog.info("| and result in packet loss. The first row shows the interrupted time buckets: first number is the bucket between 0us and    ")
40         RapidLog.info("| that number expressed in us and so on. The numbers in the other rows show how many times per second, the program was       ")
41         RapidLog.info("| interrupted for a time as specified by its bucket. '0' is printed when there are no interrupts in this bucket throughout   ")
42         RapidLog.info("| the duration of the test. 0.00 means there were interrupts in this bucket but very few. Due to rounding this shows as 0.00 ") 
43         RapidLog.info("+----------------------------------------------------------------------------------------------------------------------------")
44         sys.stdout.flush()
45         for machine in self.machines:
46             buckets=machine.socket.show_irq_buckets(1)
47             print('Measurement ongoing ... ',end='\r')
48             machine.start() # PROX cores will be started within 0 to 1 seconds
49             # That is why we sleep a bit over 1 second to make sure all cores
50             # are started
51             time.sleep(1.2)
52             old_irq = [[0 for x in range(len(buckets))] for y in range(len(machine.get_cores()))] 
53             irq     = [[0 for x in range(len(buckets))] for y in range(len(machine.get_cores()))]
54             column_names = []
55             for bucket in buckets:
56                 column_names.append('<{}'.format(bucket))
57             column_names[-1] = '>{}'.format(buckets[-2])
58             for j,bucket in enumerate(buckets):
59                 for i,irqcore in enumerate(machine.get_cores()):
60                     old_irq[i][j] = machine.socket.irq_stats(irqcore,j)
61             # Measurements in the loop above, are updated by PROX every second
62             # This means that taking the same measurement 0.5 second later
63             # might results in the same data or data from the next 1s window
64             time.sleep(float(self.test['runtime']))
65             row_names = []
66             for i,irqcore in enumerate(machine.get_cores()):
67                 row_names.append(irqcore)
68                 for j,bucket in enumerate(buckets):
69                     diff =  machine.socket.irq_stats(irqcore,j) - old_irq[i][j]
70                     if diff == 0:
71                         irq[i][j] = '0'
72                     else:
73                         irq[i][j] = str(round(old_div(diff,float(self.test['runtime'])), 2))
74             # Measurements in the loop above, are updated by PROX every second
75             # This means that taking the same measurement 0.5 second later
76             # might results in the same data or data from the next 1s window
77             # Conclusion: we don't know the exact window size.
78             # Real measurement windows might be wrong by 1 second
79             # This could be fixed in this script by checking this data every
80             # 0.5 seconds Not implemented since we can also run this test for
81             # a longer time and decrease the error. The absolute number of
82             # interrupts is not so important.
83             machine.stop()
84             RapidLog.info('Results for PROX instance %s'%machine.name)
85             RapidLog.info('{:>12}'.format('bucket us') + ''.join(['{:>12}'.format(item) for item in column_names]))
86             for j, row in enumerate(irq):
87                 RapidLog.info('Core {:>7}'.format(row_names[j]) + ''.join(['{:>12}'.format(item) for item in row]))
88             variables = {}
89             variables['test'] = self.test['test']
90             variables['environment_file'] = self.test['environment_file']
91             variables['Machine'] = machine.name
92             for i,irqcore in enumerate(machine.get_cores()):
93                 variables['Core'] = '{}'.format(row_names[i])
94                 for j,bucket in enumerate(buckets):
95                     variables['B{}'.format(column_names[j].replace(">","M").replace("<","").replace(" ",""))] = irq[i][j]
96                 self.post_data('rapid_irqtest', variables)
97         return (True, None)