diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 48c3aebc16..7eee43dcbf 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.12.2 -PKG_RELEASE:=2 +PKG_VERSION:=2.12.3 +PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPL-2.0 diff --git a/net/mwan3/files/usr/share/rpcd/ucode/mwan3 b/net/mwan3/files/usr/share/rpcd/ucode/mwan3 index 2e145c72e5..913aae3258 100644 --- a/net/mwan3/files/usr/share/rpcd/ucode/mwan3 +++ b/net/mwan3/files/usr/share/rpcd/ucode/mwan3 @@ -14,7 +14,7 @@ function get_str(iface, property) { } function get_int(iface, property) { - return int(get_str(iface, property)); + return int(get_str(iface, property)) || 0; } function get_uptime() { diff --git a/net/mwan3/test-rpcd.uc b/net/mwan3/test-rpcd.uc new file mode 100644 index 0000000000..ec85758c51 --- /dev/null +++ b/net/mwan3/test-rpcd.uc @@ -0,0 +1,17 @@ +import { readfile } from 'fs'; + +const source = readfile('/usr/share/rpcd/ucode/mwan3'); +const begin = index(source, 'function get_str_raw('); +const end = index(source, 'function get_uptime('); +if (begin < 0 || end <= begin) + die('Cannot find mwan3 integer helpers\n'); +const read_integer = loadstring(substr(source, begin, end - begin) + + '\nreturn get_int("wan", "SCORE");', { raw_mode: true }); + +for (let sample in [['', 0], [null, 0], ['\n', 0], ['invalid', 0], + ['0', 0], ['17', 17], ['17\n', 17]]) { + const actual = call(read_integer, null, { readfile: () => sample[0] }); + if (actual !== sample[1]) + die(sprintf('get_int(%J): expected %d, got %J\n', sample[0], sample[1], actual)); + printf('get_int(%J): %d\n', sample[0], actual); +} diff --git a/net/mwan3/test.sh b/net/mwan3/test.sh index c3982c6d33..49c036ec68 100755 --- a/net/mwan3/test.sh +++ b/net/mwan3/test.sh @@ -37,3 +37,7 @@ actual=$(sanitize_route "$ipv6_route") echo "actual: '$actual'" >&2 exit 1 } + +# Check that empty, missing and invalid rpcd state becomes zero. +# Numeric values must be preserved. +ucode -S "$(dirname "$0")/test-rpcd.uc"