Merge "Fix package parsing equivalence test comparisons"

This commit is contained in:
TreeHugger Robot
2020-06-30 17:10:02 +00:00
committed by Android (Google) Code Review
2 changed files with 52 additions and 23 deletions

View File

@@ -96,30 +96,29 @@ open class AndroidPackageParsingTestBase {
anyString(), anyInt())) { true }
}
lateinit var oldPackages: List<PackageParser.Package>
val oldPackages = mutableListOf<PackageParser.Package>()
lateinit var newPackages: List<AndroidPackage>
val newPackages = mutableListOf<AndroidPackage>()
@Suppress("ConstantConditionIf")
@JvmStatic
@BeforeClass
fun setUpPackages() {
this.oldPackages = apks.mapNotNull {
try {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
} catch (ignored: Exception) {
// Parsing issues will be caught by SystemPartitionParseTest
null
}
}
this.newPackages = apks.mapNotNull {
apks.mapNotNull {
try {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false) to
packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
} catch (ignored: Exception) {
// Parsing issues will be caught by SystemPartitionParseTest
// It is intentional that a failure of either call here will result in failing
// both. Having null on one side would mean nothing to compare. Due to the
// nature of presubmit, this may not be caused by the change being tested, so
// it's unhelpful to consider it a failure. Actual parsing issues will be
// reported by SystemPartitionParseTest in postsubmit.
null
}
}.forEach { (old, new) ->
oldPackages += old
newPackages += new
}
if (DUMP_HPROF_TO_EXTERNAL) {

View File

@@ -20,7 +20,11 @@ import android.content.pm.PackageManager
import android.content.pm.PackageParser
import android.platform.test.annotations.Postsubmit
import com.android.server.pm.PackageManagerService
import com.android.server.pm.PackageManagerServiceUtils
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.io.File
/**
* This test parses all the system APKs on the device image to ensure that they succeed.
@@ -34,20 +38,46 @@ import org.junit.Test
@Postsubmit
class SystemPartitionParseTest {
private val APKS = PackageManagerService.SYSTEM_PARTITIONS
.flatMap { listOfNotNull(it.appFolder, it.privAppFolder, it.overlayFolder) }
.flatMap {
it.walkTopDown()
.filter { it.name.endsWith(".apk") }
.toList()
}
.distinct()
private val parser = PackageParser2.forParsingFileWithDefaults()
@get:Rule
val tempFolder = TemporaryFolder()
private fun buildApks(): List<File> {
val files = PackageManagerService.SYSTEM_PARTITIONS
.flatMap { listOfNotNull(it.appFolder, it.privAppFolder, it.overlayFolder) }
.flatMap {
it.listFiles()
?.toList()
?: emptyList()
}
.distinct()
.toMutableList()
val compressedFiles = mutableListOf<File>()
files.removeAll { it ->
it.listFiles()?.toList().orEmpty()
.filter { it.name.endsWith(PackageManagerService.COMPRESSED_EXTENSION) }
.also { compressedFiles.addAll(it) }
.isNotEmpty()
}
compressedFiles.mapTo(files) { input ->
tempFolder.newFolder()
.also {
// Decompress to an APK file inside the temp folder which can be tested.
it.resolve(input.nameWithoutExtension + ".apk")
.apply { PackageManagerServiceUtils.decompressFile(input, this) }
}
}
return files
}
@Test
fun verify() {
val exceptions = APKS
val exceptions = buildApks()
.map {
runCatching {
parser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)