Add test to the MapParser class in OTA_analyzer.
Add unit test to the MapParser class in map_parser.js. Please refer to this CL for the original class definition: https://android-review.googlesource.com/c/platform/development/+/1760909 Test: npm run test:unit Change-Id: I2d640e9c5e27c0a012e32b4be09348034b67b235
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
|
const defaults = require('jest-config')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
preset: '@vue/cli-plugin-unit-jest',
|
preset: '@vue/cli-plugin-unit-jest',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.vue$': 'vue-jest'
|
'^.+\\.vue$': 'vue-jest'
|
||||||
|
},
|
||||||
|
globals: {
|
||||||
|
...defaults.globals,
|
||||||
|
crypto: require('crypto'),
|
||||||
|
TextEncoder: require('util').TextEncoder,
|
||||||
|
TextDecoder: require('util').TextDecoder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
63
tools/ota_analysis/src/__tests__/map_parser.test.js
Normal file
63
tools/ota_analysis/src/__tests__/map_parser.test.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import * as zip from '@zip.js/zip.js/dist/zip-full.min.js'
|
||||||
|
import { MapParser } from '@/services/map_parser.js'
|
||||||
|
|
||||||
|
var targetFile = new Blob()
|
||||||
|
var mapParser
|
||||||
|
// Please refer to system_test.map for more details.
|
||||||
|
const systemMap = [
|
||||||
|
'//system/apex/com.android.test1.apex',
|
||||||
|
'//system/apex/com.android.test2.apex',
|
||||||
|
'//system/apex/com.android.test2.apex',
|
||||||
|
'//system/apex/com.android.test2.apex',
|
||||||
|
'//system/apex/com.android.test3.apk',
|
||||||
|
'//system/apex/com.android.test1.apex',
|
||||||
|
'//system/apex/com.android.test1.apex',
|
||||||
|
'//system/apex/com.android.test1.apex',
|
||||||
|
'//system/apex/com.android.test1.apex',
|
||||||
|
'unknown',
|
||||||
|
'//init.environ.rc'
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a virtual Android build which only contains a .map file
|
||||||
|
*/
|
||||||
|
beforeAll(async () => {
|
||||||
|
// web worker is not supported by zip.js, turn it off
|
||||||
|
zip.configure({
|
||||||
|
useWebWorkers: false,
|
||||||
|
})
|
||||||
|
// Use system_test.map as a virtual map file
|
||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
const file = path.join(__dirname, "./", "system_test.map")
|
||||||
|
const text = fs.readFileSync(file, 'utf-8', (err, data) => data)
|
||||||
|
const blobWriter = new zip.BlobWriter("application/zip")
|
||||||
|
const writer = new zip.ZipWriter(blobWriter)
|
||||||
|
await writer.add("IMAGES/system_test.map", new zip.TextReader(text))
|
||||||
|
await writer.close()
|
||||||
|
targetFile = blobWriter.getData()
|
||||||
|
mapParser = new MapParser(targetFile)
|
||||||
|
await mapParser.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Initialize a map parser instance.', () => {
|
||||||
|
expect(mapParser.mapFiles.keys().next().value).toEqual('system_test')
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Establish a map of system file.', async () => {
|
||||||
|
await mapParser.add('system_test', 11)
|
||||||
|
expect(mapParser.maps.get('system_test')).toEqual(systemMap)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Query the map of system file.', async () => {
|
||||||
|
await mapParser.add('system_test', 11)
|
||||||
|
var queryExtents = []
|
||||||
|
for (let i = 0; i < 11; i++)
|
||||||
|
queryExtents.push(new Object({
|
||||||
|
startBlock: i,
|
||||||
|
// The number of blocks does not matter, because we only query the
|
||||||
|
// starting block.
|
||||||
|
numBlocks: 0
|
||||||
|
}))
|
||||||
|
expect(mapParser.query('system_test', queryExtents)).toEqual(systemMap)
|
||||||
|
})
|
||||||
4
tools/ota_analysis/src/__tests__/system_test.map
Normal file
4
tools/ota_analysis/src/__tests__/system_test.map
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
//init.environ.rc 10
|
||||||
|
//system/apex/com.android.test1.apex 5-6 0 0 7-8
|
||||||
|
//system/apex/com.android.test2.apex 1-3
|
||||||
|
//system/apex/com.android.test3.apk 4
|
||||||
Reference in New Issue
Block a user