samples: net: http_client: Allow Docker based testing
Add support for CONFIG_NET_SAMPLE_SEND_ITERATIONS option so that this sample can be run multiple times against HTTP(s) server that is running inside a Docker container. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
c7a0cdd1a5
commit
8ab3dc256c
|
@ -0,0 +1,15 @@
|
|||
# Private config options for http-client sample app
|
||||
|
||||
# Copyright (c) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
mainmenu "Networking http-client sample application"
|
||||
|
||||
config NET_SAMPLE_SEND_ITERATIONS
|
||||
int "Send a sample HTTP query this many times"
|
||||
default 0
|
||||
help
|
||||
Send a sample HTTP query this many times before exiting. A value of
|
||||
zero means that the sample application in default way.
|
||||
|
||||
source "Kconfig.zephyr"
|
|
@ -147,13 +147,13 @@ static int connect_socket(sa_family_t family, const char *server, int port,
|
|||
return ret;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
static int run_queries(void)
|
||||
{
|
||||
struct sockaddr_in6 addr6;
|
||||
struct sockaddr_in addr4;
|
||||
int sock4 = -1, sock6 = -1;
|
||||
int32_t timeout = 3 * MSEC_PER_SEC;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
int port = HTTP_PORT;
|
||||
|
||||
if (IS_ENABLED(CONFIG_NET_SOCKETS_SOCKOPT_TLS)) {
|
||||
|
@ -164,7 +164,7 @@ void main(void)
|
|||
if (ret < 0) {
|
||||
LOG_ERR("Failed to register public certificate: %d",
|
||||
ret);
|
||||
exit(1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
port = HTTPS_PORT;
|
||||
|
@ -184,7 +184,7 @@ void main(void)
|
|||
|
||||
if (sock4 < 0 && sock6 < 0) {
|
||||
LOG_ERR("Cannot create HTTP connection.");
|
||||
exit(1);
|
||||
return -ECONNABORTED;
|
||||
}
|
||||
|
||||
if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
|
@ -240,7 +240,7 @@ void main(void)
|
|||
|
||||
if (sock4 < 0 && sock6 < 0) {
|
||||
LOG_ERR("Cannot create HTTP connection.");
|
||||
exit(1);
|
||||
return -ECONNABORTED;
|
||||
}
|
||||
|
||||
if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
|
@ -302,7 +302,7 @@ void main(void)
|
|||
|
||||
if (sock4 < 0 && sock6 < 0) {
|
||||
LOG_ERR("Cannot create HTTP connection.");
|
||||
exit(1);
|
||||
return -ECONNABORTED;
|
||||
}
|
||||
|
||||
if (sock4 >= 0 && IS_ENABLED(CONFIG_NET_IPV4)) {
|
||||
|
@ -353,5 +353,34 @@ void main(void)
|
|||
close(sock6);
|
||||
}
|
||||
|
||||
k_sleep(K_FOREVER);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
int iterations = CONFIG_NET_SAMPLE_SEND_ITERATIONS;
|
||||
int i = 0;
|
||||
int ret;
|
||||
|
||||
while (iterations == 0 || i < iterations) {
|
||||
ret = run_queries();
|
||||
if (ret < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (iterations > 0) {
|
||||
i++;
|
||||
if (i >= iterations) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (iterations == 0) {
|
||||
k_sleep(K_FOREVER);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue