Commit Graph

168 Commits

Author SHA1 Message Date
JW Wang
347843b298 Rewrite how we abandon sessions
The original code is flawed in that `pm install-abandon` only abandons
the 1st session returned by `pm get-stagedsessions ...`.

1. move AbandonSessionsRule to be shared by multiple host tests
2. use AbandonSessionsRule to do the job

Bug: 160754072
Bug: 185973415
Test: StagedInstallInternalTest
Change-Id: Ib7b32fbd7b1133ac6a8e6782234a4fe2c5a782bd
Merged-In: Ib7b32fbd7b1133ac6a8e6782234a4fe2c5a782bd
(cherry picked from commit 3ac333f2d2)
2021-04-22 00:04:22 +01:00
JW Wang
f3a85cdee9 findNetworkStackApk returns an array of files (2/n)
This change handles the case of split APKs. All files starting with
"NetworkStack" will be returned as split APKs.

See b/159978937#comment6. NetworkStack is changed from a single APK to
split APKs. We need this change for install to succeed.

Bug: 159978937
Test: atest NetworkStagedRollbackTest
Change-Id: I20f5fee08ea208ba4dc7711d82a1718239c647c2
2020-06-29 16:16:10 +08:00
JW Wang
864d59ed70 Clean up rollbacks and test apps
See comment#6.

Clean up rollbacks and test apps before and after running tests.
This ensure we are in a good and expected condition when running tests.

Bug: 154080003
Test: atest RollbackTest
Test: atest MultiUserRollbackTest
Test: atest NetworkStagedRollbackTest
Test: atest StagedRollbackTest

Change-Id: If10fc8865e644611f1cf6a9db9d6dca6c7f11aee
2020-06-04 14:45:11 +08:00
JW Wang
e90db5aba3 Add tests for snapshot-deletion (2/n)
1. Document behavior changes due to ag/11475396
2. Test snapshots are deleted after restoration

See go/rollbackmanager-snapshot-deletion for more details.

Bug: 151805360
Test: atest StagedRollbackTest

Change-Id: Ia8993f82073a145889243bcefc74b6336bf71749
2020-05-29 15:49:54 +08:00
JW Wang
89325cf2cd Search more NetworkStack paths
The test failed because it can't find the apk file for NetworkStack.
Let's include more names for search.

Bug: 154792230
Test: atest NetworkStagedRollbackTest
Change-Id: I0909e531fcd0e99fcedb8d07ba0be01f4e762914
2020-04-23 17:34:46 +08:00
JW Wang
ac9dac6a9d Remove the workaround
Bug: 153832351
Test: atest MultiUserRollbackTest
Change-Id: I0718632fe9c81884965f0cc10a302155d434c621
2020-04-13 15:03:13 +08:00
JW Wang
65a7eeee7b Skip the test if no mainline modules installed
The test failed because we failed to enable rollback for
ModuleMetadataGoogle which is not a module on AOSP builds.

Let's skip the test for builds which have no mainline modules
installed.

Bug: 152721401
Test: atest StagedRollbackTest
Change-Id: Iaf75dea5388e2a751a26f983a79924c4358d4833
2020-04-03 21:42:55 +08:00
JW Wang
350c26a4bf Fix a flaky test.
See b/152840581#comment2 for the analysis.

call #waitForDeviceNotAvailable to wait for reboot reliably.

Bug: 152840581
Test: atest NetworkStagedRollbackTest
Change-Id: Ibbc9998c74681b1b8fc29b90ea66406f39ae7443
2020-04-01 18:33:20 +08:00
JW Wang
9f8407b0aa Run expiration when rollback lifetime is changed. DO NOT MERGE
See b/151890602#comment6 for the detail.

When rollback lifetime is changed, we need to re-schedule the
expiration algorithm so rollbacks can expire at the correct time.

Note we combine #runExpiration and #scheduleExpiration so there is only
one entrance to schedule the expiration algorithm.

See
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/10899294/1/services/core/java/com/android/server/rollback/RollbackManagerServiceImpl.java#672
for the rationale.

Bug: 151890602
Test: atest RollbackTest
Change-Id: I10355143dedc0af92e0b2adfedb5f008e160cbb3
2020-03-31 18:52:29 +08:00
JW Wang
5b163cfcee Add logs for debugging
See b/151890602#comment4.

If the assumption is true, we will see logs that the rollback for
testappA is exipred happens slightly after the call to #getAvailableRollbacks.

Also move assertions below so the test runs to the end and we have a
better picture for what happened during the test.

(Cherry-picked from eab998a9af)

Bug: 151890602
Test: m
Merged-In: I85adb8c3c5598ef4ce11550b51f22d1ce3c282a6
Change-Id: I85adb8c3c5598ef4ce11550b51f22d1ce3c282a6
2020-03-31 11:01:23 +08:00
JW Wang
28310268d9 Fix an NPE in WatchdogEventLogger#stop
See b/152550404#comment15.

https://cs.corp.google.com/android/frameworks/base/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java?rcl=0b9230489ead3a2ad328d46a47194cfa9dffd25c&l=86
My theory is that somehow #setUp throws before calling mLogger.start()
and then mLogger.stop() runs into an NPE.

Let's add a null-check in the hope that the actual root cause will stand
out.

Bug: 152550404
Test: atest StagedRollbackTest
Change-Id: Ifd323e6a8707a2de19d03ecbe536feacdbb4e9c6
2020-03-30 10:19:36 +08:00
JW Wang
a09e3c0983 Fix a flaky test
It is possible to have multiple committed rollbacks which include the
same app.

Uninstalling an app will delete committed rollbacks which include
the app. However, there is a race condition between when the app is
uninstalled and when rollback manager deletes the rollback as is stated
here:

https://cs.corp.google.com/android/frameworks/base/tests/RollbackTest/RollbackTest/src/com/android/tests/rollback/RollbackTest.java?rcl=75dfeca3d40624b745f41155aa38bc5e3fa405fe&l=116

We hit the assertion in #getUniqueRollbackInfoForPackage when there are
multiple rollbacks including the same package which is caused by the
race condition above.

Let's rewrite the code by calling #hasRollbackInclude instead which will
not throw.

Also do some cleanup in the xml to improve the isolation of our tests.

Bug: 152271716
Test: atest RollbackTest
Change-Id: Iad3effe52db2a0d2d5e3914bcd08ed93926f3fd3
2020-03-24 16:09:58 +08:00
JW Wang
8cb6fe8c21 Override phenotype flags during tests
https://g3doc.corp.google.com/experiments/g3doc/mobile/phenotype/android/testing.md?cl=head#hermetic

Phenotype talks to a server to override the device config changes made
by the tests. Therefore, rollback expiration didn't happen as expected
and caused the test to fail.

We need to override the flags on our own during tests so the
device config values ('rollback_lifetime_in_millis' in this case)
won't be changed in an unexpected way.

Note this is the same fix as ag/10467568.

Bug: 151890602
Test: atest RollbackTest
Change-Id: Ie884e4807999d105f6224c46a39434e1f437ed1b
2020-03-19 11:12:36 +08:00
JW Wang
45bf445ed4 Rewrite testBadApkOnly (1/n)
When tradefed fails to run a test, it will try to recover the device
which might lead to another reboot. This interferes with our test
flow which also involves reboot. See b/150749023#comment2 for more
details.

Let's rewrite the test to prevent auto-recovery of tradefed from kicking
in. Generally, it is a bad practice to depend our test flow on a failed
test due to reboot. We should call #waitForDeviceNotAvailable to wait
for reboot to happen and then call #waitForDeviceAvailable before
continuing next tests.

Bug: 150749023
Test: atest StagedRollbackTest#testBadApkOnly
Change-Id: Ia39630585c3b7344174a8c66d0a33f05a2d80cc7
2020-03-09 10:01:23 +08:00
JW Wang
757a3bad2c Do cleanup before/after running the test
Somehow rollbacks related to testappA are not cleaned before running the
test and cause test failures. See b/150653097#comment2 for more details.

Let's clean rollbacks manually to have a clean start.

Bug: 150653097
Test: atest MultiUserRollbackTest
Change-Id: I4eb126e193f76c821d26fc62115263b86066a215
2020-03-03 16:17:57 +08:00
JW Wang
6033dd2c58 Override phenotype flags during tests
https://g3doc.corp.google.com/experiments/g3doc/mobile/phenotype/android/testing.md?cl=head#hermetic

Phenotype talks to a server to override the device config changes made
by the tests. Therefore, watchdog timeout didn't happen as expected and
caused tests to fail.

We need to override the flags on our own during tests so the
device config values ('watchdog_request_timeout_millis' in this case)
won't be changed in an unexpected way.

See b/148042585#comment21 for more details.

Bug: 148042585
Test: atest NetworkStagedRollbackTest
Change-Id: I4d8944f7fef93445de8f971c6a96fef7c71872db
2020-03-02 14:57:56 +08:00
Gavin Corkery
7c46fe3663 Ensure staged rollback status is logged on boot
In the cases that a logging parent cannot be found for any packages
in a rollback, the watchdog event should still be logged. Ensure
that the state of a rollback is captured on boot by removing the
condition of only saving a rollback id if there is a logging package,
and by adding a symbolic null package to the list of logging packages
on boot if none were found. Expand tests to verify.

Bug: 149957011
Test: atest StagedRollbackTest
Test: atest NetworkStagedRollbackTest
Change-Id: I56f8afb6730e59fbe67ea8747e0da3aca19a0d8a
2020-02-23 17:23:23 +00:00
JW Wang
14168f321a Remove unused code (4/n)
Bug: 149876119
Test: m
Change-Id: I3f7c88eeb74ce5b44646fcb7a690665b78a17f2d
2020-02-20 18:52:21 +08:00
JW Wang
67eb86bb4c Pass "-g --user all" when installing apps (3/n)
'-g' to grant permissions automatically without checking the API level.
This works around the issue of b/149733368#comment2.

'--user all' to install the app on all users. This is more efficient
than calling #installPackageAsUser one by one on each user.

Bug: 149876119
Test: atest MultiUserRollbackTest
Change-Id: Ia5d85d3c13925ae969ffab9319360c1fefe1f950
2020-02-20 18:52:18 +08:00
JW Wang
f2a75879d3 No need to switch users before running tests (2/n)
My local test shows that switch-user doesn't work on my physical device.
In fact there are APIs to run tests against a particular user without
switching. It also speeds up tests without switching users from time to
time.

Bug: 149876119
Test: atest MultiUserRollbackTest
Change-Id: I34d26ddcb6a6e9cdc39228310830a3cd83212e4a
2020-02-20 18:49:59 +08:00
JW Wang
eb908a9ee1 Wait for rollback becomes available (1/n)
Sometimes RollbackManager is slow in making rollbacks available.
Let's give it enough time to do the job and make test less flaky.

Bug: 149876119
Test: atest MultiUserRollbackTest

Change-Id: I0a64e2dcde1f5e6dae618cacd6546ad953c1aca7
2020-02-20 16:25:10 +08:00
JW Wang
99c5b20bbd Speed up tests
Don't reboot the device when there is no file to delete. This saves us a
significant amount of time since each reboot takes 1 min and there are
dozens of reboot during the whole test case.

Bug: 149528114
Test: atest StagedRollbackTest

Change-Id: If3b06a304d9c87680c7cc5b7498d3b2ecf11cdfa
2020-02-17 22:08:39 +08:00
Patrick Baumann
d28bf33cf2 Adds QUERY_ALL_PACKAGES permission to rollbacktest
Test: atest com.android.tests.rollback.host.StagedRollbackTest
Bug: None
Change-Id: I499bf5f5ac8032db584aa307b2329533eb38fd36
2020-02-14 10:10:45 -08:00
JW Wang
d617d2ffbe Extract common code to a lib (4/n)
Bug: 147785893
Test: atest StagedRollbackTest NetworkStagedRollbackTest
Change-Id: I98da9f6287680691eb17afcd931b51c215da213c
2020-02-12 17:22:00 +08:00
JW Wang
332c07903a Move testNetworkPassedDoesNotRollback (3/n)
Bug: 147785893
Test: atest NetworkStagedRollbackTest
Change-Id: I16933808cc25b2c24be295b14c02c4e5fcfa600f
2020-02-11 11:16:20 +08:00
JW Wang
82228f22d4 Move testNetworkFailedRollback (2/n)
Bug: 147785893
Test: atest NetworkStagedRollbackTest
Change-Id: I801499b760e38a1eec4bab69daaa533124ad9531
2020-02-10 17:10:04 +08:00
JW Wang
6a68c9a380 Merge "Move network tests to new classes (1/n)" 2020-02-07 23:29:15 +00:00
JW Wang
ce92d6309a Move network tests to new classes (1/n)
By classifying the tests into 2 categories, we can:
1) run remaining tests with network disabled to reduce the interference
   of network crashes.
2) make it easier to identify bugs caused by network stack or
   problems in rollback infra.

Note this CL contains stubs only. We will move actual test code later.

Bug: 147785893
Test: m
Change-Id: I5ecc63a057e9a115ea3aa446970a3f20dff750d0
2020-02-07 19:49:12 +08:00
Gavin Corkery
818041eed6 Add tests for Watchdog logging metrics
Use the logcat output of WatchdogRollbackLogger as an indication
that the expected log events are sent to statsd.

Bug: 138782888
Test: atest StagedRollbackTest
Change-Id: I9a9d48da1cb1926186b2feedd0b78ab1bbd14fdf
2020-02-06 12:31:38 +00:00
Oli Lan
b9525aa0f7 Add test for DE (user) snapshot and restore.
This adds a test for rolling back device encrypted (user) apex data,
similar to the tests previously added for DE_sys and CE data.

Bug: 141148175
Test: atest StagedRollbackTest#testRollbackApexDataDirectories_DeUser
Change-Id: I632957449e4aa4f93df2e8bf0ae541937472d9fe
2020-01-30 11:25:15 +00:00
Oli Lan
26fdbb1a29 Add tests for DE_sys and CE apex data rollback.
This adds tests in StagedRollbackTest for apex data directory rollback.

The test performs the following steps:

- Push files into the apex data directory
- Update the APEX with rollback enabled
- Remove files from data directory
- Add new files to data directory
- Roll back the update
- Verify old files are restored

Bug: 141148175
Test: atest StagedRollbackTest#testRollbackApexDataDirectories_DeSys
Test: atest StagedRollbackTest#testRollbackApexDataDirectories_Ce
Change-Id: Ie1e7ed626c0b654c19b23bfcb008ac4d717aafe2
2020-01-29 14:10:41 +00:00
Mohammad Samiul Islam
8474b608a7 Merge "Revert "Revert "Make RollbackPackageHealthObserver observe apk-in-apex""" 2020-01-16 17:59:33 +00:00
JW Wang
2d66ab9be8 Merge changes I7579d6c9,I329b1f1a,I46d08fe2
* changes:
  No need to call #updateRollbackLifetimeDurationInMillis (3/n)
  Register an OnPropertiesChangedListener in onBootCompleted (2/n)
  Squash runnables in onBootCompleted (1/n)
2020-01-16 14:21:13 +00:00
Mohammad Samiul Islam
e7e63a692a Revert "Revert "Make RollbackPackageHealthObserver observe apk-in-apex""
This reverts commit 400124c6ae.

Reason for revert: Fixed the compile error; TestAppACrashingV2 was not
available to com.android.apex.apkrollback.test_v1

Change-Id: Ic443e913b837c9bb2716678521ad1d12d3bc7e4d
2020-01-16 14:00:28 +00:00
Greg Kaiser
400124c6ae Revert "Make RollbackPackageHealthObserver observe apk-in-apex"
This reverts commit d56ce00039.

This revert is to fix the wembley build.

Test: Local wembley build
Change-Id: I651f20ffc6ba11cced5a2a737fd3d77211127221
2020-01-16 05:40:17 -08:00
Mohammad Samiul Islam
67d72581ac Merge "Make RollbackPackageHealthObserver observe apk-in-apex" 2020-01-16 12:48:16 +00:00
Mohammad Samiul Islam
d56ce00039 Make RollbackPackageHealthObserver observe apk-in-apex
Due to b/147666157, this CL will only work as long as an apk is not
embedded in two different apex.

Bug: 142712057
Test: StagedRollbackTest#testRollbackApexWithApkCrashing
Change-Id: I60f7f70b627fd380094a11373259debddd5dc532
2020-01-15 15:29:32 +00:00
Mohammad Samiul Islam
724b6028ef Merge changes from topic "rollback-all"
* changes:
  Allow handling of all pending staged rollback sessions before rebooting
  Add test for verifying all available rollbacks are triggered during native crash
2020-01-15 12:52:01 +00:00
JW Wang
4ff9d08435 No need to call #updateRollbackLifetimeDurationInMillis (3/n)
No need to call #updateRollbackLifetimeDurationInMillis manually inside
reloadPersistedData. Also fix tests since #reloadPersistedData no longer
pulls DeviceConfig changes.

Bug: 147712943
Test: atest StagedRollbackTest RollbackTest
Change-Id: I7579d6c969117189e01e0767decd1faeaa811eb9
2020-01-15 18:33:02 +08:00
Mohammad Samiul Islam
2f9fa5c9da Allow handling of all pending staged rollback sessions before rebooting
When there is an unattributable native service crash during boot, we
rollback all packages available for rollback. In the current
implementation, we reboot immediately when a staged rollback session
becomes ready, even though there can be other staged rollback sessions
which are still being handled.

In this CL, the logic is changed to allow the health observer wait for
all staged sessions to be handled before rebooting.

Bug: 141843321
Test: atest StagedRollbackTest#testNativeWatchdogTriggersRollbackForAll
Test: atest StagedRollbackTest
Change-Id: Ib2aaee22868e5502b68847aa7f64e428070f7e3c
2020-01-14 09:04:21 +00:00
Mohammad Samiul Islam
9481762932 Add test for verifying all available rollbacks are triggered during native crash
Bug: 135977463
Test: atest StagedRollbackTest#testNativeWatchdogTriggersRollbackForAll
Change-Id: Iaff10b39207753434c216de5d462211c9826e69c
2020-01-13 11:35:20 +00:00
Mohammad Samiul Islam
3fcecfc1ce Rollback user data of apks-in-apex while rolling back the apex
Currently, the RollbackManager is not aware of the apk-in-apex being
installed since the install is done by PM during scan phase of boot. As
such, RM does not backup the user data of the apk-in-apex.

In the new implementation, we ask the RM to snapshot/restore user data
of apk-in-apex while resuming the apex session in StagingManager.

Bug: 142712057
Test: atest StagedRollbackTest#testRollbackApexWithApk
Test: atest AppDataRollbackHelperTest
Test: atest RollbackStoreTest
Test: atest RollbackUnitTest
Change-Id: Ibbaa5d0c98cb883588c085d77bc89c3e8217d76a
2020-01-10 16:15:47 +00:00
JW Wang
557b2a5aa2 Clean up rollbacks after each test (2/n)
testNetworkPassedDoesNotRollback leaves a rollback for the network stack
and we need to clean up all rollbacks before running
testNativeWatchdogTriggersRollback otherwise the test will fail on
devices which doesn't support checkpoint.

See b/146991129 comment#2 for the detail.

Bug: 147259494
Test: atest StagedRollbackTest
Change-Id: Ib9c5e3f56bf31bfbf6f5a415879f9eb1b10d270e
2020-01-07 14:35:08 +08:00
JW Wang
f86cecf873 Rewrite and re-enable the test (1/n)
The test is rewritten as testNetworkFailedRollback was in ag/9648485 to
empoly more device methods for better logging and debugging.

Bug: 147259494
Test: atest StagedRollbackTest
Change-Id: I4104d20296dee4abba2996f8f9e3b47e258bf6a9
2020-01-07 12:28:21 +08:00
JW Wang
82768bf925 Respect the rollback data policy (3/n)
1. Don't snapshot user data when the policy is WIPE.
2. Add tests to verify user data is wiped/restored correctly.

Bug: 144683152
Test: atest RollbackStoreTest RollbackUnitTest AppDataRollbackHelperTest
Test: atest RollbackTest StagedRollbackTest
Change-Id: I470233080efbba724ace6f0dbf2ab5256db49054
2020-01-02 22:07:00 +08:00
JW Wang
b13131f10c Clean up the rollback when test is done
When multiple staged sessions are installed on a device which doesn't
support checkpoint, only the 1st will prevail. The test failed when
TestApp.A is not the 1st rollback to commit.

We need to clean up the rollback left by testRollbackWhitelistedApp so
TestApp.A is always the only and first one to commit.

Bug: 146991129
Test: atest StagedRollbackTest
Change-Id: I4afdace934b7b7e3b198169dc2eb0da66c65eb94
2019-12-30 19:52:06 +08:00
JW Wang
9b51b7319c Check the white list to decide whether to enable rollback (2/n)
Bug: 144680850
Test: atest RollbackTest StagedRollbackTest
Change-Id: I4b6b42d6a0fce836d7ebaca8bcde8c837c086e9b
2019-12-17 10:29:30 +08:00
Mohammad Samiul Islam
a3f650dc8d Mitigate native crash without depending on ModuleMetaData
Mitigation attempts should be made whenever rollbacks are available.

Bug: 141843321
Test: atest StagedRollbackTest#testNativeWatchdogTriggersRollback
Change-Id: I2dde8c6415191ff3787a82ea3abc0fcc9a3cd7b1
2019-12-11 09:43:54 +00:00
JW Wang
517bb2b25b Test child sessions time out in enabling rollback (2/n)
The rollback shouldn't be available if any of the child sessions times
out in enabling rollback.

Bug: 144732395
Test: atest RollbackTest
Change-Id: Id899f3c1ec100fcdcad1f24f2701f95b1c49bc69
2019-11-21 17:55:05 +08:00
Remi NGUYEN VAN
d02b13334b Merge "Autodetect NetworkStack path in rollback test" 2019-11-11 11:51:35 +00:00