Skip to content
Draft
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
25 changes: 25 additions & 0 deletions control/src/backend/cell-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,28 @@ describe('selectServingCell — permutation invariance (MANDATORY)', () => {
}
});
});

describe('non-finite measurements are no measurement', () => {
const NON_FINITE = [Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];

test('NaN and infinities never reach a reading', () => {
for (const bad of NON_FINITE) {
const reading = read({ 'physical-ci': bad, rsrp: bad, rsrq: bad, sinr: bad });
expect(reading.pci).toBeUndefined();
expect(reading.rsrp).toBeUndefined();
expect(reading.rsrq).toBeUndefined();
expect(reading.sinr).toBeUndefined();
}
});

test('the serving cell does not depend on input order when one rsrp is NaN', () => {
const cells = [
read({ ci: 'a', rsrp: Number.NaN }),
read({ ci: 'b', rsrp: -90 }),
read({ ci: 'c', rsrp: -80 }),
];
for (const order of permutations(cells)) {
expect(selectServingCell(order)?.cellId).toBe('c');
}
});
});
18 changes: 14 additions & 4 deletions control/src/backend/cell-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,28 @@ function readServing(cell: DecodedProps): boolean {
return cellType?.toLowerCase().includes('serving') ?? false;
}

/**
* A numeric property, but only a real measurement. A D-Bus `d` can carry NaN or an
* infinity, and either one makes the serving-cell comparison below return NaN, which
* breaks its total order; a reading that is not a number is the same as no reading.
*/
function measurementProp(cell: DecodedProps, key: string): number | undefined {
const value = numberProp(cell, key);
return value !== undefined && Number.isFinite(value) ? value : undefined;
}

/** Normalize ONE cell's `a{sv}` dict into a `CellReading`, pinning the known keys. */
export function normalizeCellReading(
cell: DecodedProps,
provenance: CellInfoProvenance,
): CellReading {
const cellId = stringProp(cell, 'ci') ?? stringProp(cell, 'cell-id');
const tac = stringProp(cell, 'tac');
const pci = numberProp(cell, 'physical-ci');
const rsrp = numberProp(cell, 'rsrp');
const rsrq = numberProp(cell, 'rsrq');
const pci = measurementProp(cell, 'physical-ci');
const rsrp = measurementProp(cell, 'rsrp');
const rsrq = measurementProp(cell, 'rsrq');
// `sinr` ONLY — a dict carrying `snr` must never populate this field.
const sinr = numberProp(cell, 'sinr');
const sinr = measurementProp(cell, 'sinr');
// `band` ONLY when directly supplied; never inferred.
const band = stringProp(cell, 'band');
return {
Expand Down
6 changes: 3 additions & 3 deletions control/src/fuzz/cell-info.property.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const KEYS = [
const variantValue = fc.oneof(
fc.string({ maxLength: 12 }),
fc.integer(),
// Non-finite readings are covered next to the fix that handles them.
fc.double({ noNaN: true, noDefaultInfinity: true }),
fc.double(),
fc.constantFrom(Number.NaN, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY),
fc.boolean(),
fc.array(fc.integer(), { maxLength: 3 }),
);
Expand All @@ -56,7 +56,7 @@ describe('cell-info normalization', () => {
expect(typeof reading.serving).toBe('boolean');
for (const key of ['pci', 'rsrp', 'rsrq', 'sinr'] as const) {
const value = reading[key];
if (value !== undefined) expect(typeof value).toBe('number');
if (value !== undefined) expect(Number.isFinite(value)).toBe(true);
}
}
}),
Expand Down