Merge changes If7cb1cbb,I1d09ac01 into main
* changes: Adds more data points for benchmarking tests Move test zip file to assets
This commit is contained in:
@@ -29,6 +29,7 @@ android_test {
|
||||
"src/**/*.kt",
|
||||
"src/**/*.aidl",
|
||||
],
|
||||
asset_dirs: ["assets"],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"mockito-target-minus-junit4",
|
||||
|
||||
BIN
tests/benchmark/assets/dataset/A052701.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052701.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052801.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052801.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052802.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052802.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052803.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052803.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052804.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052804.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052901.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052901.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A052902.zip
Normal file
BIN
tests/benchmark/assets/dataset/A052902.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053001.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053001.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053002.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053002.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053003.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053003.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053004.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053004.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053005.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053005.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053006.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053006.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053007.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053007.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053101.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053101.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053102.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053102.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053103.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053103.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A053104.zip
Normal file
BIN
tests/benchmark/assets/dataset/A053104.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A060101.zip
Normal file
BIN
tests/benchmark/assets/dataset/A060101.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A060102.zip
Normal file
BIN
tests/benchmark/assets/dataset/A060102.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A060201.zip
Normal file
BIN
tests/benchmark/assets/dataset/A060201.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/A060202.zip
Normal file
BIN
tests/benchmark/assets/dataset/A060202.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B053001.zip
Normal file
BIN
tests/benchmark/assets/dataset/B053001.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B053002.zip
Normal file
BIN
tests/benchmark/assets/dataset/B053002.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060101.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060101.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060201.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060201.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060202.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060202.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060203.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060203.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060204.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060204.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060205.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060205.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060206.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060206.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/B060207.zip
Normal file
BIN
tests/benchmark/assets/dataset/B060207.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060101.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060101.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060102.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060102.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060103.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060103.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060104.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060104.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060105.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060105.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060106.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060106.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060107.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060107.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060108.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060108.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060109.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060109.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060110.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060110.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060111.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060111.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060112.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060112.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060113.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060113.zip
Normal file
Binary file not shown.
BIN
tests/benchmark/assets/dataset/C060114.zip
Normal file
BIN
tests/benchmark/assets/dataset/C060114.zip
Normal file
Binary file not shown.
Binary file not shown.
@@ -20,10 +20,9 @@ import android.net.NetworkStats.NonMonotonicObserver
|
||||
import android.net.NetworkStatsCollection
|
||||
import android.net.netstats.NetworkStatsDataMigrationUtils.PREFIX_UID
|
||||
import android.os.DropBoxManager
|
||||
import androidx.test.InstrumentationRegistry
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.android.internal.util.FileRotator
|
||||
import com.android.internal.util.FileRotator.Reader
|
||||
import com.android.server.connectivity.benchmarktests.R
|
||||
import com.android.server.net.NetworkStatsRecorder
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.DataInputStream
|
||||
@@ -44,23 +43,22 @@ class NetworkStatsTest {
|
||||
companion object {
|
||||
private val DEFAULT_BUFFER_SIZE = 8192
|
||||
private val FILE_CACHE_WARM_UP_REPEAT_COUNT = 10
|
||||
private val TEST_REPEAT_COUNT = 10
|
||||
private val UID_COLLECTION_BUCKET_DURATION_MS = TimeUnit.HOURS.toMillis(2)
|
||||
private val UID_RECORDER_ROTATE_AGE_MS = TimeUnit.DAYS.toMillis(15)
|
||||
private val UID_RECORDER_DELETE_AGE_MS = TimeUnit.DAYS.toMillis(90)
|
||||
private val TEST_DATASET_SUBFOLDER = "dataset/"
|
||||
|
||||
private val testFilesDir by lazy {
|
||||
// These file generated by using real user dataset which has many uid records
|
||||
// and agreed to share the dataset for testing purpose. These dataset can be
|
||||
// extracted from rooted devices by using
|
||||
// "adb pull /data/misc/apexdata/com.android.tethering/netstats" command.
|
||||
val zipInputStream =
|
||||
ZipInputStream(getInputStreamForResource(R.raw.netstats_many_uids_zip))
|
||||
unzipToTempDir(zipInputStream)
|
||||
}
|
||||
|
||||
private val uidTestFiles: List<File> by lazy {
|
||||
getSortedListForPrefix(testFilesDir, "uid")
|
||||
// These files are generated by using real user dataset which has many uid records
|
||||
// and agreed to share the dataset for testing purpose. These dataset can be
|
||||
// extracted from rooted devices by using
|
||||
// "adb pull /data/misc/apexdata/com.android.tethering/netstats" command.
|
||||
private val testFilesAssets by lazy {
|
||||
val zipFiles = context.assets.list(TEST_DATASET_SUBFOLDER)!!.asList()
|
||||
zipFiles.map {
|
||||
val zipInputStream =
|
||||
ZipInputStream((TEST_DATASET_SUBFOLDER + it).toAssetInputStream())
|
||||
File(unzipToTempDir(zipInputStream), "netstats")
|
||||
}
|
||||
}
|
||||
|
||||
// Test results shows the test cases who read the file first will take longer time to
|
||||
@@ -72,24 +70,34 @@ class NetworkStatsTest {
|
||||
@BeforeClass
|
||||
fun setUpOnce() {
|
||||
repeat(FILE_CACHE_WARM_UP_REPEAT_COUNT) {
|
||||
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
||||
for (file in uidTestFiles) {
|
||||
readFile(file, collection)
|
||||
testFilesAssets.forEach {
|
||||
val uidTestFiles = getSortedListForPrefix(it, "uid")
|
||||
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
||||
for (file in uidTestFiles) {
|
||||
readFile(file, collection)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getInputStreamForResource(resourceId: Int): DataInputStream =
|
||||
DataInputStream(
|
||||
InstrumentationRegistry.getContext()
|
||||
.getResources().openRawResource(resourceId)
|
||||
)
|
||||
val context get() = InstrumentationRegistry.getInstrumentation().getContext()
|
||||
private fun String.toAssetInputStream() = DataInputStream(context.assets.open(this))
|
||||
|
||||
private fun unzipToTempDir(zis: ZipInputStream): File {
|
||||
val statsDir =
|
||||
Files.createTempDirectory(NetworkStatsTest::class.simpleName).toFile()
|
||||
generateSequence { zis.nextEntry }.forEach { entry ->
|
||||
FileOutputStream(File(statsDir, entry.name)).use {
|
||||
val entryFile = File(statsDir, entry.name)
|
||||
if (entry.isDirectory) {
|
||||
entryFile.mkdirs()
|
||||
return@forEach
|
||||
}
|
||||
|
||||
// Make sure all folders exists. There is no guarantee anywhere.
|
||||
entryFile.parentFile!!.mkdirs()
|
||||
|
||||
// If the entry is a file extract it.
|
||||
FileOutputStream(entryFile).use {
|
||||
zis.copyTo(it, DEFAULT_BUFFER_SIZE)
|
||||
}
|
||||
}
|
||||
@@ -99,7 +107,7 @@ class NetworkStatsTest {
|
||||
// List [xt|uid|uid_tag].<start>-<end> files under the given directory.
|
||||
private fun getSortedListForPrefix(statsDir: File, prefix: String): List<File> {
|
||||
assertTrue(statsDir.exists())
|
||||
return statsDir.list() { dir, name -> name.startsWith("$prefix.") }
|
||||
return statsDir.list { _, name -> name.startsWith("$prefix.") }
|
||||
.orEmpty()
|
||||
.map { it -> File(statsDir, it) }
|
||||
.sorted()
|
||||
@@ -115,7 +123,8 @@ class NetworkStatsTest {
|
||||
fun testReadCollection_manyUids() {
|
||||
// The file cache is warmed up by the @BeforeClass method, so now the test can repeat
|
||||
// this a number of time to have a stable number.
|
||||
repeat(TEST_REPEAT_COUNT) {
|
||||
testFilesAssets.forEach {
|
||||
val uidTestFiles = getSortedListForPrefix(it, "uid")
|
||||
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
||||
for (file in uidTestFiles) {
|
||||
readFile(file, collection)
|
||||
@@ -127,10 +136,10 @@ class NetworkStatsTest {
|
||||
fun testReadFromRecorder_manyUids() {
|
||||
val mockObserver = mock<NonMonotonicObserver<String>>()
|
||||
val mockDropBox = mock<DropBoxManager>()
|
||||
repeat(TEST_REPEAT_COUNT) {
|
||||
testFilesAssets.forEach {
|
||||
val recorder = NetworkStatsRecorder(
|
||||
FileRotator(
|
||||
testFilesDir, PREFIX_UID, UID_RECORDER_ROTATE_AGE_MS, UID_RECORDER_DELETE_AGE_MS
|
||||
it, PREFIX_UID, UID_RECORDER_ROTATE_AGE_MS, UID_RECORDER_DELETE_AGE_MS
|
||||
),
|
||||
mockObserver,
|
||||
mockDropBox,
|
||||
|
||||
Reference in New Issue
Block a user