11/**
2- * Copyright 2025 Arm Limited
2+ * Copyright 2025-2026 Arm Limited
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1414 * limitations under the License.
1515 */
1616
17+ import * as path from 'path' ;
1718import { CbuildRunReader } from './cbuild-run-reader' ;
1819
1920const TEST_CBUILD_RUN_FILE = 'test-data/multi-core.cbuild-run.yml' ; // Relative to repo root
2021const TEST_FILE_PATH = 'test-data/fileReaderTest.txt' ; // Relative to repo root
22+ const PACK_ROOT = '/my/pack/root' ;
23+
24+ const EXPECTED_CUSTOM_SVD = path . resolve ( path . dirname ( TEST_CBUILD_RUN_FILE ) , '../../MyDevice/multi-core-custom.svd' ) ;
25+ const EXPECTED_CUSTOM_SCVD = path . resolve ( path . dirname ( TEST_CBUILD_RUN_FILE ) , '../../MyDevice/multi-core-custom.scvd' ) ;
26+
2127
2228describe ( 'CbuildRunReader' , ( ) => {
2329
@@ -61,6 +67,7 @@ describe('CbuildRunReader', () => {
6167 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd' ,
6268 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd' ,
6369 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd' ,
70+ EXPECTED_CUSTOM_SVD ,
6471 ]
6572 } ,
6673 {
@@ -69,6 +76,7 @@ describe('CbuildRunReader', () => {
6976 expectedSvdPaths : [
7077 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core0.svd' ,
7178 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd' ,
79+ EXPECTED_CUSTOM_SVD ,
7280 ]
7381 } ,
7482 {
@@ -77,15 +85,19 @@ describe('CbuildRunReader', () => {
7785 expectedSvdPaths : [
7886 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd' ,
7987 '/my/pack/root/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd' ,
88+ EXPECTED_CUSTOM_SVD ,
8089 ]
8190 } ,
8291 ] ) ( 'returns SVD file path ($info)' , async ( { pname, expectedSvdPaths } ) => {
8392 await cbuildRunReader . parse ( TEST_CBUILD_RUN_FILE ) ;
8493 const svdFilePaths = cbuildRunReader . getSvdFilePaths ( '/my/pack/root' , pname ) ;
85- expect ( svdFilePaths . length ) . toEqual ( svdFilePaths . length ) ;
94+ expect ( svdFilePaths . length ) . toEqual ( expectedSvdPaths . length ) ;
8695 for ( let i = 0 ; i < svdFilePaths . length ; i ++ ) {
8796 // eslint-disable-next-line security/detect-object-injection
88- expect ( expectedSvdPaths [ i ] ) . toEqual ( svdFilePaths [ i ] ) ;
97+ const expectedPath = path . normalize ( path . resolve ( expectedSvdPaths [ i ] ) ) ;
98+ // eslint-disable-next-line security/detect-object-injection
99+ const actualPath = path . normalize ( path . resolve ( svdFilePaths [ i ] ) ) ;
100+ expect ( expectedPath ) . toEqual ( actualPath ) ;
89101 }
90102 } ) ;
91103
@@ -111,11 +123,28 @@ describe('CbuildRunReader', () => {
111123 const systemDescriptions = cbuildRun ?. [ 'system-descriptions' ] ;
112124 expect ( systemDescriptions ) . toBeDefined ( ) ;
113125 const svdPaths = cbuildRunReader . getSvdFilePaths ( '' , 'Core1' ) ;
126+ expect ( svdPaths . map ( path . normalize ) ) . toEqual ( [
127+ path . normalize (
128+ path . resolve ( path . dirname ( TEST_CBUILD_RUN_FILE ) , '${CMSIS_PACK_ROOT}' , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SVD' , 'MyDevice_Core1.svd' )
129+ ) ,
130+ path . normalize (
131+ path . resolve ( path . dirname ( TEST_CBUILD_RUN_FILE ) , '${CMSIS_PACK_ROOT}' , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SVD' , 'MyDevice_generic.svd' )
132+ ) ,
133+ path . normalize ( EXPECTED_CUSTOM_SVD ) ,
134+ ] ) ;
135+ } ) ;
114136
115- expect ( svdPaths ) . toEqual ( [
116- '${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_Core1.svd' ,
117- '${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SVD/MyDevice_generic.svd'
137+ it ( 'includes descriptors without pname when filtering by pname (SVD)' , async ( ) => {
138+ await cbuildRunReader . parse ( TEST_CBUILD_RUN_FILE ) ;
139+ const cbuildRun = ( cbuildRunReader as unknown as { cbuildRun ?: { [ 'system-descriptions' ] ?: Array < { file : string ; type : string ; pname ?: string } > } } ) . cbuildRun ;
140+ const systemDescriptions = cbuildRun ?. [ 'system-descriptions' ] ;
141+ expect ( systemDescriptions ) . toBeDefined ( ) ;
142+ const svdPaths = cbuildRunReader . getSvdFilePaths ( PACK_ROOT , 'Core1' ) ;
118143
144+ expect ( svdPaths . map ( path . normalize ) ) . toEqual ( [
145+ path . normalize ( path . resolve ( PACK_ROOT , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SVD' , 'MyDevice_Core1.svd' ) ) ,
146+ path . normalize ( path . resolve ( PACK_ROOT , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SVD' , 'MyDevice_generic.svd' ) ) ,
147+ path . normalize ( EXPECTED_CUSTOM_SVD ) ,
119148 ] ) ;
120149 } ) ;
121150
@@ -124,12 +153,29 @@ describe('CbuildRunReader', () => {
124153 const cbuildRun = ( cbuildRunReader as unknown as { cbuildRun ?: { [ 'system-descriptions' ] ?: Array < { file : string ; type : string ; pname ?: string } > } } ) . cbuildRun ;
125154 const systemDescriptions = cbuildRun ?. [ 'system-descriptions' ] ?? [ ] ;
126155 expect ( systemDescriptions ) . toBeDefined ( ) ;
127- const scvdPaths = cbuildRunReader . getScvdFilePaths ( '' , 'Core1' ) ;
156+ const scvdPaths = cbuildRunReader . getScvdFilePaths ( PACK_ROOT , 'Core1' ) ;
128157
129158 expect ( scvdPaths ) . toEqual ( [
130- '${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/MySoftware_component.scvd' ,
131- '${CMSIS_PACK_ROOT}/MyVendor/MyDevice/1.0.0/Debug/SCVD/Core1.scvd' ,
159+ path . normalize ( path . resolve ( PACK_ROOT , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SCVD' , 'MySoftware_component.scvd' ) ) ,
160+ path . normalize ( EXPECTED_CUSTOM_SCVD ) ,
161+ path . normalize ( path . resolve ( PACK_ROOT , 'MyVendor' , 'MyDevice' , '1.0.0' , 'Debug' , 'SCVD' , 'Core1.scvd' ) ) ,
132162 ] ) ;
133163 } ) ;
164+
165+ it ( 'resolves relative SVD paths relative to the cbuild-run.yml file location' , async ( ) => {
166+ await cbuildRunReader . parse ( TEST_CBUILD_RUN_FILE ) ;
167+ const svdFilePaths = cbuildRunReader . getSvdFilePaths ( PACK_ROOT ) ;
168+ const expectedTail = path . normalize ( path . join ( 'MyDevice' , 'multi-core-custom.svd' ) ) ;
169+ const resolvedCustom = svdFilePaths . find ( ( p : string ) => p . endsWith ( expectedTail ) ) ;
170+ expect ( resolvedCustom ) . toEqual ( path . normalize ( EXPECTED_CUSTOM_SVD ) ) ;
171+ } ) ;
172+
173+ it ( 'resolves relative SCVD paths relative to the cbuild-run.yml file location' , async ( ) => {
174+ await cbuildRunReader . parse ( TEST_CBUILD_RUN_FILE ) ;
175+ const scvdFilePaths = cbuildRunReader . getScvdFilePaths ( PACK_ROOT ) ;
176+ const expectedTail = path . normalize ( path . join ( 'MyDevice' , 'multi-core-custom.scvd' ) ) ;
177+ const resolvedCustom = scvdFilePaths . find ( ( p : string ) => p . endsWith ( expectedTail ) ) ;
178+ expect ( resolvedCustom ) . toEqual ( path . normalize ( EXPECTED_CUSTOM_SCVD ) ) ;
179+ } ) ;
134180 } ) ;
135181} ) ;
0 commit comments