]> Git Repo - esp-hosted.git/blame - host/linux/host_control/python_support/stress.py
Merge branch 'pr129_vuhailongkl97' into 'master'
[esp-hosted.git] / host / linux / host_control / python_support / stress.py
CommitLineData
2f806355
YM
1#!/usr/bin/env python3
2# Copyright 2015-2022 Espressif Systems (Shanghai) PTE LTD
8a98f153 3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
2f806355 16import sys
8a98f153 17
2f806355 18if sys.version_info[0] < 3:
4c4ccc7b
YM
19 print("please re-run using python3")
20 exit()
8a98f153 21
2f806355
YM
22from time import *
23from py_parse.cmds import ctrl_cmd
24from py_parse.process import process_init_control_lib, process_deinit_control_lib, process_heartbeat
25from hosted_py_header import *
26import traceback
35dad04f 27
4c4ccc7b 28STRESS_TEST_COUNT=100
2f806355
YM
29sta_mode = 'station'
30sta_mac = 'aa:bb:cc:dd:ee:ff'
4c4ccc7b
YM
31sta_ssid = 'MyWifi'
32sta_pwd = 'MyWifiPass@123'
2f806355 33
4c4ccc7b 34softap_mode = 'softap'
2f806355
YM
35softap_mac = 'cc:bb:aa:ee:ff:dd'
36softap_ssid = 'ESPWiFi'
37softap_pwd = 'ESPWiFi@123'
38
39sta_softap_mode = 'station+softap'
40max_tx_pwr_input = 22
41
42event1 = 'esp_init'
43event2 = 'heartbeat'
44event3 = 'sta_disconnect_from_ap'
45event4 = 'sta_disconnect_from_softap'
46
4c4ccc7b
YM
47argumentList = sys.argv[1:]
48if argumentList and len(argumentList):
49 if "--help" in argumentList or "help" in argumentList:
50 pass
51 else:
52 print("arguments are not required for this script")
53 print("Please edit STRESS_TEST_COUNT in stress.py")
54 print("Edit bitmasks need to be tested and re-run as -\nsudo python3 stress.py")
55 sys.exit()
56
2f806355
YM
57bit = 0
58
59TEST_EVENTS=(1 << bit)
60bit += 1
61
62TEST_MODE_STA=(1 << bit)
63bit += 1
64
65TEST_SCAN_WIFI=(1 << bit)
66bit += 1
67
68TEST_STATION_MAC=(1 << bit)
69bit += 1
70
71TEST_STATION_CONNECT_DISCONNECT=(1 << bit)
72bit += 1
73
74TEST_MODE_SOFTAP=(1 << bit)
75bit += 1
76
77TEST_SOFTAP_MAC=(1 << bit)
78bit += 1
79
80TEST_SOFTAP_VENDOR_IE=(1 << bit)
81bit += 1
82
83TEST_SOFTAP_START_STOP=(1 << bit)
84bit += 1
85
86TEST_STATION_SOFTAP_MODE=(1 << bit)
87bit += 1
88
89TEST_HEARTBEAT=(1 << bit)
90bit += 1
91
92TEST_POWER_SAVE=(1 << bit)
93bit += 1
94
95TEST_WIFI_TX_POWER=(1 << bit)
96
97STRESS_TEST=(TEST_EVENTS | TEST_MODE_STA | TEST_SCAN_WIFI |
4c4ccc7b
YM
98 TEST_STATION_MAC | TEST_STATION_CONNECT_DISCONNECT |
99 TEST_MODE_SOFTAP | TEST_SOFTAP_MAC | TEST_SOFTAP_VENDOR_IE |
100 TEST_SOFTAP_START_STOP | TEST_STATION_SOFTAP_MODE |
101 TEST_HEARTBEAT | TEST_POWER_SAVE | TEST_WIFI_TX_POWER)
2f806355
YM
102
103
4c4ccc7b 104process_init_control_lib()
2f806355 105try:
4c4ccc7b
YM
106 cmd = ctrl_cmd()
107
108 # Config heartbeat
109 if (STRESS_TEST & TEST_EVENTS):
110 for i in (range(STRESS_TEST_COUNT)):
111 print("*************** "+str(i)+" ****************")
112 cmd.unsubscribe_event(event1)
113 cmd.subscribe_event(event1)
114 cmd.unsubscribe_event(event2)
115 cmd.subscribe_event(event2)
116 cmd.unsubscribe_event(event3)
117 cmd.subscribe_event(event3)
118 cmd.unsubscribe_event(event4)
119 cmd.subscribe_event(event4)
120
121 if (STRESS_TEST & TEST_HEARTBEAT):
122 for i in (range(STRESS_TEST_COUNT)):
123 print("*************** "+str(i)+" ****************")
124 cmd.heartbeat(False)
125 cmd.heartbeat(True, 10)
126
127
128 # set wifi mode to station
129 if (STRESS_TEST & TEST_MODE_STA):
130 for i in (range(STRESS_TEST_COUNT)):
131 print("*************** "+str(i)+" ****************")
132 cmd.wifi_set_mode(sta_mode)
133 cmd.wifi_get_mode()
134
135 # get available wifi
136 if (STRESS_TEST & TEST_SCAN_WIFI):
137 for i in (range(STRESS_TEST_COUNT)):
138 print("*************** "+str(i)+" ****************")
139 cmd.get_available_ap()
140
141 # station mode
142
143 # set MAC addeess for station mode
144 if (STRESS_TEST & TEST_STATION_MAC):
145 for i in (range(STRESS_TEST_COUNT)):
146 print("*************** "+str(i)+" ****************")
147 cmd.wifi_set_mac(sta_mode, sta_mac)
148 cmd.wifi_get_mac(sta_mode)
149
150 # station connect and disconnect
151 if (STRESS_TEST & TEST_STATION_CONNECT_DISCONNECT):
152 for i in (range(STRESS_TEST_COUNT)):
153 print("*************** "+str(i)+" ****************")
154 cmd.connect_ap(sta_ssid, sta_pwd)
155 cmd.get_connected_ap_info()
156 cmd.disconnect_ap()
157
158 # softAP mode
159
160 # set wifi mode to softap
161 if (STRESS_TEST & TEST_MODE_SOFTAP):
162 for i in (range(STRESS_TEST_COUNT)):
163 print("*************** "+str(i)+" ****************")
164 cmd.wifi_set_mode(softap_mode)
165 cmd.wifi_get_mode()
166
167 if (STRESS_TEST & TEST_SOFTAP_MAC):
168 for i in (range(STRESS_TEST_COUNT)):
169 print("*************** "+str(i)+" ****************")
170 cmd.wifi_set_mac(softap_mode, softap_mac)
171 cmd.wifi_get_mac(softap_mode)
172
173
174 # set MAC address for softap mode
175 if (STRESS_TEST & TEST_SOFTAP_VENDOR_IE):
176 for i in (range(STRESS_TEST_COUNT)):
177 print("*************** "+str(i)+" ****************")
178 print("Reset softap vendor IE")
179 cmd.softap_vendor_ie(False)
180 cmd.softap_vendor_ie(True, "Test Vendor IE")
181 print("Set softap vendor IE")
182
183 # softAP start, connect station and stop
184 if (STRESS_TEST & TEST_SOFTAP_START_STOP):
185 for i in (range(STRESS_TEST_COUNT)):
186 print("*************** "+str(i)+" ****************")
187 cmd.start_softap(softap_ssid, softap_pwd)
188 cmd.get_softap_info()
189
190 print("***********************")
191 print("Connect station to softAP :"+str(softap_ssid)+" within 15 seconds")
192
193 sleep(15)
194 print("***********************")
195
196 cmd.softap_connected_clients_info()
197 cmd.stop_softap()
198
199 # station + softAP mode
200
201 # test station+softap mode
202 if (STRESS_TEST & TEST_STATION_SOFTAP_MODE):
203 for i in (range(STRESS_TEST_COUNT)):
204 print("*************** "+str(i)+" ****************")
205 cmd.wifi_set_mode(sta_softap_mode)
206 cmd.wifi_get_mode()
207
208 cmd.get_available_ap()
209
210 cmd.connect_ap(sta_ssid, sta_pwd)
211 cmd.start_softap(softap_ssid, softap_pwd)
212
213 cmd.get_connected_ap_info()
214 cmd.get_softap_info()
215
216 cmd.disconnect_ap()
217 cmd.stop_softap()
218
219 # power save mode
220
221 # set and get power save mode
222 if (STRESS_TEST & TEST_POWER_SAVE):
223 for i in (range(STRESS_TEST_COUNT)):
224 print("*************** "+str(i)+" ****************")
225 cmd.set_wifi_power_save("max")
226 cmd.get_wifi_power_save()
227
228 # maximum transmitting power
229
230 # set and get maximum transmitting power
231 if (STRESS_TEST & TEST_WIFI_TX_POWER):
232 for i in (range(STRESS_TEST_COUNT)):
233 print("*************** "+str(i)+" ****************")
234 cmd.set_wifi_max_tx_power(max_tx_pwr_input)
235 cmd.get_wifi_curr_tx_power()
236
237 process_deinit_control_lib(True)
2f806355 238except:
4c4ccc7b
YM
239 process_deinit_control_lib(True)
240 traceback.print_exc()
This page took 0.050338 seconds and 4 git commands to generate.