Branch data Line data Source code
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 : 0 : app_repeat_usage(void) 18 : : { 19 [ # # ]: 0 : printf(" -t <num> number of times to repeat calling spdk_app_start/stop\n"); 20 : 0 : } 21 : : 22 : : static int 23 : 20 : app_repeat_parse_arg(int ch, char *arg) 24 : : { 25 [ + - ]: 20 : switch (ch) { 26 : 20 : case 't': 27 : 20 : g_repeat_times = spdk_strtol(arg, 0); 28 [ - + ]: 20 : if (g_repeat_times < 2) { 29 : 0 : return -EINVAL; 30 : : } 31 : 20 : break; 32 : 0 : default: 33 : 0 : return -EINVAL; 34 : : } 35 : 20 : return 0; 36 : : } 37 : : 38 : : static void 39 : 80 : app_repeat_started(void *arg1) 40 : : { 41 : 80 : int index = *(int *)arg1; 42 : : 43 [ - + ]: 80 : printf("spdk_app_start is called in Round %d.\n", index); 44 : 80 : } 45 : : 46 : : static void 47 : 80 : _app_repeat_shutdown_cb(void) 48 : : { 49 [ - + ]: 80 : printf("Shutdown signal received, stop current app iteration\n"); 50 : 80 : spdk_app_stop(0); 51 : 80 : } 52 : : 53 : : int 54 : 20 : main(int argc, char **argv) 55 : : { 56 : : int rc; 57 : 8 : int i; 58 : : 59 : 20 : spdk_app_opts_init(&g_opts, sizeof(g_opts)); 60 : 20 : g_opts.name = "app_repeat"; 61 : 20 : g_opts.shutdown_cb = _app_repeat_shutdown_cb; 62 [ - + ]: 20 : 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 : 0 : return rc; 66 : : } 67 : : 68 [ + + ]: 100 : for (i = 0; i < g_repeat_times; i++) { 69 : 80 : rc = spdk_app_start(&g_opts, app_repeat_started, &i); 70 : 80 : spdk_app_fini(); 71 : : 72 [ - + ]: 80 : if (rc) { 73 [ # # # # ]: 0 : fprintf(stderr, "Failed to call spdk_app_start in Round %d.\n", i); 74 : 0 : break; 75 : : } 76 : : } 77 : : 78 : 20 : return rc; 79 : : }