Skip to content

Commit

Permalink
Count child tests for test-number
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Feb 9, 2021
1 parent d2049c3 commit 88bfd40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{"idle-timeout", required_argument, NULL, OPT_IDLE_TIMEOUT},
{"debug", no_argument, NULL, 'd'},
{"max-servers", required_argument, NULL, OPT_MAX_SERVERS},
{"server-test-number", required_argument, NULL, OPT_SERVER_TEST_NUMBER},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
Expand Down Expand Up @@ -1406,6 +1407,14 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
}
server_flag = 1;
break;
case OPT_SERVER_TEST_NUMBER:
test->server_test_number = unit_atoi(optarg);
if (test->server_test_number < 1) {
i_errno = IETESTNUMBER;
return -1;
}
server_flag = 1;
break;
case 'h':
usage_long(stdout);
exit(0);
Expand All @@ -1425,6 +1434,13 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
return -1;
}

/* Setting server test number manually is not allowed */
if (test->server_test_number > 0
&& (test->settings->max_servers > 1 || !iperf_get_test_one_off(test))) {
i_errno = IETESTNUMBER;
return -1;
}

#if defined(HAVE_SSL)

if (test->role == 's' && (client_username || client_rsa_public_key)){
Expand Down
4 changes: 3 additions & 1 deletion src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef uint64_t iperf_size_t;
#define OPT_BIND_DEV 24
#define OPT_IDLE_TIMEOUT 25
#define OPT_MAX_SERVERS 26
#define OPT_SERVER_TEST_NUMBER 27

/* states */
#define TEST_START 1
Expand Down Expand Up @@ -375,7 +376,8 @@ enum {
IESKEWTHRESHOLD = 29, // Invalid value specified as skew threshold
IEIDLETIMEOUT = 30, // Invalid value specified as idle state timeout
IEMAXSERVERS = 31, // Maximum number of servers servers is too high

IETESTNUMBER = 32, // Starting server test number - 0 is first (Not for manual use)

/* Test errors */
IENEWTEST = 100, // Unable to create a new test (check perror)
IEINITTEST = 101, // Test initialization failed (check perror)
Expand Down
14 changes: 10 additions & 4 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ iperf_start_new_server(struct iperf_test *test)
char *argv[MAX_ARGS];
int argc = test->argc;

#define port_str_size 10
char port_str[port_str_size];
#define port_str_max_size 10
#define test_num_str_max_size 20
char port_str[port_str_max_size + 1];
char test_num_str[test_num_str_max_size + 1];
int port;
int port_offset;
int pid;
Expand Down Expand Up @@ -196,9 +198,10 @@ iperf_start_new_server(struct iperf_test *test)
port = port_offset + test->server_port; // Set the actual port number to be used
if (port < 1 || port > 999999) // Port number not appropriate for port_str
return -1;
snprintf(port_str, port_str_size, "%d", port);
snprintf(port_str, port_str_max_size, "%d", port);
snprintf(test_num_str, test_num_str_max_size, "%d", test->server_test_number);

if (argc + 10 > MAX_ARGS) // Too many arguments
if (argc + 12 > MAX_ARGS) // Too many arguments
return -1;
for (i = 0; i < argc; argv[i] = test->argv[i], i++);

Expand All @@ -207,6 +210,8 @@ iperf_start_new_server(struct iperf_test *test)
argv[argc++] = "--one-off";
argv[argc++] = "--connect-timeout";
argv[argc++] = "30000";
argv[argc++] = "--server-test-number";
argv[argc++] = test_num_str;
argv[argc++] = "-p";
argv[argc++] = port_str;

Expand All @@ -226,6 +231,7 @@ iperf_start_new_server(struct iperf_test *test)
/* Parent */
test->servers_list[port_offset] = pid; // Save new server's info
iperf_printf(test, "New server started - port=%d, pid=%d\n", port, pid);
test->server_test_number +=1; // Count also child tests
return port;
}

Expand Down

0 comments on commit 88bfd40

Please sign in to comment.