Skip to content

Commit

Permalink
Test: Copy scanner fixtures instead of managing a layer
Browse files Browse the repository at this point in the history
This optimization will cut down parsing time and reuse the cache.

.bbappend are not included within poky/meta. We actually test bbappends
separately with busybox. They do not need to be tested again here.
  • Loading branch information
deribaucourt committed May 31, 2024
1 parent 77cfec7 commit 99474ac
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 44 deletions.
37 changes: 19 additions & 18 deletions client/src/__tests__/unit-tests/driver/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* ------------------------------------------------------------------------------------------ */

import path from 'path'
import fs from 'fs'
import { BitBakeProjectScanner } from '../../../driver/BitBakeProjectScanner'
import { BitbakeDriver } from '../../../driver/BitbakeDriver'
import { BITBAKE_TIMEOUT } from '../../../utils/ProcessUtils'
import { mockVscodeEvents } from '../../utils/vscodeMock'
import { addLayer, removeLayer } from '../../utils/bitbake'
import { importRecipe, removeRecipe } from '../../utils/bitbake'
import { logger } from '../../../lib/src/utils/OutputLogger'

let bitBakeProjectScanner: BitBakeProjectScanner
Expand Down Expand Up @@ -39,23 +40,31 @@ describe('BitBakeProjectScanner', () => {
})
mockVscodeEvents()
bitBakeProjectScanner.bitbakeDriver.spawnBitbakeProcess('devtool modify busybox').then((child) => {
child.onExit((event) => {
child.onExit(async (event) => {
expect(event.exitCode).toBe(0)
addLayer(
path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions'),
path.resolve(__dirname, '../../../../../integration-tests/project-folder/build'))
void bitBakeProjectScanner.rescanProject()
const pokyPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/poky')
const fixtureVersionPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions/recipes-fixtures/fixture-version')
const recipes = fs.readdirSync(fixtureVersionPath)
for (const recipe of recipes) {
await importRecipe(path.join(fixtureVersionPath, recipe), pokyPath)
}
const localConfPath = path.join(pathToBuildFolder, 'conf', 'local.conf')
fs.appendFileSync(localConfPath, 'PREFERRED_VERSION_fixture-version = "0.2.0"\n')
await bitBakeProjectScanner.rescanProject()
})
}, (error) => {
throw error
})
}, BITBAKE_TIMEOUT)

afterAll((done) => {
removeLayer(
path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions'),
path.resolve(__dirname, '../../../../../integration-tests/project-folder/build'))
bitBakeProjectScanner.bitbakeDriver.spawnBitbakeProcess('devtool reset busybox').then((child) => {
const pokyPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/poky')
const fixtureVersionPath = path.resolve(__dirname, '../../../../../integration-tests/project-folder/sources/meta-fixtures-versions/recipes-fixtures/fixture-version')
const recipes = fs.readdirSync(fixtureVersionPath)
for (const recipe of recipes) {
void removeRecipe(path.join(fixtureVersionPath, recipe), pokyPath)
}
child.onExit(() => {
done()
})
Expand Down Expand Up @@ -159,15 +168,7 @@ describe('BitBakeProjectScanner', () => {
version: '0.2.0',
path: expect.objectContaining({
base: 'fixture-version_0.2.0.bb'
}),
appends: expect.arrayContaining([
expect.objectContaining({
base: 'fixture-version_%.bbappend'
}),
expect.objectContaining({
base: 'fixture-version_0.2.0.bbappend'
})
])
})
})
)
})
Expand Down
21 changes: 7 additions & 14 deletions client/src/__tests__/utils/bitbake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@
import path from 'path'
import fs from 'fs'

// This is similar to the integration-tests addLayer() but doesn't use the VSCode API
export function addLayer (layer: string, buildFolder: string): void {
const bblayersConf = path.resolve(buildFolder, 'conf/bblayers.conf')
const bblayersConfContent = fs.readFileSync(bblayersConf)
let fileContent = bblayersConfContent.toString()
fileContent += `\nBBLAYERS+="${layer}"\n`
fs.writeFileSync(bblayersConf, fileContent)
/// Copy a recipe into poky
export async function importRecipe (recipePath: string, pokyPath: string): Promise<void> {
const pokyDestinationPath = path.resolve(pokyPath, 'meta/recipes-core/base-files', path.basename(recipePath))
await fs.promises.copyFile(recipePath, pokyDestinationPath)
}

// This is similar to the integration-tests removeLayer() but doesn't use the VSCode API
export function removeLayer (layer: string, buildFolder: string): void {
const bblayersConf = path.resolve(buildFolder, 'conf/bblayers.conf')
const bblayersConfContent = fs.readFileSync(bblayersConf)
let fileContent = bblayersConfContent.toString()
fileContent = fileContent.replace(`\nBBLAYERS+="${layer}"`, '')
fs.writeFileSync(bblayersConf, fileContent)
export async function removeRecipe (recipePath: string, pokyPath: string): Promise<void> {
const pokyDestinationPath = path.resolve(pokyPath, 'meta/recipes-core/base-files', path.basename(recipePath))
await fs.promises.unlink(pokyDestinationPath)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DESCRIPTION = "Dummy recipe for testing recipe versions"
LICENSE = "MIT"

SRC_URI = ""
PV = "0.1.0"

do_install() {
echo "hello"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DESCRIPTION = "Dummy recipe for testing recipe versions"
LICENSE = "MIT"

SRC_URI = ""
PV = "0.2.0"

do_install() {
echo "hello"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DESCRIPTION = "Dummy recipe for testing recipe versions"
LICENSE = "MIT"

SRC_URI = ""
PV = "0.3.0"

do_install() {
echo "hello"
Expand Down

This file was deleted.

0 comments on commit 99474ac

Please sign in to comment.