Skip to content
Open
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
2 changes: 1 addition & 1 deletion net/mwan3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=mwan3
PKG_VERSION:=2.12.2
PKG_RELEASE:=2
PKG_RELEASE:=3

PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPL-2.0
Expand Down
2 changes: 1 addition & 1 deletion net/mwan3/files/usr/share/rpcd/ucode/mwan3
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
55 changes: 55 additions & 0 deletions net/mwan3/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,58 @@ actual=$(sanitize_route "$ipv6_route")
echo "actual: '$actual'" >&2
exit 1
}

# Exercise the installed rpcd implementation with isolated state/ubus fixtures.
ucode -S - <<'EOF'
'use strict';
import { readfile } from 'fs';

const path = '/usr/share/rpcd/ucode/mwan3';
let source = readfile(path);
if (source == null)
die('Cannot read mwan3 rpcd plugin');
// Keep the actual functions and RPC implementation; replace only external I/O.
source = substr(source, index(source, 'function get_str_raw('));
let state = {};
const io = {
readfile: path => {
if (path == '/proc/uptime')
return '1000.00 1000.00\n';
return state[split(path, '/')[-1]];
},
cursor: () => ({ foreach: (config, section, callback) => callback({
'.name': 'wan', 'enabled': '1', 'track_ip': ['192.0.2.1']
}) }),
ubus: { call: (object, method, args) => object == 'service' ?
{ mwan3: { instances: { track_wan: { running: true } } } } :
{ up: true, uptime: 900 } },
popen: () => die('Unexpected process execution')
};
const plugin = call(loadstring(source, { raw_mode: true }), null, io);
let checks = 0;
const fields = ['age', 'online', 'offline', 'score', 'lost', 'turn'];
for (let value in [null, '', '\n', 'invalid', '0', '17', '17\n']) {
state = { STARTED: '1', STATUS: 'online' };
for (let key in ['TIME', 'ONLINE', 'OFFLINE', 'SCORE', 'LOST', 'TURN', 'LATENCY_192.0.2.1', 'LOSS_192.0.2.1'])
state[key] = value;
const status = call(plugin.mwan3.status.call, null, io, { args: { section: 'interfaces' } });
const wan = status.interfaces.wan;
for (let field in fields) {
const expected = (value == '17' || value == '17\n') ?
((field in ['age', 'online', 'offline']) ? 983 : 17) : 0;
if (wan[field] !== expected)
die(sprintf('%s for %J: expected %d, got %J\n', field, value, expected, wan[field]));
checks++;
}
for (let key in ['latency', 'packetloss']) {
const expected = (value == '17' || value == '17\n') ? 17 : 0;
if (wan.track_ip[0][key] !== expected)
die(sprintf('%s for %J: got %J\n', key, value, wan.track_ip[0][key]));
checks++;
}
if (!wan.running || !wan.up || wan.uptime != 900)
die('Unrelated interface status changed');
checks++;
}
printf('mwan3 rpcd integer status: %d checks passed\n', checks);
EOF