diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index c26a8776cd..fbc56cd44e 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -444,6 +444,7 @@ PSEUDOMODULES += shell_cmd_coreclk PSEUDOMODULES += shell_cmd_cryptoauthlib PSEUDOMODULES += shell_cmd_dfplayer PSEUDOMODULES += shell_cmd_fib +PSEUDOMODULES += shell_cmd_genfile PSEUDOMODULES += shell_cmd_gnrc_icmpv6_echo PSEUDOMODULES += shell_cmd_gnrc_ipv6_blacklist PSEUDOMODULES += shell_cmd_gnrc_ipv6_frag_stats diff --git a/sys/Makefile.dep b/sys/Makefile.dep index b27127765e..09885a792e 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -362,7 +362,7 @@ endif ifneq (,$(filter isrpipe_read_timeout,$(USEMODULE))) USEMODULE += isrpipe - USEMODULE += xtimer + USEMODULE += ztimer_usec endif ifneq (,$(filter md5sum sha1sum sha256sum,$(USEMODULE))) diff --git a/sys/isrpipe/Kconfig b/sys/isrpipe/Kconfig index 6519d4e328..af253a500f 100644 --- a/sys/isrpipe/Kconfig +++ b/sys/isrpipe/Kconfig @@ -15,4 +15,4 @@ menuconfig MODULE_ISRPIPE config MODULE_ISRPIPE_READ_TIMEOUT bool "ISR Pipe read with timeout" depends on MODULE_ISRPIPE - select MODULE_XTIMER + select ZTIMER_USEC diff --git a/sys/isrpipe/read_timeout/read_timeout.c b/sys/isrpipe/read_timeout/read_timeout.c index 95f9c83f2e..3a5c6b98a0 100644 --- a/sys/isrpipe/read_timeout/read_timeout.c +++ b/sys/isrpipe/read_timeout/read_timeout.c @@ -20,7 +20,7 @@ #include #include "isrpipe/read_timeout.h" -#include "xtimer.h" +#include "ztimer.h" typedef struct { mutex_t *mutex; @@ -41,9 +41,9 @@ int isrpipe_read_timeout(isrpipe_t *isrpipe, uint8_t *buffer, size_t count, uint _isrpipe_timeout_t _timeout = { .mutex = &isrpipe->mutex, .flag = 0 }; - xtimer_t timer = { .callback = _cb, .arg = &_timeout }; + ztimer_t timer = { .callback = _cb, .arg = &_timeout }; - xtimer_set(&timer, timeout); + ztimer_set(ZTIMER_USEC, &timer, timeout); while (!(res = tsrb_get(&isrpipe->tsrb, buffer, count))) { mutex_lock(&isrpipe->mutex); if (_timeout.flag) { @@ -52,7 +52,7 @@ int isrpipe_read_timeout(isrpipe_t *isrpipe, uint8_t *buffer, size_t count, uint } } - xtimer_remove(&timer); + ztimer_remove(ZTIMER_USEC, &timer); return res; } diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 370cb07a16..d33df0565b 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -1620,12 +1620,12 @@ ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, int gcoap_resp_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, unsigned code) { - if (coap_get_type(pdu) == COAP_TYPE_CON) { - coap_hdr_set_type(pdu->hdr, COAP_TYPE_ACK); - } - coap_hdr_set_code(pdu->hdr, code); + int header_len = coap_build_reply(pdu, code, buf, len, 0); - unsigned header_len = coap_get_total_hdr_len(pdu); + /* request contained no-response option or not enough space for response */ + if (header_len <= 0) { + return -1; + } pdu->options_len = 0; pdu->payload = buf + header_len; diff --git a/sys/shell/cmds/rtc.c b/sys/shell/cmds/rtc.c index eca0bbc4bf..bb5326767a 100644 --- a/sys/shell/cmds/rtc.c +++ b/sys/shell/cmds/rtc.c @@ -27,6 +27,7 @@ #include "container.h" #include "periph/rtc.h" +#include "rtc_utils.h" #include "shell.h" static void _alarm_handler(void *arg) @@ -36,19 +37,6 @@ static void _alarm_handler(void *arg) puts("The alarm rang"); } -static int dow(int year, int month, int day) -{ - /* calculate the day of week using Tøndering's algorithm */ - static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; - if (month < 1 || month > (int) ARRAY_SIZE(t)) { - /* This will be a wrong answer, but error handling is not this - * function's task (whereas memory safety is). */ - return 7; - } - year -= month < 3; - return (year + year/4 - year/100 + year/400 + t[month-1] + day) % 7; -} - /** Read a ["YYYY-MM-DD", "hh:mm:ss"] formatted value from a string array. * * This performs no validation on the entered time -- that'd be trivial on some @@ -58,7 +46,7 @@ static int dow(int year, int month, int day) * * Invalid inputs merely lead to out-of-range values inside the time struct. */ -static int _parse_time(char **argv, struct tm *time) +static void _parse_time(char **argv, struct tm *time) { short i; char *end; @@ -81,10 +69,9 @@ static int _parse_time(char **argv, struct tm *time) i = strtol(end + 1, &end, 10); time->tm_sec = i; - time->tm_wday = dow(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday); time->tm_isdst = -1; /* undefined */ - return 0; + rtc_tm_normalize(time); } static int _print_time(struct tm *time) @@ -113,14 +100,14 @@ static int _rtc_setalarm(char **argv) { struct tm now; - if (_parse_time(argv, &now) == 0) { - if (rtc_set_alarm(&now, _alarm_handler, NULL) == -1) { - puts("rtc: error setting alarm"); - return 1; - } - return 0; + _parse_time(argv, &now); + + if (rtc_set_alarm(&now, _alarm_handler, NULL) < 0) { + puts("rtc: error setting alarm"); + return 1; } - return 1; + + return 0; } static int _rtc_gettime(void) @@ -140,14 +127,14 @@ static int _rtc_settime(char **argv) { struct tm now; - if (_parse_time(argv, &now) == 0) { - if (rtc_set_time(&now) == -1) { - puts("rtc: error setting time"); - return 1; - } - return 0; + _parse_time(argv, &now); + + if (rtc_set_time(&now) < 0) { + puts("rtc: error setting time"); + return 1; } - return 1; + + return 0; } static int _rtc_usage(void) diff --git a/sys/shell/cmds/vfs.c b/sys/shell/cmds/vfs.c index 1f289d0171..e3ff58adc8 100644 --- a/sys/shell/cmds/vfs.c +++ b/sys/shell/cmds/vfs.c @@ -720,6 +720,97 @@ static int _vfs_handler(int argc, char **argv) SHELL_COMMAND(vfs, "virtual file system operations", _vfs_handler); +#if MODULE_SHELL_CMD_GENFILE +static char _get_char(unsigned i) +{ + i %= 62; /* a-z, A-Z, 0..9, -> 62 characters */ + + if (i < 10) { + return '0' + i; + } + i -= 10; + + if (i <= 'z' - 'a') { + return 'a' + i; + } + i -= 1 + 'z' - 'a'; + + return 'A' + i; +} + +static void _write_block(int fd, unsigned bs, unsigned i) +{ + char block[bs]; + char *buf = block; + + buf += snprintf(buf, bs, "|%03u|", i); + + memset(buf, _get_char(i), &block[bs] - buf); + block[bs - 1] = '\n'; + + vfs_write(fd, block, bs); +} + +static int _vfs_genfile_cmd(int argc, char **argv) +{ + unsigned blocksize = 64; + unsigned blocks = 32; + int fd = STDOUT_FILENO; + + const char *cmdname = argv[0]; + while (argc > 1 && argv[1][0] == '-') { + char *optarg = argc > 2 ? argv[2] : NULL; + char opt = argv[1][1]; + + if (optarg == NULL) { + printf("missing argument\n"); + opt = '?'; + } + + switch (opt) { + case '?': + printf("usage: %s [-o ] [-b ] [-n num blocks]\n", + cmdname); + return 0; + case 'o': + fd = vfs_open(optarg, O_CREAT | O_TRUNC | O_WRONLY, 0644); + if (fd < 0) { + printf("can't create %s\n", optarg); + return fd; + } + break; + case 'b': + blocksize = atoi(optarg); + break; + case 'n': + blocks = atoi(optarg); + break; + default: + printf("unknown option '%s'\n", argv[1]); + return 1; + } + argc -= 2; + argv += 2; + } + + if (!blocksize || !blocks || argc > 1) { + printf("invalid argument\n"); + return -EINVAL; + } + + for (unsigned i = 0; i < blocks; ++i) { + _write_block(fd, blocksize, i); + } + + if (fd != STDOUT_FILENO) { + vfs_close(fd); + printf("%u bytes written.\n", blocksize * blocks); + } + return 0; +} +SHELL_COMMAND(genfile, "generate dummy file", _vfs_genfile_cmd); +#endif + __attribute__((used)) /* only used if md5sum / sha1sum / sha256sum is used */ static inline void _print_digest(const uint8_t *digest, size_t len, const char *file) { diff --git a/tests/sys/bloom_bytes/main.c b/tests/sys/bloom_bytes/main.c index 5628cad6b2..e476047344 100644 --- a/tests/sys/bloom_bytes/main.c +++ b/tests/sys/bloom_bytes/main.c @@ -107,13 +107,17 @@ int main(void) printf("\n"); printf("%d elements probably in the filter.\n", in); printf("%d elements not in the filter.\n", not_in); - double false_positive_rate = (double) in / (double) lenA; + unsigned false_positive_rate = (1000UL * in) / lenA; /* Use 'fmt/print_float' to work on all platforms (atmega) * Stdout should be flushed before to prevent garbled output. */ #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC) fflush(stdout); #endif - print_float(false_positive_rate, 6); + + char buf[8]; + int res = fmt_s32_dfp(buf, false_positive_rate, -3); + + print(buf, res); puts(" false positive rate."); bloom_del(&bloom); diff --git a/tests/sys/fido2_ctap/Makefile b/tests/sys/fido2_ctap/Makefile index d83c0476c0..31999264d5 100644 --- a/tests/sys/fido2_ctap/Makefile +++ b/tests/sys/fido2_ctap/Makefile @@ -5,6 +5,7 @@ include ../Makefile.sys_common USEMODULE += fido2_ctap_transport_hid USEMODULE += usbus +USEMODULE += ztimer_sec USEPKG += fido2_tests USB_VID ?= $(USB_VID_TESTING) diff --git a/tests/sys/fido2_ctap/app.config.test b/tests/sys/fido2_ctap/app.config.test index 8667a0d282..a54418e524 100644 --- a/tests/sys/fido2_ctap/app.config.test +++ b/tests/sys/fido2_ctap/app.config.test @@ -5,6 +5,8 @@ CONFIG_MODULE_FIDO2=y CONFIG_MODULE_FIDO2_CTAP=y CONFIG_MODULE_FIDO2_CTAP_TRANSPORT=y CONFIG_MODULE_FIDO2_CTAP_TRANSPORT_HID=y +CONFIG_MODULE_ZTIMER=y +CONFIG_MODULE_ZTIMER_SEC=y CONFIG_PACKAGE_FIDO2_TESTS=y diff --git a/tests/sys/fido2_ctap/main.c b/tests/sys/fido2_ctap/main.c index bda766ca1e..6fbf5cd4e7 100644 --- a/tests/sys/fido2_ctap/main.c +++ b/tests/sys/fido2_ctap/main.c @@ -23,7 +23,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#include "xtimer.h" +#include "ztimer.h" #include "fido2/ctap.h" #include "fido2/ctap/transport/ctap_transport.h" @@ -31,6 +31,6 @@ int main(void) { /* sleep in order to see early DEBUG outputs */ - xtimer_sleep(3); + ztimer_sleep(ZTIMER_SEC, 3); fido2_ctap_transport_init(); } diff --git a/tests/sys/usbus_hid/Makefile b/tests/sys/usbus_hid/Makefile index 24967a39db..3a38a6fe82 100644 --- a/tests/sys/usbus_hid/Makefile +++ b/tests/sys/usbus_hid/Makefile @@ -3,6 +3,7 @@ BOARD ?= nrf52840dk include ../Makefile.sys_common USEMODULE += usbus_hid +USEMODULE += xtimer DISABLE_MODULE += auto_init_usbus diff --git a/tests/sys/vfs_default/Makefile b/tests/sys/vfs_default/Makefile index 6785f408ae..716b7b7ade 100644 --- a/tests/sys/vfs_default/Makefile +++ b/tests/sys/vfs_default/Makefile @@ -4,6 +4,7 @@ USEMODULE += vfs_default USEMODULE += vfs_auto_format USEMODULE += ps +USEMODULE += shell_cmd_genfile USEMODULE += shell_cmds_default include $(RIOTBASE)/Makefile.include diff --git a/tests/unittests/tests-bloom/tests-bloom.c b/tests/unittests/tests-bloom/tests-bloom.c index 55918133a3..b6452989fb 100644 --- a/tests/unittests/tests-bloom/tests-bloom.c +++ b/tests/unittests/tests-bloom/tests-bloom.c @@ -63,7 +63,7 @@ static void test_bloom_based_on_dictionary_fixture(void) { int in = 0; int not_in = 0; - double false_positive_rate = 0; + int false_positive_rate = 0; load_dictionary_fixture(); @@ -78,11 +78,11 @@ static void test_bloom_based_on_dictionary_fixture(void) not_in++; } } - false_positive_rate = (double) in / (double) lenA; + false_positive_rate = (1000 * in) / lenA; TEST_ASSERT_EQUAL_INT(TESTS_BLOOM_PROB_IN_FILTER, in); TEST_ASSERT_EQUAL_INT(TESTS_BLOOM_NOT_IN_FILTER, not_in); - TEST_ASSERT(false_positive_rate < TESTS_BLOOM_FALSE_POS_RATE_THR); + TEST_ASSERT(false_positive_rate < TESTS_BLOOM_FALSE_POS_RATE_THR * 1000); } Test *tests_bloom_tests(void)