1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2020 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/stdinc.h" 7 8 #include "spdk/event.h" 9 #include "spdk/string.h" 10 #include "spdk/thread.h" 11 12 struct spdk_app_opts g_opts = {}; 13 static const char g_app_repeat_get_opts_string[] = "t:"; 14 static int g_repeat_times = 2; 15 16 static void 17 app_repeat_usage(void) 18 { 19 printf(" -t <num> number of times to repeat calling spdk_app_start/stop\n"); 20 } 21 22 static int 23 app_repeat_parse_arg(int ch, char *arg) 24 { 25 switch (ch) { 26 case 't': 27 g_repeat_times = spdk_strtol(arg, 0); 28 if (g_repeat_times < 2) { 29 return -EINVAL; 30 } 31 break; 32 default: 33 return -EINVAL; 34 } 35 return 0; 36 } 37 38 static void 39 app_repeat_started(void *arg1) 40 { 41 int index = *(int *)arg1; 42 43 printf("spdk_app_start is called in Round %d.\n", index); 44 } 45 46 static void 47 _app_repeat_shutdown_cb(void) 48 { 49 printf("Shutdown signal received, stop current app iteration\n"); 50 spdk_app_stop(0); 51 } 52 53 int 54 main(int argc, char **argv) 55 { 56 int rc; 57 int i; 58 59 spdk_app_opts_init(&g_opts, sizeof(g_opts)); 60 g_opts.name = "app_repeat"; 61 g_opts.shutdown_cb = _app_repeat_shutdown_cb; 62 if ((rc = spdk_app_parse_args(argc, argv, &g_opts, g_app_repeat_get_opts_string, 63 NULL, app_repeat_parse_arg, app_repeat_usage)) != 64 SPDK_APP_PARSE_ARGS_SUCCESS) { 65 return rc; 66 } 67 68 for (i = 0; i < g_repeat_times; i++) { 69 rc = spdk_app_start(&g_opts, app_repeat_started, &i); 70 spdk_app_fini(); 71 72 if (rc) { 73 fprintf(stderr, "Failed to call spdk_app_start in Round %d.\n", i); 74 break; 75 } 76 } 77 78 return rc; 79 } 80