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
60f800c2
Commit
60f800c2
authored
1 year ago
by
Mark Chien
Committed by
Gerrit Code Review
1 year ago
Browse files
Options
Downloads
Plain Diff
Merge "EthernetTetheringTest: make some global variables static" into main
parents
8c22b9a3
1e6e2720
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
Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java
+36
-39
36 additions, 39 deletions
...tegration/base/android/net/EthernetTetheringTestBase.java
with
36 additions
and
39 deletions
Tethering/tests/integration/base/android/net/EthernetTetheringTestBase.java
+
36
−
39
View file @
60f800c2
...
...
@@ -31,12 +31,14 @@ import static android.net.TetheringTester.isAddressIpv4;
import
static
android
.
net
.
TetheringTester
.
isExpectedIcmpPacket
;
import
static
android
.
net
.
TetheringTester
.
isExpectedTcpPacket
;
import
static
android
.
net
.
TetheringTester
.
isExpectedUdpPacket
;
import
static
com
.
android
.
net
.
module
.
util
.
HexDump
.
dumpHexString
;
import
static
com
.
android
.
net
.
module
.
util
.
NetworkStackConstants
.
ICMPV6_ROUTER_ADVERTISEMENT
;
import
static
com
.
android
.
net
.
module
.
util
.
NetworkStackConstants
.
TCPHDR_ACK
;
import
static
com
.
android
.
net
.
module
.
util
.
NetworkStackConstants
.
TCPHDR_SYN
;
import
static
com
.
android
.
testutils
.
TestNetworkTrackerKt
.
initTestNetwork
;
import
static
com
.
android
.
testutils
.
TestPermissionUtil
.
runAsShell
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
...
...
@@ -46,7 +48,6 @@ import static org.junit.Assert.fail;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
android.app.UiAutomation
;
import
android.content.Context
;
import
android.content.pm.PackageManager
;
import
android.net.EthernetManager.TetheredInterfaceCallback
;
...
...
@@ -141,11 +142,12 @@ public abstract class EthernetTetheringTestBase {
protected
static
final
ByteBuffer
TX_PAYLOAD
=
ByteBuffer
.
wrap
(
new
byte
[]
{
(
byte
)
0x56
,
(
byte
)
0x78
});
private
final
Context
mContext
=
InstrumentationRegistry
.
getInstrumentation
().
getContext
();
private
final
EthernetManager
mEm
=
mContext
.
getSystemService
(
EthernetManager
.
class
);
private
final
TetheringManager
mTm
=
mContext
.
getSystemService
(
TetheringManager
.
class
);
private
final
PackageManager
mPackageManager
=
mContext
.
getPackageManager
();
private
final
CtsNetUtils
mCtsNetUtils
=
new
CtsNetUtils
(
mContext
);
private
static
final
Context
sContext
=
InstrumentationRegistry
.
getInstrumentation
().
getContext
();
private
static
final
EthernetManager
sEm
=
sContext
.
getSystemService
(
EthernetManager
.
class
);
private
static
final
TetheringManager
sTm
=
sContext
.
getSystemService
(
TetheringManager
.
class
);
private
static
final
PackageManager
sPackageManager
=
sContext
.
getPackageManager
();
private
static
final
CtsNetUtils
sCtsNetUtils
=
new
CtsNetUtils
(
sContext
);
// Late initialization in setUp()
private
boolean
mRunTests
;
...
...
@@ -161,7 +163,7 @@ public abstract class EthernetTetheringTestBase {
private
MyTetheringEventCallback
mTetheringEventCallback
;
public
Context
getContext
()
{
return
m
Context
;
return
s
Context
;
}
@BeforeClass
...
...
@@ -170,11 +172,10 @@ public abstract class EthernetTetheringTestBase {
// Tethering would cache the last upstreams so that the next enabled tethering avoids
// picking up the address that is in conflict with the upstreams. To protect subsequent
// tests, turn tethering on and off before running them.
final
Context
ctx
=
InstrumentationRegistry
.
getInstrumentation
().
getContext
();
final
CtsTetheringUtils
utils
=
new
CtsTetheringUtils
(
ctx
);
final
CtsTetheringUtils
utils
=
new
CtsTetheringUtils
(
sContext
);
final
TestTetheringEventCallback
callback
=
utils
.
registerTetheringEventCallback
();
try
{
if
(!
callback
.
isWifiTetheringSupported
(
ctx
))
return
;
if
(!
callback
.
isWifiTetheringSupported
(
sContext
))
return
;
callback
.
expectNoTetheringActive
();
...
...
@@ -195,13 +196,13 @@ public abstract class EthernetTetheringTestBase {
mRunTests
=
isEthernetTetheringSupported
();
assumeTrue
(
mRunTests
);
mTetheredInterfaceRequester
=
new
TetheredInterfaceRequester
(
mHandler
,
mEm
);
mTetheredInterfaceRequester
=
new
TetheredInterfaceRequester
(
mHandler
);
}
private
boolean
isEthernetTetheringSupported
()
throws
Exception
{
if
(
m
Em
==
null
)
return
false
;
if
(
s
Em
==
null
)
return
false
;
return
runAsShell
(
NETWORK_SETTINGS
,
TETHER_PRIVILEGED
,
()
->
m
Tm
.
isTetheringSupported
());
return
runAsShell
(
NETWORK_SETTINGS
,
TETHER_PRIVILEGED
,
()
->
s
Tm
.
isTetheringSupported
());
}
protected
void
maybeStopTapPacketReader
(
final
TapPacketReader
tapPacketReader
)
...
...
@@ -230,7 +231,7 @@ public abstract class EthernetTetheringTestBase {
protected
void
stopEthernetTethering
(
final
MyTetheringEventCallback
callback
)
{
runAsShell
(
TETHER_PRIVILEGED
,
()
->
{
m
Tm
.
stopTethering
(
TETHERING_ETHERNET
);
s
Tm
.
stopTethering
(
TETHERING_ETHERNET
);
maybeUnregisterTetheringEventCallback
(
callback
);
});
}
...
...
@@ -282,13 +283,13 @@ public abstract class EthernetTetheringTestBase {
// waiting timeout, just checking whether the system currently has any
// ethernet interface is more reliable.
if
(!
SdkLevel
.
isAtLeastT
())
{
return
runAsShell
(
CONNECTIVITY_USE_RESTRICTED_NETWORKS
,
()
->
m
Em
.
isAvailable
());
return
runAsShell
(
CONNECTIVITY_USE_RESTRICTED_NETWORKS
,
()
->
s
Em
.
isAvailable
());
}
// If previous test case doesn't release tethering interface successfully, the other tests
// after that test may be skipped as unexcepted.
// TODO: figure out a better way to check default tethering interface existenion.
final
TetheredInterfaceRequester
requester
=
new
TetheredInterfaceRequester
(
mHandler
,
mEm
);
final
TetheredInterfaceRequester
requester
=
new
TetheredInterfaceRequester
(
mHandler
);
try
{
// Use short timeout (200ms) for requesting an existing interface, if any, because
// it should reurn faster than requesting a new tethering interface. Using default
...
...
@@ -308,13 +309,13 @@ public abstract class EthernetTetheringTestBase {
protected
void
setIncludeTestInterfaces
(
boolean
include
)
{
runAsShell
(
NETWORK_SETTINGS
,
()
->
{
m
Em
.
setIncludeTestInterfaces
(
include
);
s
Em
.
setIncludeTestInterfaces
(
include
);
});
}
protected
void
setPreferTestNetworks
(
boolean
prefer
)
{
runAsShell
(
NETWORK_SETTINGS
,
()
->
{
m
Tm
.
setPreferTestNetworks
(
prefer
);
s
Tm
.
setPreferTestNetworks
(
prefer
);
});
}
...
...
@@ -344,7 +345,6 @@ public abstract class EthernetTetheringTestBase {
protected
static
final
class
MyTetheringEventCallback
implements
TetheringEventCallback
{
private
final
TetheringManager
mTm
;
private
final
CountDownLatch
mTetheringStartedLatch
=
new
CountDownLatch
(
1
);
private
final
CountDownLatch
mTetheringStoppedLatch
=
new
CountDownLatch
(
1
);
private
final
CountDownLatch
mLocalOnlyStartedLatch
=
new
CountDownLatch
(
1
);
...
...
@@ -368,19 +368,18 @@ public abstract class EthernetTetheringTestBase {
// seconds. See b/289881008.
private
static
final
int
EXPANDED_TIMEOUT_MS
=
30000
;
MyTetheringEventCallback
(
TetheringManager
tm
,
String
iface
)
{
this
(
tm
,
iface
,
null
);
MyTetheringEventCallback
(
String
iface
)
{
this
(
iface
,
null
);
mAcceptAnyUpstream
=
true
;
}
MyTetheringEventCallback
(
TetheringManager
tm
,
String
iface
,
Network
expectedUpstream
)
{
mTm
=
tm
;
MyTetheringEventCallback
(
String
iface
,
Network
expectedUpstream
)
{
mIface
=
new
TetheringInterface
(
TETHERING_ETHERNET
,
iface
);
mExpectedUpstream
=
expectedUpstream
;
}
public
void
unregister
()
{
m
Tm
.
unregisterTetheringEventCallback
(
this
);
s
Tm
.
unregisterTetheringEventCallback
(
this
);
mUnregistered
=
true
;
}
@Override
...
...
@@ -531,12 +530,12 @@ public abstract class EthernetTetheringTestBase {
// after etherent tethering started.
final
MyTetheringEventCallback
callback
;
if
(
expectedUpstream
!=
null
)
{
callback
=
new
MyTetheringEventCallback
(
mTm
,
iface
,
expectedUpstream
);
callback
=
new
MyTetheringEventCallback
(
iface
,
expectedUpstream
);
}
else
{
callback
=
new
MyTetheringEventCallback
(
mTm
,
iface
);
callback
=
new
MyTetheringEventCallback
(
iface
);
}
runAsShell
(
NETWORK_SETTINGS
,
()
->
{
m
Tm
.
registerTetheringEventCallback
(
mHandler:
:
post
,
callback
);
s
Tm
.
registerTetheringEventCallback
(
mHandler:
:
post
,
callback
);
// Need to hold the shell permission until callback is registered. This helps to avoid
// the test become flaky.
callback
.
awaitCallbackRegistered
();
...
...
@@ -556,7 +555,7 @@ public abstract class EthernetTetheringTestBase {
};
Log
.
d
(
TAG
,
"Starting Ethernet tethering"
);
runAsShell
(
TETHER_PRIVILEGED
,
()
->
{
m
Tm
.
startTethering
(
request
,
mHandler:
:
post
/* executor */
,
startTetheringCallback
);
s
Tm
.
startTethering
(
request
,
mHandler:
:
post
/* executor */
,
startTetheringCallback
);
// Binder call is an async call. Need to hold the shell permission until tethering
// started. This helps to avoid the test become flaky.
if
(!
tetheringStartedLatch
.
await
(
TIMEOUT_MS
,
TimeUnit
.
MILLISECONDS
))
{
...
...
@@ -606,14 +605,12 @@ public abstract class EthernetTetheringTestBase {
protected
static
final
class
TetheredInterfaceRequester
implements
TetheredInterfaceCallback
{
private
final
Handler
mHandler
;
private
final
EthernetManager
mEm
;
private
TetheredInterfaceRequest
mRequest
;
private
final
CompletableFuture
<
String
>
mFuture
=
new
CompletableFuture
<>();
TetheredInterfaceRequester
(
Handler
handler
,
EthernetManager
em
)
{
TetheredInterfaceRequester
(
Handler
handler
)
{
mHandler
=
handler
;
mEm
=
em
;
}
@Override
...
...
@@ -631,7 +628,7 @@ public abstract class EthernetTetheringTestBase {
assertNull
(
"BUG: more than one tethered interface request"
,
mRequest
);
Log
.
d
(
TAG
,
"Requesting tethered interface"
);
mRequest
=
runAsShell
(
NETWORK_SETTINGS
,
()
->
m
Em
.
requestTetheredInterface
(
mHandler:
:
post
,
this
));
s
Em
.
requestTetheredInterface
(
mHandler:
:
post
,
this
));
return
mFuture
;
}
...
...
@@ -654,7 +651,7 @@ public abstract class EthernetTetheringTestBase {
protected
TestNetworkInterface
createTestInterface
()
throws
Exception
{
TestNetworkManager
tnm
=
runAsShell
(
MANAGE_TEST_NETWORKS
,
()
->
m
Context
.
getSystemService
(
TestNetworkManager
.
class
));
s
Context
.
getSystemService
(
TestNetworkManager
.
class
));
TestNetworkInterface
iface
=
runAsShell
(
MANAGE_TEST_NETWORKS
,
()
->
tnm
.
createTapInterface
());
Log
.
d
(
TAG
,
"Created test interface "
+
iface
.
getInterfaceName
());
...
...
@@ -669,7 +666,7 @@ public abstract class EthernetTetheringTestBase {
lp
.
setLinkAddresses
(
addresses
);
lp
.
setDnsServers
(
dnses
);
return
runAsShell
(
MANAGE_TEST_NETWORKS
,
()
->
initTestNetwork
(
m
Context
,
lp
,
TIMEOUT_MS
));
return
runAsShell
(
MANAGE_TEST_NETWORKS
,
()
->
initTestNetwork
(
s
Context
,
lp
,
TIMEOUT_MS
));
}
protected
void
sendDownloadPacketUdp
(
@NonNull
final
InetAddress
srcIp
,
...
...
@@ -851,7 +848,7 @@ public abstract class EthernetTetheringTestBase {
private
void
maybeRetryTestedUpstreamChanged
(
final
Network
expectedUpstream
,
final
TimeoutException
fallbackException
)
throws
Exception
{
// Fall back original exception because no way to reselect if there is no WIFI feature.
assertTrue
(
fallbackException
.
toString
(),
m
PackageManager
.
hasSystemFeature
(
FEATURE_WIFI
));
assertTrue
(
fallbackException
.
toString
(),
s
PackageManager
.
hasSystemFeature
(
FEATURE_WIFI
));
// Try to toggle wifi network, if any, to reselect upstream network via default network
// switching. Because test network has higher priority than internet network, this can
...
...
@@ -867,7 +864,7 @@ public abstract class EthernetTetheringTestBase {
// See Tethering#chooseUpstreamType, CtsNetUtils#toggleWifi.
// TODO: toggle cellular network if the device has no WIFI feature.
Log
.
d
(
TAG
,
"Toggle WIFI to retry upstream selection"
);
m
CtsNetUtils
.
toggleWifi
();
s
CtsNetUtils
.
toggleWifi
();
// Wait for expected upstream.
final
CompletableFuture
<
Network
>
future
=
new
CompletableFuture
<>();
...
...
@@ -881,14 +878,14 @@ public abstract class EthernetTetheringTestBase {
}
};
try
{
m
Tm
.
registerTetheringEventCallback
(
mHandler:
:
post
,
callback
);
s
Tm
.
registerTetheringEventCallback
(
mHandler:
:
post
,
callback
);
assertEquals
(
"onUpstreamChanged for unexpected network"
,
expectedUpstream
,
future
.
get
(
TIMEOUT_MS
,
TimeUnit
.
MILLISECONDS
));
}
catch
(
TimeoutException
e
)
{
throw
new
AssertionError
(
"Did not receive upstream "
+
expectedUpstream
+
" callback after "
+
TIMEOUT_MS
+
"ms"
);
}
finally
{
m
Tm
.
unregisterTetheringEventCallback
(
callback
);
s
Tm
.
unregisterTetheringEventCallback
(
callback
);
}
}
...
...
@@ -925,7 +922,7 @@ public abstract class EthernetTetheringTestBase {
mDownstreamReader
=
makePacketReader
(
mDownstreamIface
);
mUpstreamReader
=
makePacketReader
(
mUpstreamTracker
.
getTestIface
());
final
ConnectivityManager
cm
=
m
Context
.
getSystemService
(
ConnectivityManager
.
class
);
final
ConnectivityManager
cm
=
s
Context
.
getSystemService
(
ConnectivityManager
.
class
);
// Currently tethering don't have API to tell when ipv6 tethering is available. Thus, make
// sure tethering already have ipv6 connectivity before testing.
if
(
cm
.
getLinkProperties
(
mUpstreamTracker
.
getNetwork
()).
hasGlobalIpv6Address
())
{
...
...
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