Skip to content

Commit 0b54797

Browse files
committed
Test CPU states on periodic refresh
Signed-off-by: Jens Reinecke <[email protected]>
1 parent 0c67124 commit 0b54797

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/features/cpu-states/__snapshots__/cpu-states.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ exports[`CpuStates tests with established connection and CPU states supported ca
1212
"",
1313
]
1414
`;
15+
16+
exports[`CpuStates tests with established connection and CPU states supported captures states for periodic refreshs but does not add to history 1`] = `
17+
[
18+
"",
19+
"ΔT CPU States Reason ",
20+
" 0 0 step ",
21+
"",
22+
"",
23+
"ΔT CPU States Reason ",
24+
" 0 0 step ",
25+
"",
26+
]
27+
`;

src/features/cpu-states/cpu-states.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,42 @@ describe('CpuStates', () => {
273273
expect(await cpuStates.getActiveTimeString()).toEqual(' 0 states');
274274
});
275275

276+
it('captures states for periodic refreshs but does not add to history', async () => {
277+
const debugConsoleOutput: string[] = [];
278+
(vscode.debug.activeDebugConsole.appendLine as jest.Mock).mockImplementation(line => debugConsoleOutput.push(line));
279+
280+
// Initial stopped event to capture initial states.
281+
(debugSession.customRequest as jest.Mock).mockResolvedValueOnce({
282+
address: '0xE0001004',
283+
data: new Uint8Array([ 0x01, 0x00, 0x00, 0x00 ]).buffer
284+
});
285+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
286+
(tracker as any)._onStopped.fire(createStoppedEvent(gdbtargetDebugSession, 'step', 0));
287+
await waitForMs(0);
288+
289+
// Capture initial history and clear console while keeping object unchanged for above callback.
290+
cpuStates.showStatesHistory();
291+
const initialHistoryLength = debugConsoleOutput.length;
292+
293+
// Refresh event to add states but not history entry.
294+
(debugSession.customRequest as jest.Mock).mockResolvedValueOnce({
295+
address: '0xE0001004',
296+
data: new Uint8Array([ 0x04, 0x00, 0x00, 0x00 ]).buffer
297+
});
298+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
299+
(gdbtargetDebugSession.refreshTimer as any)._onRefresh.fire(gdbtargetDebugSession);
300+
await waitForMs(0);
301+
302+
// Diff is 4 - 1 = 3 states, but no new history entry.
303+
expect(cpuStates.activeCpuStates?.states).toEqual(BigInt(3));
304+
expect(await cpuStates.getActiveTimeString()).toEqual(' 3 states');
305+
cpuStates.showStatesHistory();
306+
// Expecting same output length, i.e. no additional lines due to added history entries.
307+
expect(debugConsoleOutput.length).toEqual(2*initialHistoryLength);
308+
// Match snapshot to notice any unexpected changes.
309+
expect(debugConsoleOutput).toMatchSnapshot();
310+
});
311+
276312
it('fires refresh events on active stack item change', async () => {
277313
const delays: number[] = [];
278314
const listener = (delay: number) => delays.push(delay);

0 commit comments

Comments
 (0)