1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from vstf.controller.unittest import model
16 from vstf.controller.settings.flows_settings import FlowsSettings
17 from vstf.controller.settings.tool_settings import ToolSettings
18 from vstf.controller.settings.perf_settings import PerfSettings
19 from vstf.controller.sw_perf.perf_provider import PerfProvider
20 from vstf.controller.sw_perf.flow_producer import FlowsProducer
21 from vstf.controller.settings.tester_settings import TesterSettings
22 from vstf.controller.env_build.env_build import EnvBuildApi as Builder
23 from vstf.common.log import setup_logging
24 import vstf.controller.sw_perf.performance as pf
26 LOG = logging.getLogger(__name__)
29 class TestPerf(model.Test):
32 LOG.info("start performance unit test.")
33 super(TestPerf, self).setUp()
34 self.dir = os.path.dirname(__file__)
35 self.perf_path = os.path.join(self.dir, '../../../etc/vstf/perf')
36 self.base_path = os.path.join(self.dir, '../../../etc/vstf/env')
39 LOG.info("stop performance unit test.")
41 @unittest.skip('for now')
42 def test_batch_perf(self):
44 LOG.info(self.perf_path)
45 LOG.info(self.base_path)
46 perf_settings = PerfSettings(path=self.perf_path)
47 flows_settings = FlowsSettings(path=self.perf_path)
48 tool_settings = ToolSettings(path=self.base_path)
49 tester_settings = TesterSettings(path=self.base_path)
50 flow_producer = FlowsProducer(self.conn, flows_settings)
51 provider = PerfProvider(
52 flows_settings.settings,
53 tool_settings.settings,
54 tester_settings.settings)
55 perf = pf.Performance(self.conn, provider)
56 tests = perf_settings.settings
57 for scenario, cases in tests.items():
61 config_file = os.path.join(self.base_path, scenario + '.json')
65 env = Builder(self.conn, config_file)
69 casetag = case['case']
71 protocol = case['protocol']
72 profile = case['profile']
76 flow_producer.create(scenario, casetag)
77 result = perf.run(tool, protocol, ttype, sizes)
78 self.assertEqual(True, isinstance(result, dict))
81 @unittest.skip('for now')
82 def test_perf_settings(self):
83 perf_settings = PerfSettings()
84 self.assertEqual(True, perf_settings.input())
86 def test_tool_settings(self):
87 tool_settings = ToolSettings()
92 tool_settings.set_pktgen(value)
93 tool_settings.set_netperf(value)
94 tool_settings.set_iperf(value)
95 tool_settings.set_qperf(value)
96 LOG.info(tool_settings.settings)
98 def test_flow_settings(self):
100 "Tn": ["Tn-1", "Tn-2", "Tn-3", "Tn-4"],
101 "Tnv": ["Tnv-1", "Tnv-2", "Tnv-3", "Tnv-4"],
102 "Ti": ["Ti-1", "Ti-2", "Ti-3", "Ti-4", "Ti-5", "Ti-6"],
103 "Tu": ["Tu-1", "Tu-2", "Tu-3", "Tu-4", "Tu-5", "Tu-6"]
105 flows_settings = FlowsSettings(path=self.perf_path)
106 flow_producer = FlowsProducer(self.conn, flows_settings)
108 for scenario, cases in tests.items():
112 config_file = os.path.join(self.base_path, scenario + '.json')
114 LOG.info(config_file)
116 env = Builder(self.conn, config_file)
121 flow_producer.create(scenario, case)
122 LOG.info(flows_settings.settings)
125 if __name__ == "__main__":
128 log_file="/var/log/vstf/vstf-unit-test.log",