Skip to content

Commit

Permalink
tests/nanocoap_cli: add blockwise put test
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 1, 2022
1 parent 3d51f0e commit 153819f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/nanocoap_cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
extern int nanotest_client_cmd(int argc, char **argv);
extern int nanotest_client_url_cmd(int argc, char **argv);
extern int nanotest_server_cmd(int argc, char **argv);
extern int nanotest_client_put_cmd(int argc, char **argv);
static int _list_all_inet6(int argc, char **argv);

static const shell_command_t shell_commands[] = {
{ "client", "CoAP client", nanotest_client_cmd },
{ "url", "CoAP client URL request", nanotest_client_url_cmd },
{ "put", "experimental put", nanotest_client_put_cmd },
{ "server", "CoAP server", nanotest_server_cmd },
{ "inet6", "IPv6 addresses", _list_all_inet6 },
{ NULL, NULL, NULL }
Expand Down
56 changes: 56 additions & 0 deletions tests/nanocoap_cli/nanocli_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "net/nanocoap.h"
#include "net/nanocoap_sock.h"
#include "net/sock/udp.h"
#include "net/sock/util.h"

#include "od.h"

Expand Down Expand Up @@ -210,3 +211,58 @@ int nanotest_client_url_cmd(int argc, char **argv)
printf("usage: %s <get|post|put> <url> [data]\n", argv[0]);
return -1;
}

static const char song[] =
"Join us now and share the software;\n"
"You'll be free, hackers, you'll be free.\n"
"Join us now and share the software;\n"
"You'll be free, hackers, you'll be free.\n"
"\n"
"Hoarders can get piles of money,\n"
"That is true, hackers, that is true.\n"
"But they cannot help their neighbors;\n"
"That's not good, hackers, that's not good.\n"
"\n"
"When we have enough free software\n"
"At our call, hackers, at our call,\n"
"We'll kick out those dirty licenses\n"
"Ever more, hackers, ever more.\n"
"\n"
"Join us now and share the software;\n"
"You'll be free, hackers, you'll be free.\n"
"Join us now and share the software;\n"
"You'll be free, hackers, you'll be free.\n";

int nanotest_client_put_cmd(int argc, char **argv)
{
int res;
coap_block_request_t ctx;

if (argc < 2) {
printf("usage: %s <url>\n", argv[0]);
return 1;
}

res = nanocoap_block_request_init_url(&ctx, argv[1],
COAP_METHOD_PUT, COAP_BLOCKSIZE_32);
if (res < 0) {
puts(strerror(-res));
return res;
}

const char *pos = song;
size_t len = sizeof(song);

while (len) {
res = nanocoap_sock_block_request(&ctx, pos, len, 0, NULL, NULL);
if (res <= 0) {
puts(strerror(-res));
break;
}
len -= res;
pos += res;
}

nanocoap_block_request_done(&ctx);
return res;
}

0 comments on commit 153819f

Please sign in to comment.