Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_packages_modules_Connectivity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LMODroid
platform_packages_modules_Connectivity
Commits
87d66ebd
Commit
87d66ebd
authored
1 year ago
by
Treehugger Robot
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "Address comments at aosp/2658225" into main
parents
865bfaca
a0991ebb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/benchmark/src/android/net/netstats/benchmarktests/NetworkStatsTest.kt
+27
-22
27 additions, 22 deletions
...c/android/net/netstats/benchmarktests/NetworkStatsTest.kt
with
27 additions
and
22 deletions
tests/benchmark/src/android/net/netstats/benchmarktests/NetworkStatsTest.kt
+
27
−
22
View file @
87d66ebd
...
...
@@ -28,7 +28,6 @@ import com.android.server.net.NetworkStatsRecorder
import
java.io.BufferedInputStream
import
java.io.DataInputStream
import
java.io.File
import
java.io.FileInputStream
import
java.io.FileOutputStream
import
java.nio.file.Files
import
java.util.concurrent.TimeUnit
...
...
@@ -44,6 +43,8 @@ import org.mockito.Mockito.mock
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
)
...
...
@@ -63,14 +64,14 @@ class NetworkStatsTest {
}
// Test results shows the test cases who read the file first will take longer time to
// execute, and reading time getting shorter each time
. Read files several times prior to
//
tests to minimize the impact. This cannot live in setUp() since the time
//
spent on the file reading will be attributed to
the time spent on the
individual
// test case.
// execute, and reading time getting shorter each time
due to file caching mechanism.
//
Read files several times prior to tests to minimize the impact.
//
This cannot live in setUp() since
the time spent on the
file reading will be
//
attributed to the time spent on the individual
test case.
@JvmStatic
@BeforeClass
fun
setUpOnce
()
{
for
(
i
in
1
..
10
)
{
repeat
(
FILE_CACHE_WARM_UP_REPEAT_COUNT
)
{
val
collection
=
NetworkStatsCollection
(
UID_COLLECTION_BUCKET_DURATION_MS
)
for
(
file
in
uidTestFiles
)
{
readFile
(
file
,
collection
)
...
...
@@ -78,20 +79,19 @@ class NetworkStatsTest {
}
}
private
fun
getInputStreamForResource
(
resourceId
:
Int
):
DataInputStream
{
return
DataInputStream
(
private
fun
getInputStreamForResource
(
resourceId
:
Int
):
DataInputStream
=
DataInputStream
(
InstrumentationRegistry
.
getContext
()
.
getResources
().
openRawResource
(
resourceId
)
)
}
private
fun
unzipToTempDir
(
zis
:
ZipInputStream
):
File
{
val
statsDir
=
Files
.
createTempDirectory
(
NetworkStatsTest
::
class
.
simpleName
).
toFile
()
while
(
true
)
{
val
entryName
=
zis
.
nextE
ntry
?
.
name
?:
break
val
file
=
File
(
statsDir
,
entryName
)
FileOutputStream
(
file
).
use
{
zis
.
copyTo
(
it
,
DEFAULT_BUFFER_SIZE
)
}
generateSequence
{
zis
.
nextEntry
}.
forEach
{
entry
->
FileOutputStream
(
File
(
statsDir
,
e
ntry
.
name
)).
use
{
zis
.
copyTo
(
it
,
DEFAULT_BUFFER_SIZE
)
}
}
return
statsDir
}
...
...
@@ -99,20 +99,23 @@ 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
()
?:
arrayOf
()).
mapNotNull
{
if
(
it
.
startsWith
(
"$prefix."
))
File
(
statsDir
,
it
)
else
null
}.
sorted
()
return
statsDir
.
list
()
{
dir
,
name
->
name
.
startsWith
(
"$prefix."
)
}
.
orEmpty
()
.
map
{
it
->
File
(
statsDir
,
it
)
}
.
sorted
()
}
private
fun
readFile
(
file
:
File
,
reader
:
Reader
)
=
BufferedInputStream
(
F
ile
I
nputStream
(
file
)).
use
{
BufferedInputStream
(
f
ile
.
i
nputStream
()).
use
{
reader
.
read
(
it
)
}
}
@Test
fun
testReadCollection_manyUids
()
{
for
(
i
in
1
..
10
)
{
// 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
)
{
val
collection
=
NetworkStatsCollection
(
UID_COLLECTION_BUCKET_DURATION_MS
)
for
(
file
in
uidTestFiles
)
{
readFile
(
file
,
collection
)
...
...
@@ -122,13 +125,15 @@ class NetworkStatsTest {
@Test
fun
testReadFromRecorder_manyUids
()
{
for
(
i
in
1
..
10
)
{
val
mockObserver
=
mock
<
NonMonotonicObserver
<
String
>>()
val
mockDropBox
=
mock
<
DropBoxManager
>()
repeat
(
TEST_REPEAT_COUNT
)
{
val
recorder
=
NetworkStatsRecorder
(
FileRotator
(
testFilesDir
,
PREFIX_UID
,
UID_RECORDER_ROTATE_AGE_MS
,
UID_RECORDER_DELETE_AGE_MS
),
mock
<
NonMonotonicObserver
<
String
>>()
,
mock
(
DropBox
Manager
::
class
.
java
)
,
mock
Observer
,
mockDropBox
,
PREFIX_UID
,
UID_COLLECTION_BUCKET_DURATION_MS
,
false
/* includeTags */
,
...
...
@@ -138,5 +143,5 @@ class NetworkStatsTest {
}
}
inline
fun
<
reified
T
:
Any
>
mock
():
T
=
mock
(
T
::
class
.
java
)
inline
fun
<
reified
T
>
mock
():
T
=
mock
(
T
::
class
.
java
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment