From f42386587d7ed782a07408e54ed2230125e38757 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 21 May 2024 16:45:32 +0200 Subject: [PATCH] tests/nanocoap_fs: add test for nanoCoAP fs --- tests/net/nanocoap_fs/Makefile | 22 ++++++++ tests/net/nanocoap_fs/Makefile.ci | 38 +++++++++++++ tests/net/nanocoap_fs/README.md | 11 ++++ tests/net/nanocoap_fs/main.c | 89 +++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 tests/net/nanocoap_fs/Makefile create mode 100644 tests/net/nanocoap_fs/Makefile.ci create mode 100644 tests/net/nanocoap_fs/README.md create mode 100644 tests/net/nanocoap_fs/main.c diff --git a/tests/net/nanocoap_fs/Makefile b/tests/net/nanocoap_fs/Makefile new file mode 100644 index 0000000000..4625e08672 --- /dev/null +++ b/tests/net/nanocoap_fs/Makefile @@ -0,0 +1,22 @@ +include ../Makefile.net_common + +# Include packages that pull up and auto-init the link layer. +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present +USEMODULE += netdev_default +USEMODULE += auto_init_gnrc_netif +# Specify the mandatory networking modules +USEMODULE += gnrc_ipv6_default + +# Optionally include DNS support. This includes resolution of names at an +# upstream DNS server and the handling of RDNSS options in Router Advertisements +# to auto-configure that upstream DNS server. +# USEMODULE += sock_dns # include DNS client +# USEMODULE += gnrc_ipv6_nib_dns # include RDNSS option handling + +USEMODULE += nanocoap_fs + +# Required by test +USEMODULE += shell +USEMODULE += shell_cmds_default + +include $(RIOTBASE)/Makefile.include diff --git a/tests/net/nanocoap_fs/Makefile.ci b/tests/net/nanocoap_fs/Makefile.ci new file mode 100644 index 0000000000..f2aea054bb --- /dev/null +++ b/tests/net/nanocoap_fs/Makefile.ci @@ -0,0 +1,38 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-mega2560 \ + arduino-nano \ + arduino-uno \ + atmega328p \ + atmega328p-xplained-mini \ + atmega8 \ + atxmega-a3bu-xplained \ + bluepill-stm32f030c8 \ + i-nucleo-lrwan1 \ + msb-430 \ + msb-430h \ + nucleo-c031c6 \ + nucleo-f030r8 \ + nucleo-f031k6 \ + nucleo-f042k6 \ + nucleo-f303k8 \ + nucleo-f334r8 \ + nucleo-l011k4 \ + nucleo-l031k6 \ + nucleo-l053r8 \ + olimex-msp430-h1611 \ + olimex-msp430-h2618 \ + samd10-xmini \ + slstk3400a \ + stk3200 \ + stm32f030f4-demo \ + stm32f0discovery \ + stm32f7508-dk \ + stm32g0316-disco \ + stm32l0538-disco \ + telosb \ + waspmote-pro \ + weact-g030f6 \ + z1 \ + # diff --git a/tests/net/nanocoap_fs/README.md b/tests/net/nanocoap_fs/README.md new file mode 100644 index 0000000000..54af4b27d4 --- /dev/null +++ b/tests/net/nanocoap_fs/README.md @@ -0,0 +1,11 @@ +# nanoCoAP remote fs example + +This allows to mount a remote fs that was exported via e.g. `nanocoap_fileserver` +or `aiocoap-fileserver`. + +The test provides a `mount` command to mount a remote fs at a local mount point: + + mount coap://[fe80::607f:b1ff:fef7:689c]/vfs /coap + +This will mount the `vfs/` resource on the remote server as a local `/coap/` +directory. This can then be interacted with normal `vfs` commands such as `ls`. diff --git a/tests/net/nanocoap_fs/main.c b/tests/net/nanocoap_fs/main.c new file mode 100644 index 0000000000..87ac88f18e --- /dev/null +++ b/tests/net/nanocoap_fs/main.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief nanoCoAP fs test app + * + * @author Benjamin Valentin + * + * @} + */ + +#include +#include "msg.h" + +#include "net/nanocoap/fs.h" +#include "string_utils.h" +#include "shell.h" + +#define MAIN_QUEUE_SIZE (4) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +static int _cmd_mount(int argc, char **argv) +{ + static char url[64]; + static char mp[64]; + int res; + + if (argc != 3) { + printf("usage: %s \n", argv[0]); + return 1; + } + + if ((res = strscpy(mp, argv[2], sizeof(mp))) < 0) { + return res; + } + if ((res = strscpy(url, argv[1], sizeof(url))) < 0) { + return res; + } + + if (url[res] != '/') { + url[res] = '/'; + if (res == sizeof(url)) { + return -ENOBUFS; + } + url[++res] = 0; + } + + static nanocoap_fs_t nanocoap_fs_desc = { + .url = url, + }; + + static vfs_mount_t _mount = { + .fs = &nanocoap_fs_file_system, + .mount_point = mp, + .private_data = &nanocoap_fs_desc, + }; + + res = vfs_mount(&_mount); + + return res; +} + +static const shell_command_t shell_commands[] = { + { "mount", "Mount a remote fs", _cmd_mount }, + { NULL, NULL, NULL } +}; + +int main(void) +{ + /* for the thread running the shell */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should never be reached */ + return 0; +}