mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
Show roaming state and both SIM identities on dashboard
Display actual roaming registration below APN and both masked IMEIs with an active data SIM badge. Read equipment identities through the existing AT owner in a bounded background job without blocking dashboard requests or changing radio state. Cover SIM selection, no-SIM identities, masking, themes and localization.
This commit is contained in:
9 files changed
+258
-11
No files matched your search
@@ -957,6 +957,9 @@ var DASH_I18N = {
|
||||
'共 ': ['Total ', 'Toplam '],
|
||||
'余 ': ['Free ', 'Boş '],
|
||||
'簇': ['Cluster ', 'Küme '],
|
||||
'数据漫游': ['Data roaming', 'Veri dolaşımı'],
|
||||
'使用中': ['In use', 'Kullanımda'],
|
||||
'是': ['Yes', 'Evet'],
|
||||
'否': ['No', 'Hayır'],
|
||||
'状态看板': ['Dashboard', 'Durum paneli'],
|
||||
'蜂窝': ['Cellular', 'Hücresel'],
|
||||
@@ -1480,6 +1483,9 @@ html.mud-bootstrap-theme{--surface:var(--background-color-high);--surface-sunken
|
||||
.mud-rsrp{font-size:2.3rem;font-weight:700;font-variant-numeric:tabular-nums;line-height:1}
|
||||
.mud-rsrp small{font-size:.9rem;font-weight:500}
|
||||
.mud-chips{display:flex;gap:6px;justify-content:flex-end;flex-wrap:wrap}
|
||||
.mud-imei-label{display:inline-flex;align-items:center;gap:8px;flex-wrap:wrap}
|
||||
.mud-imei-active{display:inline-flex;align-items:center;padding:1px 6px;border-radius:99px;font-size:.68rem;font-weight:600;line-height:1.4;color:var(--success,#2fbf71);background:color-mix(in srgb,var(--success,#2fbf71) 14%,transparent);white-space:nowrap}
|
||||
.mud-imei-active[hidden]{display:none}
|
||||
.mud-tag{display:inline-block;padding:1px 8px;border-radius:99px;background:var(--surface-sunken,rgba(127,127,127,.1));font-size:.74rem;font-weight:600;font-variant-numeric:tabular-nums}
|
||||
.mud-q{display:inline-block;min-width:3em;padding:1px 8px;border-radius:99px;font-size:.74rem;font-weight:600;text-align:center}
|
||||
.mud-rows{display:grid;gap:2px}
|
||||
|
||||
@@ -15,6 +15,18 @@
|
||||
* 邻区行内「锁定」走 lock_set cell(SFUN 重启协议栈,约半分钟断网);锁定状态来自
|
||||
* lock_get(页面加载时取一次,锁定操作后刷新)。 */
|
||||
|
||||
// NR SA may roam while the LTE registration is absent. Never confuse the
|
||||
// permission to roam with the current network's registration state.
|
||||
function roamingLabel(cell, absent) {
|
||||
if (absent) return '否';
|
||||
var states = [cell && cell.reg5g, cell && cell.reg].filter(function(r) {
|
||||
return r && r.stat != null;
|
||||
}).map(function(r) { return Number(r.stat); });
|
||||
if (states.some(function(n) { return n === 5 || n === 10; })) return '是';
|
||||
if (states.some(function(n) { return n === 1 || n === 9; })) return '否';
|
||||
return '--';
|
||||
}
|
||||
|
||||
var DEFAULT_POLL_S = 2;
|
||||
var RATE_WIN = 40;
|
||||
|
||||
@@ -162,6 +174,7 @@ return view.extend({
|
||||
<div class="mud-rows">
|
||||
<div class="mud-r"><span class="mud-k">IPv4 / IPv6</span><span class="mud-v" id="mud-ip">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">APN</span><span class="mud-v" id="mud-apn">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">数据漫游</span><span class="mud-v" id="mud-roaming">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">会话时长</span><span class="mud-v" id="mud-sess">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">注册状态</span><span class="mud-v" id="mud-reg">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">DNS</span><span class="mud-v" id="mud-dns">--</span></div>
|
||||
@@ -215,7 +228,8 @@ return view.extend({
|
||||
<div class="mud-r"><span class="mud-k">调制解调器</span><span class="mud-v" id="mud-modem">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">运营商</span><span class="mud-v" id="mud-carr">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">PLMN</span><span class="mud-v" id="mud-plmn">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">IMEI</span><span class="mud-v" id="mud-imei">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k mud-imei-label">IMEI1 (SIM1)<span class="mud-imei-active" id="mud-imei-active1" hidden></span></span><span class="mud-v" id="mud-imei1">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k mud-imei-label">IMEI2 (SIM2)<span class="mud-imei-active" id="mud-imei-active2" hidden></span></span><span class="mud-v" id="mud-imei2">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">IMSI</span><span class="mud-v" id="mud-imsi">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">ICCID</span><span class="mud-v" id="mud-iccid">--</span></div>
|
||||
<div class="mud-r"><span class="mud-k">本机号码</span><span class="mud-v" id="mud-msisdn">--</span></div>
|
||||
@@ -402,7 +416,18 @@ return view.extend({
|
||||
if (!s) return '--';
|
||||
return this.identShown ? s : s.substring(0, 4) + '****' + s.substring(s.length - 3);
|
||||
}.bind(this);
|
||||
M.set('imei', mask(id && id.imei));
|
||||
var modem = (this.lastInfo && this.lastInfo.modem) || {};
|
||||
var imeis = modem.imeis || [];
|
||||
[0, 1].forEach(function(slot) {
|
||||
// A same-slot full snapshot can arrive before the background identity job.
|
||||
var value = imeis[slot] || (cell && Number(cell.card != null ? cell.card : M.selectedSlot()) === slot && id && id.imei);
|
||||
M.set('imei' + (slot + 1), mask(value));
|
||||
var badge = M.v('imei-active' + (slot + 1));
|
||||
if (badge) {
|
||||
badge.hidden = modem.data_sim == null || Number(modem.data_sim) !== slot;
|
||||
badge.textContent = '\u2713 ' + M.translate('使用中');
|
||||
}
|
||||
});
|
||||
M.set('imsi', mask(id && id.imsi));
|
||||
M.set('iccid', mask(id && id.iccid));
|
||||
M.set('msisdn', mask(id && id.msisdn));
|
||||
@@ -539,6 +564,7 @@ return view.extend({
|
||||
M.v('ip').innerHTML = M.esc(w.ip4 || '--') + (w.ip6 ? '<br>' + M.esc(w.ip6) : '');
|
||||
M.set('dns', w.dns || '--');
|
||||
M.set('apn', w.apn || '--');
|
||||
M.set('roaming', roamingLabel(c, absent));
|
||||
M.set('sess', w.uptime ? M.fmtUptime(w.uptime) : '--');
|
||||
var regmap = { 0: '未注册', 1: '已注册', 2: '搜索中', 3: '注册被拒', 4: '未知', 5: '已注册(漫游)', 7: '仅紧急', 8: '仅紧急', 10: '已注册' };
|
||||
var reg = absent ? '未插卡' : '--';
|
||||
@@ -562,9 +588,10 @@ return view.extend({
|
||||
M.set('carr', oper);
|
||||
M.set('plmn', (c && c.operator && c.operator.plmn) ||
|
||||
(c && c.ident && c.ident.imsi ? c.ident.imsi.substring(0, 5) : '--'));
|
||||
this.paintIdent(c);
|
||||
}
|
||||
|
||||
this.paintIdent(c);
|
||||
|
||||
/* -- 无线 · 局域网 · 设备 · SIM */
|
||||
var wf = i.wifi || {};
|
||||
M.set('ssid', wf.ssid || '--');
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
# Read equipment identities once per boot, through the existing slot-aware AT owner.
|
||||
# This background job never enables a radio, changes the data SIM or reads NV.
|
||||
set -u
|
||||
umask 077
|
||||
dir=${MU300_EQUIPMENT_DIR:-/run/unisoc-modem-equipment}
|
||||
at=${MU300_AT:-/usr/libexec/unisoc-modem/at}
|
||||
boot=${MU300_BOOT_ID_FILE:-/proc/sys/kernel/random/boot_id}
|
||||
mkdir -p "$dir" || exit 1
|
||||
exec 9>"$dir/lock" || exit 1
|
||||
flock -n 9 || exit 0
|
||||
trap 'exit 1' HUP INT TERM
|
||||
boot_id=$(cat "$boot") || exit 1
|
||||
[ -n "$boot_id" ] || exit 1
|
||||
if [ "$(cat "$dir/boot_id" 2>/dev/null)" != "$boot_id" ]; then
|
||||
rm -f "$dir/imei0" "$dir/imei1"
|
||||
printf '%s\n' "$boot_id" > "$dir/boot_id" || exit 1
|
||||
fi
|
||||
# A failed query is retried at most once a minute by the snapshot collector.
|
||||
touch "$dir/attempt"
|
||||
for slot in 0 1; do
|
||||
[ "$slot" = 0 ] || [ "${MU300_EQUIPMENT_SLOTS:-2}" = 2 ] || continue
|
||||
cached=$(cat "$dir/imei$slot" 2>/dev/null)
|
||||
case "$cached" in
|
||||
''|*[!0-9]*) ;;
|
||||
*) [ "${#cached}" != 15 ] || continue ;;
|
||||
esac
|
||||
imei=$(MU300_SIM_SLOT=$slot "$at" -t 2 'AT+CGSN' 2>/dev/null | tr -d '\r' |
|
||||
awk '/^[0-9]+$/ && length($0)==15 {print; exit}')
|
||||
[ -n "$imei" ] || continue
|
||||
printf '%s\n' "$imei" > "$dir/imei$slot.new" && mv "$dir/imei$slot.new" "$dir/imei$slot"
|
||||
done
|
||||
@@ -6,6 +6,7 @@ import * as rt from 'rtnl';
|
||||
import { statvfs } from 'luci.core';
|
||||
import { cursor } from 'uci';
|
||||
import { connect } from 'ubus';
|
||||
import * as uloop from 'uloop';
|
||||
import * as hotspot from '/usr/libexec/unisoc-modem/hotspot.uc';
|
||||
import * as apn from '/usr/libexec/unisoc-modem/apn.uc';
|
||||
|
||||
@@ -27,6 +28,22 @@ export function sim_state(slot) {
|
||||
!(row.state in ['ready','locked','absent']))return 'unknown';
|
||||
return row.state;
|
||||
};
|
||||
// Equipment identity is independent of SIM presence and the selected view.
|
||||
// HTTP reads use RAM files; only this bounded background worker uses the AT owner.
|
||||
let equipment_job=null;
|
||||
function equipment(atd,slots) {
|
||||
let dir='/run/unisoc-modem-equipment', boot_id=rd('/proc/sys/kernel/random/boot_id');
|
||||
let valid=boot_id!='' && rd(dir+'/boot_id')==boot_id;
|
||||
let values=map(['0','1'],n=>valid && match(rd(dir+'/imei'+n),/^[0-9]{15}$/)?rd(dir+'/imei'+n):null);
|
||||
let stamp=fs.stat(ROOT+dir+'/attempt')?.mtime, age=stamp==null?null:time()-stamp;
|
||||
if(atd && boot_id!='' && !equipment_job && (values[0]==null || (slots=='2' && values[1]==null)) &&
|
||||
(!valid || age==null || age<0 || age>=60)) {
|
||||
equipment_job=uloop.process('/bin/sh',['/usr/libexec/unisoc-modem/dashboard-equipment'],{
|
||||
PATH:'/usr/sbin:/usr/bin:/sbin:/bin',MU300_EQUIPMENT_SLOTS:slots
|
||||
},()=>{equipment_job=null;});
|
||||
}
|
||||
return values;
|
||||
};
|
||||
function call(bus,o,m) { return bus?.call(o,m,{}) || {}; }
|
||||
function net(dev) {
|
||||
dev=device(dev);
|
||||
@@ -179,6 +196,12 @@ export function info(slot) {
|
||||
let private_fw=obj('/etc/unisoc-ota/current.json')?.version || rd('/etc/mu300/image-version');
|
||||
if(private_fw)fw=private_fw+' ('+fw+')';
|
||||
let data_slot=cfg('data_sim','0')=='1'?'1':'0';
|
||||
let active_slot=rd('/run/mu300-data-sim-actual');
|
||||
if(wan.up) {
|
||||
if(mobile==cfg('sim0_device','sipa_eth0'))active_slot='0';
|
||||
else if(mobile==cfg('sim1_device','sipa_eth8'))active_slot='1';
|
||||
}
|
||||
if(exists('/run/mu300/sim-active-unknown'))active_slot='';
|
||||
let selection=apn.status(c,obj('/run/unisoc-apn-sim'+data_slot+'.json') || {}), selected_apn=null;
|
||||
if(selection.ok && (slot==null || ''+selection.data_sim==slot) && selection.source in ['sim','auto','network','default'] &&
|
||||
type(selection.apn)=='string' && length(selection.apn)<=100 && !match(selection.apn,/[^A-Za-z0-9.-]/))
|
||||
@@ -205,8 +228,8 @@ export function info(slot) {
|
||||
country:text(wifi.country),enc:wifi.enc || 'none',hidden:wifi.hidden ?? null,hostapd:hapd.status=='ENABLED'?1:0,
|
||||
clients:stations.rows,clients_n:stations.count},
|
||||
lan:{leases:length(leases),ip:address(rows4,lan,false),list:leases},
|
||||
modem:{alive:atd || (urc && now-urc.mtime<240)?1:0,atd:atd?1:0,data_paused:exists('/run/mu300-mobile-data-down')?1:0,
|
||||
sims:map(['0','1'],n=>({slot:int(n),state:atd?sim_state(n):'unknown'}))},
|
||||
modem:{data_sim:active_slot in ['0','1']?int(active_slot):null,alive:atd || (urc && now-urc.mtime<240)?1:0,atd:atd?1:0,data_paused:exists('/run/mu300-mobile-data-down')?1:0,
|
||||
imeis:equipment(atd,cfg('sim_slots','1')),sims:map(['0','1'],n=>({slot:int(n),state:atd?sim_state(n):'unknown'}))},
|
||||
boot:boot(),capabilities:{dualboot:executable('/opt/mu300/bin/mu300-next-boot')?1:0},
|
||||
conns:conntrack(),traffic:obj('/run/unisoc-modem-traffic/view.json')};
|
||||
};
|
||||
|
||||
@@ -75,15 +75,15 @@ with sync_playwright() as pw:
|
||||
show({cell:staged,sig:partial});
|
||||
check(document.querySelector('#mud-rat').firstChild.nodeValue==='5G SA','healthy partial read must preserve engineering signal');
|
||||
check(text('rsrp').includes('-80.0'),'partial read must not blank healthy engineering metrics');
|
||||
check(text('imei')==='fixture-zero' && text('qci')==='9' && text('neigh').includes('456'),'same SIM must keep completed slow tiers');
|
||||
check(text('imei1')==='fixture-zero' && text('qci')==='9' && text('neigh').includes('456'),'same SIM must keep completed slow tiers');
|
||||
|
||||
// A different card at the same slow timestamp must repaint and never inherit identity.
|
||||
const switched=freeze({...staged,card:1});
|
||||
show({cell:switched,sig:{...partial,card:1}});
|
||||
check(text('imei')==='--' && text('qci')==='--' && !text('neigh').includes('456'),'SIM change must clear previous card details');
|
||||
check(text('imei1')==='--' && text('qci')==='--' && !text('neigh').includes('456'),'SIM change must clear previous card details');
|
||||
check(app.lastCell.card===1,'selected card must follow fresh snapshot');
|
||||
show({cell:full,sig:{...signal,card:1,ts:203}});
|
||||
check(app.lastCell.card===1 && !app.lastCell.ident && text('imei')==='--','mismatched slow/fast cards must not merge');
|
||||
check(app.lastCell.card===1 && !app.lastCell.ident && text('imei1')==='--','mismatched slow/fast cards must not merge');
|
||||
|
||||
show({cell:freeze({ts:204,error:'both failed'}),sig:freeze({ts:205,error:'both failed'})});
|
||||
check(document.querySelector('#mud-rat').firstChild.nodeValue==='无应答','continued failure must not reuse last successful signal');
|
||||
@@ -93,7 +93,7 @@ with sync_playwright() as pw:
|
||||
show({info:simInfo('absent'),cell:{...full,ts:220,cfun:0},sig:null});
|
||||
check(document.querySelector('#mud-rat').firstChild.nodeValue==='未插卡','confirmed absence must override RF-off and stale RAT');
|
||||
check(text('reg')==='未插卡' && text('rsrp')==='--','absence must clear stale network and signal');
|
||||
check(text('imei')==='fixture-zero' && text('fwmodel')==='fixture' && text('fw')==='fixture-fw','equipment identity must remain available without a SIM');
|
||||
check(text('imei1')==='fixture-zero' && text('fwmodel')==='fixture' && text('fw')==='fixture-fw','equipment identity must remain available without a SIM');
|
||||
check(text('imsi')==='--' && text('iccid')==='--' && text('msisdn')==='--','removed SIM identifiers must not remain visible');
|
||||
check(!app.lastCell.ident.imsi && !app.lastCell.ident.iccid && !app.lastCell.ident.msisdn,'reveal must not restore identifiers from a removed SIM');
|
||||
check(full.ident.imsi==='fixture-imsi','absence filtering must not mutate the source cache');
|
||||
@@ -109,7 +109,7 @@ with sync_playwright() as pw:
|
||||
check(document.querySelector('#mud-rat').firstChild.nodeValue==='5G SA','fresh insertion/registration must restore RAT');
|
||||
app._slowCell=null; app.lastCell=null; app.lastFullTs=null;
|
||||
show({info:simInfo('absent'),cell:{...full,ts:223,cfun:0,ident:{imei:'cold-imei',model:'cold-model',fw:'cold-fw'}},sig:null});
|
||||
check(text('imei')==='cold-imei' && text('fw')==='cold-fw','a fresh no-SIM page must render newly read equipment identity');
|
||||
check(text('imei1')==='cold-imei' && text('fw')==='cold-fw','a fresh no-SIM page must render newly read equipment identity');
|
||||
check(document.querySelector('#mud-rat').firstChild.nodeValue==='未插卡','equipment identity must not fabricate registration');
|
||||
return {recovery:true,partial_recovery:true,older_signal_rejected:true,
|
||||
same_sim_details_preserved:true,sim_isolation:true,real_failures_visible:true,input_immutable:true};
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""Exercise the shipped dashboard and theme/i18n with both equipment rows."""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--resources', type=Path, default=Path(__file__).resolve().parents[1] / 'openwrt/luci-app-mu300/htdocs/luci-static/resources')
|
||||
parser.add_argument('--screenshots', type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.screenshots: args.screenshots.mkdir(parents=True, exist_ok=True)
|
||||
with sync_playwright() as pw:
|
||||
browser = pw.chromium.launch(executable_path='C:/Program Files/Google/Chrome/Application/chrome.exe')
|
||||
for language, yes, no, active in [('zh', '是', '否', '使用中'), ('en', 'Yes', 'No', 'In use'), ('tr', 'Evet', 'Hayır', 'Kullanımda')]:
|
||||
for dark in [False, True]:
|
||||
page = browser.new_page(viewport={'width': 390, 'height': 844})
|
||||
errors = []
|
||||
page.on('pageerror', lambda error: errors.append(str(error)))
|
||||
page.goto('about:blank')
|
||||
# A normal origin is required by the production sessionStorage helpers.
|
||||
page.route('http://dashboard.test/**', lambda route: route.fulfill(content_type='text/html', body='<main></main>'))
|
||||
page.goto('http://dashboard.test/')
|
||||
page.evaluate('''([common,home,language,dark])=>{
|
||||
window.L={env:{lang:language}};
|
||||
const M=new Function('rpc','baseclass','L',common)(
|
||||
{declare:()=>()=>Promise.resolve({})},{extend:o=>o},L);
|
||||
window.M=M;
|
||||
// View SIM2 while SIM1 carries data, then reverse only the data slot.
|
||||
sessionStorage.setItem('modem-view-slot','1');
|
||||
sessionStorage.setItem('mu300-view-slot','1');
|
||||
window.app=new Function('view','uci','M','SimRadio',home)({extend:o=>o},{},M,{});
|
||||
const root=document.querySelector('main');root.innerHTML=app.html();app._root=root;
|
||||
document.documentElement.style.cssText=dark?'--surface:#171b24;--text:#eee;--success:#57c98a':'--surface:#fff;--text:#111;--success:#16814b';
|
||||
document.body.style.color=dark?'#eee':'#111';
|
||||
M.injectCss();
|
||||
window.snapshot={info:{modem:{alive:1,atd:1,data_sim:0,imeis:['866100000000408','866100000000409']}},
|
||||
cell:{card:1,ts:1,cfun:1,reg:{stat:1},ident:{imei:'866100000000409'}}};
|
||||
window.paint=()=>app.update(JSON.parse(JSON.stringify(snapshot)));
|
||||
paint();
|
||||
}''', [(args.resources/'mu300/common.js').read_text(encoding='utf-8'),
|
||||
(args.resources/'view/mu300/home.js').read_text(encoding='utf-8'), language, dark])
|
||||
assert page.locator('#mud-imei1').inner_text() == '8661****408'
|
||||
assert page.locator('#mud-imei2').inner_text() == '8661****409'
|
||||
assert page.locator('#mud-imei-active1').is_visible()
|
||||
assert not page.locator('#mud-imei-active2').is_visible()
|
||||
assert active in page.locator('#mud-imei-active1').inner_text()
|
||||
assert page.locator('#mud-roaming').inner_text() == no
|
||||
if args.screenshots and language == 'zh':
|
||||
page.screenshot(path=str(args.screenshots/('dark.png' if dark else 'light.png')), full_page=True)
|
||||
# NR-only roaming must win over the nonregistered LTE snapshot.
|
||||
page.evaluate("snapshot.cell.reg={stat:2};snapshot.cell.reg5g={stat:5};paint()")
|
||||
assert page.locator('#mud-roaming').inner_text() == yes
|
||||
# No slow-tier timestamp change: equipment and active-slot repaint anyway.
|
||||
page.evaluate('snapshot.info.modem.data_sim=1;app.identShown=true;paint()')
|
||||
assert page.locator('#mud-imei2').inner_text() == '866100000000409'
|
||||
assert not page.locator('#mud-imei-active1').is_visible()
|
||||
assert page.locator('#mud-imei-active2').is_visible()
|
||||
page.evaluate('snapshot.cell.reg=null;snapshot.cell.reg5g=null;snapshot.info.modem.data_sim=null;paint()')
|
||||
assert page.locator('#mud-roaming').inner_text() == '--'
|
||||
assert not page.locator('#mud-imei-active2').is_visible()
|
||||
# A missing SIM must not erase hardware identity or retain roaming.
|
||||
page.evaluate("snapshot.info.modem.sims=[{slot:0,state:'ready'},{slot:1,state:'absent'}];paint()")
|
||||
assert page.locator('#mud-roaming').inner_text() == no
|
||||
assert page.locator('#mud-imei2').inner_text() == '866100000000409'
|
||||
# Chip identity may complete while the other card is being viewed.
|
||||
page.evaluate('snapshot.info.modem.imeis=[null,null];app.identShown=false;paint()')
|
||||
assert page.locator('#mud-imei1').inner_text() == '--'
|
||||
page.evaluate("snapshot.info.modem.imeis=['866100000000408','866100000000409'];paint()")
|
||||
assert page.locator('#mud-imei1').inner_text() == '8661****408'
|
||||
assert page.evaluate('document.documentElement.scrollWidth<=innerWidth'), 'mobile overflow'
|
||||
assert not errors, errors
|
||||
page.close()
|
||||
browser.close()
|
||||
print('PASS: dual IMEI, masking, actual data SIM, roaming, missing SIM, three languages and both themes')
|
||||
@@ -16,13 +16,14 @@ class Snapshot:
|
||||
self.config=self.root/'config';self.config.mkdir(exist_ok=True)
|
||||
self.responses={};self.stations=[];self.addresses=[]
|
||||
for name,source in {
|
||||
'loop':"export function process(exe,args,env,cb) {writefile(getenv('DASH_FIXTURE')+'/spawn.json',sprintf('%J',{exe,args,env}));return {pid:999};};",
|
||||
'bus':"export function connect(path,timeout) {return {call:(o,m,a)=>{let p=json(readfile(getenv('DASH_FIXTURE')+'/rpc.json'));writefile(getenv('DASH_FIXTURE')+'/last-call.json',sprintf('%J',{o,m,a,timeout}));return p[o+'.'+m] ?? null;}};};",
|
||||
'nl':"export const constants={NL80211_CMD_GET_STATION:19,NLM_F_DUMP:768}; export function request(c,f,a) {return json(readfile(getenv('DASH_FIXTURE')+'/stations.json'));};",
|
||||
'rt':"export const constants={RTM_GETADDR:22,NLM_F_DUMP:768,AF_INET:2,AF_INET6:10}; export function request(c,f,a) {return filter(json(readfile(getenv('DASH_FIXTURE')+'/addresses.json')),r=>r.family==a.family);};"
|
||||
}.items():
|
||||
(self.module/(name+'.uc')).write_text("import {readfile,writefile} from 'fs';\n"+source)
|
||||
source=DASH.read_text().replace('nl.const.','nl.constants.').replace('rt.const.','rt.constants.')
|
||||
for old,new in [('ubus','bus'),('nl80211','nl'),('rtnl','rt')]:
|
||||
for old,new in [('ubus','bus'),('nl80211','nl'),('rtnl','rt'),('uloop','loop')]:
|
||||
source=source.replace("from '"+old+"'","from './"+new+".uc'")
|
||||
for name in ['hotspot','apn']:
|
||||
source=source.replace("'/usr/libexec/unisoc-modem/"+name+".uc'",json.dumps(str(APP/'usr/libexec/unisoc-modem'/(name+'.uc'))))
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Run the equipment collector against a fake slot-aware AT owner, never hardware."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / 'openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/dashboard-equipment'
|
||||
|
||||
|
||||
class Equipment(unittest.TestCase):
|
||||
def test_boot_cache_slot_scope_rejection_and_single_slot(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
root = Path(temp)
|
||||
boot = root/'boot'; boot.write_text('boot-one\n')
|
||||
owner = root/'at'
|
||||
owner.write_text('''#!/bin/sh
|
||||
printf '%s %s\\n' "$MU300_SIM_SLOT" "$*" >> "$TEST_LOG"
|
||||
echo AT+CGSN
|
||||
case "$MU300_SIM_SLOT" in
|
||||
0) echo 866100000000408 ;;
|
||||
1) if [ -f "$TEST_BAD" ]; then echo ERROR; echo 12345; else echo 866100000000409; fi ;;
|
||||
esac
|
||||
echo OK
|
||||
''')
|
||||
owner.chmod(0o700)
|
||||
env = dict(os.environ, MU300_EQUIPMENT_DIR=str(root/'cache'), MU300_AT=str(owner),
|
||||
MU300_BOOT_ID_FILE=str(boot), TEST_LOG=str(root/'calls'), TEST_BAD=str(root/'bad'))
|
||||
def run():
|
||||
subprocess.run(['sh', str(SCRIPT)], env=env, check=True, capture_output=True, timeout=5)
|
||||
(root/'bad').touch(); run()
|
||||
self.assertEqual((root/'cache/imei0').read_text().strip(), '866100000000408')
|
||||
self.assertFalse((root/'cache/imei1').exists())
|
||||
(root/'bad').unlink(); run()
|
||||
self.assertEqual((root/'cache/imei1').read_text().strip(), '866100000000409')
|
||||
calls = (root/'calls').read_text(); run()
|
||||
self.assertEqual((root/'calls').read_text(), calls, 'successful reads must not poll AT again')
|
||||
self.assertEqual(calls.splitlines(), ['0 -t 2 AT+CGSN', '1 -t 2 AT+CGSN', '1 -t 2 AT+CGSN'])
|
||||
boot.write_text('boot-two\n'); env['MU300_EQUIPMENT_SLOTS']='1'; run()
|
||||
self.assertFalse((root/'cache/imei1').exists(), 'never reuse a previous boot or query an unsupported SIM slot')
|
||||
self.assertEqual((root/'calls').read_text().splitlines()[-1], '0 -t 2 AT+CGSN')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -14,6 +14,46 @@ class NativeSnapshot(unittest.TestCase):
|
||||
self.temp=tempfile.TemporaryDirectory();self.addCleanup(self.temp.cleanup)
|
||||
self.root=Path(self.temp.name);self.snap=Snapshot(self.root)
|
||||
|
||||
def test_active_data_slot_is_not_the_view_or_saved_preference(self):
|
||||
self.snap.write('run/mu300-data-sim-actual','1')
|
||||
self.snap.responses['network.interface.wan.status']['up']=False
|
||||
self.assertEqual(self.snap.run(slot='0')['modem']['data_sim'],1)
|
||||
self.snap.responses['network.interface.wan.status'].update(up=True,l3_device='sipa_eth0')
|
||||
self.assertEqual(self.snap.run(slot='1')['modem']['data_sim'],0)
|
||||
self.snap.write('run/mu300/sim-active-unknown','1')
|
||||
self.assertIsNone(self.snap.run()['modem']['data_sim'])
|
||||
|
||||
def test_equipment_queries_are_background_and_failed_reads_are_throttled(self):
|
||||
self.snap.write('proc/sys/kernel/random/boot_id','fixture-boot')
|
||||
self.snap.write('run/mu300-at/owner/pid','100')
|
||||
self.snap.write('proc/100/cmdline','mu300-modemd')
|
||||
fifo=self.root/'run/mu300-at/cmd'; os.mkfifo(fifo)
|
||||
self.snap.run(slot='1')
|
||||
job=json.loads((self.root/'spawn.json').read_text())
|
||||
self.assertEqual(job['exe'],'/bin/sh')
|
||||
self.assertEqual(job['args'],['/usr/libexec/unisoc-modem/dashboard-equipment'])
|
||||
self.assertEqual(job['env']['MU300_EQUIPMENT_SLOTS'],'2')
|
||||
(self.root/'spawn.json').unlink()
|
||||
self.snap.write('run/unisoc-modem-equipment/boot_id','fixture-boot')
|
||||
attempt=self.snap.write('run/unisoc-modem-equipment/attempt','')
|
||||
self.snap.run(slot='0')
|
||||
self.assertFalse((self.root/'spawn.json').exists(),'failed IMEI reads must not query on every page poll')
|
||||
os.utime(attempt,(1,1))
|
||||
self.snap.run(slot='0')
|
||||
self.assertTrue((self.root/'spawn.json').exists(),'failed reads should eventually retry')
|
||||
|
||||
def test_dual_equipment_cache_and_boot_isolation(self):
|
||||
self.snap.write('proc/sys/kernel/random/boot_id','fixture-boot')
|
||||
self.snap.write('run/unisoc-modem-equipment/boot_id','fixture-boot')
|
||||
self.snap.write('run/unisoc-modem-equipment/imei0','866100000000408')
|
||||
self.snap.write('run/unisoc-modem-equipment/imei1','866100000000409')
|
||||
result=self.snap.run(slot='1')
|
||||
self.assertEqual(result['modem']['imeis'],['866100000000408','866100000000409'])
|
||||
self.snap.write('run/unisoc-modem-equipment/imei1','ERROR')
|
||||
self.assertEqual(self.snap.run(slot='1')['modem']['imeis'],['866100000000408',None])
|
||||
self.snap.write('proc/sys/kernel/random/boot_id','other-boot')
|
||||
self.assertEqual(self.snap.run()['modem']['imeis'],[None,None])
|
||||
|
||||
def test_full_snapshot_and_public_apn(self):
|
||||
s=self.snap
|
||||
s.write('sys/class/thermal/thermal_zone0/type','soc-thmzone\n');s.write('sys/class/thermal/thermal_zone0/temp','42000\n')
|
||||
|
||||
Reference in new issue
Block a user