]> Git Repo - esp-hosted.git/commitdiff
Added in (a) stress app - human readable args (b) test and stress app - superuser...
authorYogesh Mantri <[email protected]>
Tue, 18 Jan 2022 17:56:45 +0000 (23:26 +0530)
committerYogesh Mantri <[email protected]>
Wed, 19 Jan 2022 09:53:08 +0000 (15:23 +0530)
host/linux/host_control/c_support/stress.c
host/linux/host_control/c_support/test.c

index 17978233c5b37d456c2e056ad6fece7b2ac21c55..940ca7edb12d003fa7f42006645f62609507f386 100644 (file)
 
 /***** 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;
 }
index bcd1929991477bf1245e6dad7a3b53b24af039cd..fbd1c4b84ff1e1f967b616f1e424da271e4ef3c8 100644 (file)
@@ -26,6 +26,11 @@ int main(int argc, char *argv[])
 {
     /* Below APIs could be used by demo application */
 
+       if(getuid()) {
+               printf("Please re-run program with superuser access\n");
+               return FAILURE;
+       }
+
     int ret = control_path_platform_init();
     if (ret != SUCCESS) {
         printf("EXIT!!!!\n");
This page took 0.029972 seconds and 4 git commands to generate.