Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/gcoap_fileserver: add test for PUT #18725

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion sys/net/application_layer/gcoap/fileserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ static ssize_t _put_file(coap_pkt_t *pdu, uint8_t *buf, size_t len,
if ((ret = vfs_lseek(fd, 0, SEEK_END)) < 0) {
goto close_on_error;
}
if (block1.offset != (unsigned)ret) {
if (block1.offset < (unsigned)ret) {
fabian18 marked this conversation as resolved.
Show resolved Hide resolved
/* ignore duplicate packet */
create = false; /* don't delete file */
ret = COAP_CODE_CONTINUE;
goto close_on_error;
}
if (block1.offset > (unsigned)ret) {
/* expect block to be in the correct order during initial creation */
ret = COAP_CODE_REQUEST_ENTITY_INCOMPLETE;
goto close_on_error;
Expand Down
2 changes: 2 additions & 0 deletions tests/gcoap_fileserver/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ USEMODULE += shell
USEMODULE += shell_commands

USEMODULE += gcoap_fileserver
USEMODULE += gcoap_fileserver_put

USEMODULE += nanocoap_vfs

USEMODULE += constfs
Expand Down
1 change: 1 addition & 0 deletions tests/gcoap_fileserver/Makefile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BOARD_INSUFFICIENT_MEMORY := \
atmega1284p \
atmega328p \
atmega328p-xplained-mini \
atxmega-a1-xplained \
atxmega-a3bu-xplained \
blackpill \
bluepill \
Expand Down
13 changes: 12 additions & 1 deletion tests/gcoap_fileserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];

/* CoAP resources. Must be sorted by path (ASCII order). */
static const coap_resource_t _resources[] = {
{ "/const", COAP_GET | COAP_MATCH_SUBTREE, gcoap_fileserver_handler, "/const" },
{
.path = "/const",
.methods = COAP_GET | COAP_MATCH_SUBTREE,
.handler = gcoap_fileserver_handler,
.context = "/const"
},
{
.path = "/vfs",
.methods = COAP_GET | COAP_PUT | COAP_MATCH_SUBTREE,
.handler = gcoap_fileserver_handler,
.context = VFS_DEFAULT_DATA
},
};

static gcoap_listener_t _listener = {
Expand Down
7 changes: 7 additions & 0 deletions tests/gcoap_fileserver/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ def test_linear_topology(factory, zep_dispatch):

# Download file from CoAP server
B.cmd("vfs rm /nvm0/song.txt")
B.cmd("vfs rm /nvm0/song2.txt")
B.cmd("ncget coap://[2001:db8::1]/const/song.txt", timeout=60)

# make sure the content matches
assert A.cmd("md5sum /const/song.txt").split()[2] == B.cmd("md5sum /nvm0/song.txt").split()[2]

# upload the file to node B (only one node should write MEMORY.bin)
A.cmd("ncput /const/song.txt coap://[" + global_addr(B.cmd("ifconfig 7"))[1] + "]/vfs/song2.txt", timeout=60)

# make sure the content matches
assert B.cmd("md5sum /nvm0/song.txt").split()[2] == B.cmd("md5sum /nvm0/song2.txt").split()[2]

# terminate nodes
for n in nodes:
n.stop_term()
Expand Down