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/**/*.kt",
|
||||||
"src/**/*.aidl",
|
"src/**/*.aidl",
|
||||||
],
|
],
|
||||||
|
asset_dirs: ["assets"],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
"androidx.test.rules",
|
"androidx.test.rules",
|
||||||
"mockito-target-minus-junit4",
|
"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.NetworkStatsCollection
|
||||||
import android.net.netstats.NetworkStatsDataMigrationUtils.PREFIX_UID
|
import android.net.netstats.NetworkStatsDataMigrationUtils.PREFIX_UID
|
||||||
import android.os.DropBoxManager
|
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
|
||||||
import com.android.internal.util.FileRotator.Reader
|
import com.android.internal.util.FileRotator.Reader
|
||||||
import com.android.server.connectivity.benchmarktests.R
|
|
||||||
import com.android.server.net.NetworkStatsRecorder
|
import com.android.server.net.NetworkStatsRecorder
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
import java.io.DataInputStream
|
import java.io.DataInputStream
|
||||||
@@ -44,23 +43,22 @@ class NetworkStatsTest {
|
|||||||
companion object {
|
companion object {
|
||||||
private val DEFAULT_BUFFER_SIZE = 8192
|
private val DEFAULT_BUFFER_SIZE = 8192
|
||||||
private val FILE_CACHE_WARM_UP_REPEAT_COUNT = 10
|
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_COLLECTION_BUCKET_DURATION_MS = TimeUnit.HOURS.toMillis(2)
|
||||||
private val UID_RECORDER_ROTATE_AGE_MS = TimeUnit.DAYS.toMillis(15)
|
private val UID_RECORDER_ROTATE_AGE_MS = TimeUnit.DAYS.toMillis(15)
|
||||||
private val UID_RECORDER_DELETE_AGE_MS = TimeUnit.DAYS.toMillis(90)
|
private val UID_RECORDER_DELETE_AGE_MS = TimeUnit.DAYS.toMillis(90)
|
||||||
|
private val TEST_DATASET_SUBFOLDER = "dataset/"
|
||||||
|
|
||||||
private val testFilesDir by lazy {
|
// These files are generated by using real user dataset which has many uid records
|
||||||
// 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
|
// and agreed to share the dataset for testing purpose. These dataset can be
|
||||||
// extracted from rooted devices by using
|
// extracted from rooted devices by using
|
||||||
// "adb pull /data/misc/apexdata/com.android.tethering/netstats" command.
|
// "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 =
|
val zipInputStream =
|
||||||
ZipInputStream(getInputStreamForResource(R.raw.netstats_many_uids_zip))
|
ZipInputStream((TEST_DATASET_SUBFOLDER + it).toAssetInputStream())
|
||||||
unzipToTempDir(zipInputStream)
|
File(unzipToTempDir(zipInputStream), "netstats")
|
||||||
}
|
}
|
||||||
|
|
||||||
private val uidTestFiles: List<File> by lazy {
|
|
||||||
getSortedListForPrefix(testFilesDir, "uid")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test results shows the test cases who read the file first will take longer time to
|
// Test results shows the test cases who read the file first will take longer time to
|
||||||
@@ -72,24 +70,34 @@ class NetworkStatsTest {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
fun setUpOnce() {
|
fun setUpOnce() {
|
||||||
repeat(FILE_CACHE_WARM_UP_REPEAT_COUNT) {
|
repeat(FILE_CACHE_WARM_UP_REPEAT_COUNT) {
|
||||||
|
testFilesAssets.forEach {
|
||||||
|
val uidTestFiles = getSortedListForPrefix(it, "uid")
|
||||||
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
||||||
for (file in uidTestFiles) {
|
for (file in uidTestFiles) {
|
||||||
readFile(file, collection)
|
readFile(file, collection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getInputStreamForResource(resourceId: Int): DataInputStream =
|
val context get() = InstrumentationRegistry.getInstrumentation().getContext()
|
||||||
DataInputStream(
|
private fun String.toAssetInputStream() = DataInputStream(context.assets.open(this))
|
||||||
InstrumentationRegistry.getContext()
|
|
||||||
.getResources().openRawResource(resourceId)
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun unzipToTempDir(zis: ZipInputStream): File {
|
private fun unzipToTempDir(zis: ZipInputStream): File {
|
||||||
val statsDir =
|
val statsDir =
|
||||||
Files.createTempDirectory(NetworkStatsTest::class.simpleName).toFile()
|
Files.createTempDirectory(NetworkStatsTest::class.simpleName).toFile()
|
||||||
generateSequence { zis.nextEntry }.forEach { entry ->
|
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)
|
zis.copyTo(it, DEFAULT_BUFFER_SIZE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,7 +107,7 @@ class NetworkStatsTest {
|
|||||||
// List [xt|uid|uid_tag].<start>-<end> files under the given directory.
|
// List [xt|uid|uid_tag].<start>-<end> files under the given directory.
|
||||||
private fun getSortedListForPrefix(statsDir: File, prefix: String): List<File> {
|
private fun getSortedListForPrefix(statsDir: File, prefix: String): List<File> {
|
||||||
assertTrue(statsDir.exists())
|
assertTrue(statsDir.exists())
|
||||||
return statsDir.list() { dir, name -> name.startsWith("$prefix.") }
|
return statsDir.list { _, name -> name.startsWith("$prefix.") }
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
.map { it -> File(statsDir, it) }
|
.map { it -> File(statsDir, it) }
|
||||||
.sorted()
|
.sorted()
|
||||||
@@ -115,7 +123,8 @@ class NetworkStatsTest {
|
|||||||
fun testReadCollection_manyUids() {
|
fun testReadCollection_manyUids() {
|
||||||
// The file cache is warmed up by the @BeforeClass method, so now the test can repeat
|
// 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.
|
// 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)
|
val collection = NetworkStatsCollection(UID_COLLECTION_BUCKET_DURATION_MS)
|
||||||
for (file in uidTestFiles) {
|
for (file in uidTestFiles) {
|
||||||
readFile(file, collection)
|
readFile(file, collection)
|
||||||
@@ -127,10 +136,10 @@ class NetworkStatsTest {
|
|||||||
fun testReadFromRecorder_manyUids() {
|
fun testReadFromRecorder_manyUids() {
|
||||||
val mockObserver = mock<NonMonotonicObserver<String>>()
|
val mockObserver = mock<NonMonotonicObserver<String>>()
|
||||||
val mockDropBox = mock<DropBoxManager>()
|
val mockDropBox = mock<DropBoxManager>()
|
||||||
repeat(TEST_REPEAT_COUNT) {
|
testFilesAssets.forEach {
|
||||||
val recorder = NetworkStatsRecorder(
|
val recorder = NetworkStatsRecorder(
|
||||||
FileRotator(
|
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,
|
mockObserver,
|
||||||
mockDropBox,
|
mockDropBox,
|
||||||
|
|||||||
Reference in New Issue
Block a user