/***** Please Read *****/
/* Before use stress.c : User must enter user configuration parameter in "test_config.h" file */
+#define DEFAULT_ITERATIONS 100
+
+static void inline usage(char *argv[])
+{
+ printf("usage: sudo %s <Number of test iterations> [%s] [%s] [%s] [%s] [%s] [%s] [%s]\n",
+ argv[0], SCAN, STA_CONNECT, STA_DISCONNECT, AP_START,
+ STA_LIST, AP_STOP, WIFI_TX_POWER);
+ printf("For example: sudo %s 100 %s %s %s %s %s %s %s\n",
+ argv[0], SCAN, STA_CONNECT, STA_DISCONNECT, AP_START,
+ STA_LIST, AP_STOP, WIFI_TX_POWER);
+}
int main(int argc, char *argv[])
{
- /* Below APIs could be used by demo application */
- char* num = argv[1];
- int ret = 0, stress_test_count = 0;
- ret = control_path_platform_init();
- if (ret != SUCCESS) {
- printf("EXIT!!!!\n");
- exit(0);
- }
+ /* Below APIs could be used by demo application */
+ int ret = 0, stress_test_count = 0;
+ int str_args_start = 2;
+
+ if(getuid()) {
+ printf("Please re-run program with superuser access\n");
+ usage(argv);
+ exit(-1);
+ }
+
+ if (!argv[1]) {
+ usage(argv);
+ exit(-1);
+ }
+
+ stress_test_count = atoi(argv[1]);
+
+ if(!stress_test_count) {
+ printf("Stress count(first arg) identified 0, defaulting to %u\n",
+ DEFAULT_ITERATIONS);
+ stress_test_count = DEFAULT_ITERATIONS;
+ str_args_start = 1;
+ }
+
+ ret = control_path_platform_init();
+ if (ret != SUCCESS) {
+ printf("Failed to read serial driver file\n");
+ exit(0);
+ }
- stress_test_count = atoi(num);
- for (int i=2; i<argc; i++) {
- for (int j=0; j<stress_test_count; j++) {
- if (0 == strncasecmp(STA_CONNECT, argv[i], sizeof(STA_CONNECT))) {
- test_station_mode_connect();
- }
- if (0 == strncasecmp(STA_DISCONNECT, argv[i], sizeof(STA_DISCONNECT))) {
- test_station_mode_disconnect();
- }
- if (0 == strncasecmp(AP_START, argv[i], sizeof(AP_START))) {
- test_softap_mode_start();
- }
- if (0 == strncasecmp(AP_STOP, argv[i], sizeof(AP_STOP))) {
- test_softap_mode_stop();
- }
- if (0 == strncasecmp(SCAN, argv[i], sizeof(SCAN))) {
- test_get_available_wifi();
- }
- if (0 == strncasecmp(STA_LIST, argv[i], sizeof(STA_LIST))) {
- test_softap_mode_connected_clients_info();
- }
- if (0 == strncasecmp(WIFI_TX_POWER, argv[i], sizeof(WIFI_TX_POWER))) {
- test_wifi_set_max_tx_power();
- test_wifi_get_curr_tx_power();
- }
- }
- }
+ for (int test_count=0; test_count<stress_test_count; test_count++) {
+ printf("\nIteration %u:\n",test_count+1);
+ for (int i=str_args_start; i<argc; i++) {
+ if (0 == strncasecmp(SCAN, argv[i], sizeof(SCAN))) {
+ test_get_available_wifi();
+ } else if (0 == strncasecmp(STA_CONNECT, argv[i], sizeof(STA_CONNECT))) {
+ test_station_mode_connect();
+ } else if (0 == strncasecmp(STA_DISCONNECT, argv[i], sizeof(STA_DISCONNECT))) {
+ test_station_mode_disconnect();
+ } else if (0 == strncasecmp(AP_START, argv[i], sizeof(AP_START))) {
+ test_softap_mode_start();
+ } else if (0 == strncasecmp(STA_LIST, argv[i], sizeof(STA_LIST))) {
+ test_softap_mode_connected_clients_info();
+ } else if (0 == strncasecmp(AP_STOP, argv[i], sizeof(AP_STOP))) {
+ test_softap_mode_stop();
+ } else if (0 == strncasecmp(WIFI_TX_POWER, argv[i], sizeof(WIFI_TX_POWER))) {
+ test_wifi_set_max_tx_power();
+ test_wifi_get_curr_tx_power();
+ }
+ }
+ }
- return 0;
+ return 0;
}