Bottlenecks POSCA testing code reconstruction
[bottlenecks.git] / testsuites / posca / testcase_script / posca_factor_system_bandwidth.py
1 #!/usr/bin/env python
2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 '''This file realize the function of run systembandwidth script.
11 for example this contain two part first run_script,
12 second is algorithm, this part is about how to judge the bottlenecks.
13 This test is using yardstick as a tool to begin test.'''
14
15 import os
16 import time
17 import utils.logger as log
18 import utils.infra_setup.runner.yardstick as Runner
19 # --------------------------------------------------
20 # logging configuration
21 # --------------------------------------------------
22 LOG = log.Logger(__name__)
23
24 test_dict = {
25     "action": "runTestCase",
26     "args": {
27         "opts": {
28             "task-args": {}
29         },
30         "testcase": "netperf_bottlenecks"
31     }
32 }
33
34
35 def env_pre():
36     Runner.Create_Incluxdb()
37
38
39 def do_test(test_config, con_dic):
40     test_dict['args']['opts']['task-args'] = test_config
41     Task_id = Runner.Send_Data(test_dict, con_dic['runner_config'])
42     time.sleep(con_dic['test_config']['test_time'])
43     Data_Reply = Runner.Get_Reply(con_dic['runner_config'], Task_id)
44     test_date = Data_Reply[con_dic['runner_config']['testcase']][0]
45     return test_date
46
47
48 def run(con_dic):
49     data = {}
50     rx_pkt_a = con_dic['test_config']['rx_pkt_sizes'].split(',')
51     tx_pkt_a = con_dic['test_config']['tx_pkt_sizes'].split(',')
52     data["rx_pkt_sizes"] = rx_pkt_a
53     data["tx_pkt_sizes"] = tx_pkt_a
54     con_dic["result_file"] = os.path.dirname(
55         os.path.abspath(__file__)) + "/test_case/result"
56     date_id = 0
57     cur_role_result = 1
58     pre_role_result = 1
59     pre_reply = {}
60     data_return = {}
61     data_max = {}
62     data_return["throughput"] = 1
63     for test_x in data["tx_pkt_sizes"]:
64         data_max["throughput"] = 1
65         bandwidth_tmp = 1
66         for test_y in data["rx_pkt_sizes"]:
67             test_config = {
68                 "tx_msg_size": float(test_x),
69                 "rx_msg_size": float(test_y),
70                 "test_time": con_dic['test_config']['test_time']
71             }
72             date_id = date_id + 1
73             data_reply = do_test(test_config, con_dic)
74             bandwidth = float(data_reply["throughput"])
75             if (data_max["throughput"] < bandwidth):
76                 data_max = data_reply
77             if (abs(bandwidth_tmp - bandwidth) / bandwidth_tmp < 0.025):
78                 print(pre_reply)
79                 break
80             else:
81                 pre_reply = data_reply
82                 bandwidth_tmp = bandwidth
83         cur_role_result = float(pre_reply["throughput"])
84         if (abs(pre_role_result - cur_role_result) / pre_role_result < 0.025):
85             print("date_id is %d,package return at line 111\n" % date_id)
86         if data_return["throughput"] < data_max["throughput"]:
87             data_return = data_max
88         pre_role_result = cur_role_result
89     print("date_id is %d,id return success\n" % date_id)
90     return data_return
91
92
93 def main():
94     run(con_dic)
95
96
97 if __name__ == '__main__':
98     main()
99