2020 */
2121
2222import * as vscode from 'vscode' ;
23+ import type { DebugProtocol } from '@vscode/debugprotocol' ;
2324import type { GDBTargetDebugTracker } from '../../../../debug-session' ;
2425import type { GDBTargetDebugSession } from '../../../../debug-session/gdbtarget-debug-session' ;
2526import { componentViewerLogger } from '../../../../logger' ;
@@ -38,6 +39,7 @@ const instanceFactory = jest.fn(() => ({
3839 getGuiTree : jest . fn < ScvdGuiInterface [ ] | undefined , [ ] > ( ( ) => [ ] ) ,
3940 updateActiveSession : jest . fn ( ) ,
4041 cancelExecution : jest . fn ( ) ,
42+ setSvdPath : jest . fn ( ) ,
4143} ) ) ;
4244
4345jest . mock ( '../../component-viewer-instance' , ( ) => ( {
@@ -102,6 +104,26 @@ const getReadScvdFiles = (controller: TestClass) =>
102104// Local test mocks
103105type ExpansionEventCallback = ( event : vscode . TreeViewExpansionEvent < ScvdGuiInterface > ) => void ;
104106
107+ const makeMemoryEvent = ( ) : DebugProtocol . MemoryEvent => ( {
108+ event : 'memory' ,
109+ type : 'event' ,
110+ seq : 1 ,
111+ body : {
112+ memoryReference : '0x1234' ,
113+ offset : 0 ,
114+ count : 4 ,
115+ } ,
116+ } ) ;
117+
118+ const makeInvalidatedEvent = ( ) : DebugProtocol . InvalidatedEvent => ( {
119+ event : 'invalidated' ,
120+ type : 'event' ,
121+ seq : 1 ,
122+ body : {
123+ areas : [ 'variables' ] ,
124+ } ,
125+ } ) ;
126+
105127const createController = (
106128 context : vscode . ExtensionContext = extensionContextFactory ( ) ,
107129 provider : ComponentViewerTreeDataProvider = treeDataProviderFactory ( )
@@ -157,12 +179,12 @@ describe('ComponentViewerBase', () => {
157179 expect ( vscode . commands . registerCommand ) . toHaveBeenCalledWith ( 'vscode-cmsis-debugger.testClass.lockComponent' , expect . any ( Function ) ) ;
158180 expect ( vscode . commands . registerCommand ) . toHaveBeenCalledWith ( 'vscode-cmsis-debugger.testClass.unlockComponent' , expect . any ( Function ) ) ;
159181 expect ( vscode . commands . registerCommand ) . toHaveBeenCalledWith ( 'vscode-cmsis-debugger.testClass.expandAll' , expect . any ( Function ) ) ;
160- // 1 tree view + 2 event listeners + 7 commands + 6 tracker disposables
161- expect ( context . subscriptions . length ) . toBe ( 16 ) ;
182+ // 1 tree view + 2 event listeners + 7 commands + 8 tracker disposables
183+ expect ( context . subscriptions . length ) . toBe ( 18 ) ;
162184 expect ( vscode . commands . registerCommand ) . toHaveBeenCalledWith ( 'vscode-cmsis-debugger.testClass.filterTree' , expect . any ( Function ) ) ;
163185 expect ( vscode . commands . registerCommand ) . toHaveBeenCalledWith ( 'vscode-cmsis-debugger.testClass.clearFilter' , expect . any ( Function ) ) ;
164- // 1 tree view + 2 event listeners + 7 commands + 6 tracker disposables
165- expect ( context . subscriptions . length ) . toBe ( 16 ) ;
186+ // 1 tree view + 2 event listeners + 7 commands + 8 tracker disposables
187+ expect ( context . subscriptions . length ) . toBe ( 18 ) ;
166188 } ) ;
167189
168190 it ( 'should fail to activate the test class tree data provider if view is not correctly loaded' , async ( ) => {
@@ -213,6 +235,22 @@ describe('ComponentViewerBase', () => {
213235 expect ( instanceFactory ) . toHaveBeenCalledTimes ( 2 ) ;
214236 } ) ;
215237
238+ it ( 'sets svd path from debug configuration when reading scvd files' , async ( ) => {
239+ const session = debugSessionFactory ( 's1' , [ 'a.scvd' ] ) ;
240+ ( session . session as unknown as { configuration : { definitionPath : string } } ) . configuration = {
241+ definitionPath : '/device.svd' ,
242+ } ;
243+ ( controller as unknown as { _activeSession ?: Session } ) . _activeSession = session ;
244+
245+ const instance = instanceFactory ( ) ;
246+ instanceFactory . mockImplementationOnce ( ( ) => instance ) ;
247+
248+ const readScvdFiles = getReadScvdFiles ( controller ) ;
249+ await readScvdFiles ( tracker , session ) ;
250+
251+ expect ( instance . setSvdPath ) . toHaveBeenCalledWith ( '/device.svd' ) ;
252+ } ) ;
253+
216254 it ( 'skips reading scvd files when no active session is set' , async ( ) => {
217255 const session = debugSessionFactory ( 's1' , [ 'a.scvd' ] ) ;
218256 const readScvdFiles = getReadScvdFiles ( controller ) ;
@@ -235,6 +273,7 @@ describe('ComponentViewerBase', () => {
235273 getGuiTree : jest . fn ( ( ) => [ ] ) ,
236274 updateActiveSession : jest . fn ( ) ,
237275 cancelExecution : jest . fn ( ) ,
276+ setSvdPath : jest . fn ( ) ,
238277 } ) ) ;
239278 const showErrorSpy = jest . spyOn ( vscode . window , 'showErrorMessage' ) . mockResolvedValue ( undefined ) ;
240279 const errorSpy = jest . spyOn ( componentViewerLogger , 'error' ) ;
@@ -292,6 +331,9 @@ describe('ComponentViewerBase', () => {
292331 await tracker . callbacks . stackTrace ?.( { session } ) ;
293332 expect ( ( controller as unknown as { _activeSession ?: Session } ) . _activeSession ) . toBe ( session ) ;
294333
334+ await tracker . callbacks . memory ?.( { session, event : makeMemoryEvent ( ) } ) ;
335+ await tracker . callbacks . invalidated ?.( { session, event : makeInvalidatedEvent ( ) } ) ;
336+
295337
296338 ( controller as unknown as { _activeSession ?: Session } ) . _activeSession = session ;
297339 await tracker . callbacks . willStop ?.( session ) ;
@@ -351,6 +393,36 @@ describe('ComponentViewerBase', () => {
351393 expect ( ( controller as unknown as { _activeSession ?: Session } ) . _activeSession ) . toBe ( sessionA ) ;
352394 } ) ;
353395
396+ it ( 'updates instances on memory event' , async ( ) => {
397+ const sessionA = debugSessionFactory ( 's1' , [ ] , 'stopped' ) ;
398+
399+ ( controller as unknown as { _activeSession ?: Session } ) . _activeSession = sessionA ;
400+
401+ const scheduleSpy = jest
402+ . spyOn ( controller as unknown as { schedulePendingUpdate : ( reason : UpdateReason ) => void } , 'schedulePendingUpdate' )
403+ . mockImplementation ( ( ) => undefined ) ;
404+
405+ const handleOnMemoryEvent = ( controller as unknown as { handleOnMemoryEvent : ( s : Session ) => Promise < void > } ) . handleOnMemoryEvent . bind ( controller ) ;
406+ await handleOnMemoryEvent ( sessionA ) ;
407+
408+ expect ( scheduleSpy ) . toHaveBeenCalledWith ( 'memoryEvent' ) ;
409+ } ) ;
410+
411+ it ( 'updates instances on invalidated event' , async ( ) => {
412+ const sessionA = debugSessionFactory ( 's1' , [ ] , 'stopped' ) ;
413+
414+ ( controller as unknown as { _activeSession ?: Session } ) . _activeSession = sessionA ;
415+
416+ const scheduleSpy = jest
417+ . spyOn ( controller as unknown as { schedulePendingUpdate : ( reason : UpdateReason ) => void } , 'schedulePendingUpdate' )
418+ . mockImplementation ( ( ) => undefined ) ;
419+
420+ const handleOnInvalidated = ( controller as unknown as { handleOnInvalidated : ( s : Session ) => Promise < void > } ) . handleOnInvalidated . bind ( controller ) ;
421+ await handleOnInvalidated ( sessionA ) ;
422+
423+ expect ( scheduleSpy ) . toHaveBeenCalledWith ( 'invalidated' ) ;
424+ } ) ;
425+
354426 it ( 'does not update active session when stack item matches the active session' , async ( ) => {
355427 const sessionA = debugSessionFactory ( 's1' ) ;
356428 const updateSpy = jest . fn ( ) ;
0 commit comments