Commit graph

1892 commits

Author SHA1 Message Date
Yifan Hong
e6c1a84276 libsnapshot: fix incorrect assumption of cow images
libsnapshot used to assume CoW images are always mapped
with device mapper, and call GetDeviceString directly.
However, in tests, it is possible that it is mapped as loop
devices. Fix the incorrect assumption and calls
IImageManager::GetMappedImageDevice instead.

Test: libsnapshot_fuzzer with corpus
Bug: 154633114
Change-Id: I1ec39744480e514ae7a7902643ed863e0ca0a340
2020-05-05 18:01:15 -07:00
Yifan Hong
2e66043394 Merge "Add tests for zero snapshot size." 2020-05-05 15:23:35 +00:00
Alessio Balsini
f2554ab2ad Merge "fiemap_image_test: libcrypto_utils as static lib" 2020-05-04 17:48:06 +00:00
David Anderson
5a0177d945 fastboot: Fix snapshot-update merge behavior.
When merging in recovery, the "imminent data wipe" code was used, which
made the assumption the /metadata and /data state would be zapped. This
caused future OTAs to error because the old snapshots were detected.

This CL allows OTAs to proceed even if unexpected snapshots are present.
It also forces the state to "MergeCompleted" after a merge in recovery,
so that the next normal boot can perform cleanup.

Bug: 155339165
Test: fastboot snapshot-update merge, then take another OTA
      vts_libsnapshot_test
Change-Id: Ief6dea3ba76323044e61307272dda320a4494aea
2020-05-02 16:02:07 -07:00
Yifan Hong
f4cd49afa4 Merge changes from topic "snapshot_fuzz"
* changes:
  Enable automatic libsnapshot fuzzer runs
  Also log corpus when aborted through libbase.
  libsnapshot_fuzzer: Fuzz MapUpdateSnapshot.
  libsnapshot_fuzzer: construct valid super partition metadata.
  libsnapshot_fuzzer: Fuzz CreateUpdateSnapshots
  libsnapshot_fuzzer: add additional tests for more APIs
  libsnapshot_fuzzer: use protobuf
  libsnapshot_fuzzer: map super image
2020-05-02 04:46:31 +00:00
Yifan Hong
e0c2e62c87 Add tests for zero snapshot size.
Test: run vts_libsnapshot_test
Test: fails without the fix patch
Bug: 155484992
Change-Id: Ia048704f427682d4f83219fbf9813ae06d05298b
2020-05-01 16:22:27 -07:00
Yifan Hong
83c690c7a6 Handle zero snapshot size appropriately.
This won't happen in practice because device size is never
zero. Hypothetically, if it is, PartitionCowCreator still
suggests that a CoW size of 8192 bytes needs to be created. In
reality, it is not necessary.

Test: libsnapshot_fuzzer
Bug: 155484992
Change-Id: I6c69f54820522d50c699384eec90c474ca3a9402
2020-05-01 18:46:44 +00:00
Yifan Hong
c43f513c91 Enable automatic libsnapshot fuzzer runs
Test: none
Bug: 154633114
Change-Id: I226d88b74bd1ea6b3cb912609d7bdf10aa8208fd
2020-05-01 11:00:48 -07:00
Yifan Hong
4d5bfabfeb Also log corpus when aborted through libbase.
If a CHECK or LOG(FATAL) is hit, also attempt to log the current
corpus.

Test: pass
Bug: 154633114
Change-Id: Id0f376021011924f5d64eb5b591b5ebab6dc7dbc
2020-05-01 11:00:48 -07:00
David Anderson
b827d1db0c Merge "remount: Improve messaging when a reboot is needed." 2020-05-01 17:44:18 +00:00
Alessio Balsini
ce036fd7ba fiemap_image_test: libcrypto_utils as static lib
libcrypto_utils is not available as 32 bit library in 64 bit devices.
Import the library as static.

Bug: 148878078
Test: nativetest/fiemap_image_test
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I2b8cd69d06607f4216e4e2220dd8561e6eff323c
2020-05-01 12:18:39 +01:00
Yifan Hong
0d4a47b0c7 libsnapshot_fuzzer: Fuzz MapUpdateSnapshot.
Test: run it
Bug: 154633114
Change-Id: I15ea0fb28df5b0f6d32096aab808549c3855c289
2020-04-30 23:06:42 -07:00
Yifan Hong
db0e62b87a libsnapshot_fuzzer: construct valid super partition metadata.
This should hopefully achieve more coverage.

Test: pass
Bug: 154633114
Change-Id: Ice575f2d8c3e22b80465c133d055e7c4368ebdfa
2020-04-30 23:06:42 -07:00
Yifan Hong
74d1fb4571 libsnapshot_fuzzer: Fuzz CreateUpdateSnapshots
Test: run it
Bug: 154633114
Change-Id: I56ed2953e85714d23a9273224a28eb8e8e47a54d
2020-04-30 23:05:36 -07:00
Yifan Hong
c0df932a43 libsnapshot_fuzzer: add additional tests for more APIs
Test: run it
Bug: 154633114
Change-Id: I956cb74bfd46750137dfa73e9e040dd9d1782ce7
2020-04-30 23:05:36 -07:00
Yifan Hong
90a9393ea0 libsnapshot_fuzzer: use protobuf
Use protobuf because it already has all the fuzzing implemenetations.
Delete fuzz_utils.

Pros:
- Fuzzing protobuf is faster; it is easy to achieve 4K exec/s
- It is more guided; protobufs are fuzzed using mutators, and mutators
  should have better knowledge of the structure of the fuzz data
- No more hand-written parsing code of the fuzz data. That code in
  fuzz_utils.h is deleted.
- Corpus data can be reused even after adding new fields in the protobuf
- Corpus data is human-readable and easily manually written (it is
  the text format of the protobuf)

Cons:
- The "actions" are "declared" in protobuf definition and "defined" in
  C++, so there's more boilerplate to write. Adding a new "Action"
  requires changes in both.

Test: run libsnapshot_fuzzer
Bug: 154633114
Change-Id: Idc2a6b2c087e370e4cfef53142a244b9b275389e
2020-04-30 23:05:36 -07:00
Yifan Hong
5eb2d6fa27 libsnapshot_fuzzer: map super image
... instead of operating on the image file directly.
Test: run it
Bug: 154633114

Change-Id: Id04c0d15d0d52483647716f8bfb0b8ee1a2876d9
2020-04-30 23:05:36 -07:00
Alessio Balsini
75672f8be5 snapshot_test: Fix overflow in statvfs arithmetics
Operations on (unsigned long) f_bsize and f_bfree are correctly handled
on 64 bit architectures, but when switching to 32 bit, the
multiplication between the two could result in an overflow, causing the
test to crash.
Fix by using a uint64_t operand, hinting the compiler to handle the
whole multiplication with 64 bit operands.

Bug: 154355449
Bug: 148889015
Test: vts_libsnapshot_test (32 bit)
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: Ief5c03ff7954c4a3e8597ef6e7df467f59428877
2020-04-30 21:02:26 +01:00
David Anderson
45253ae5c6 remount: Improve messaging when a reboot is needed.
Bug: 149665201
Test: adb remount
Change-Id: I990ce80f14795669d4bbf05789910c5b15ee53cf
2020-04-29 22:04:58 -07:00
David Anderson
b954b13613 Merge "libfiemap: Ignore userdata requirements in fiemap_writer_test when running a DSU." 2020-04-28 22:09:25 +00:00
Treehugger Robot
3124175854 Merge "Moves some shared_libs to static_libs for vts_libsnapshot_test." 2020-04-28 18:49:52 +00:00
Treehugger Robot
fdabad8d53 Merge "Add fuzz test for libsnapshot" 2020-04-28 08:28:53 +00:00
David Anderson
dde0c28089 Merge "liblp: Remove alignment_offset handling." 2020-04-28 04:30:23 +00:00
Daniel Norman
2f8eb83f52 Moves some shared_libs to static_libs for vts_libsnapshot_test.
These shared_libs are missing from /system/lib/ on 64-bit devices.

Test: Build, install, and run 32bit vts_libsnapshot_test.
Bug: 154115505
Change-Id: Iaf2014748546a055d35e4fe0e24969eef13db7fa
2020-04-27 15:39:35 -07:00
David Anderson
cc2bf6b9d3 libfiemap: Ignore userdata requirements in fiemap_writer_test when running a DSU.
The test is guaranteed to fail because userdata is itself a fiemap-backed device.

Bug: 154447105
Test: fiemap_writer_test on DSU
Change-Id: Ied35da0eb7aba3daca7ed430f006bf1e90e21dca
2020-04-27 21:46:53 +00:00
Yifan Hong
1b0893ea5e Add fuzz test for libsnapshot
Bug: 154633114
Test: source fuzz.sh && run_snapshot_fuzz_all -runs=100000

Change-Id: I5cd9e3f088ca283d3a49959c38aa74a483931f2c
2020-04-27 12:37:40 -07:00
Mark Salyzyn
93c1233f12 fs_mgr: overlayfs: replace adb reboot -R with adb remount -R
Signed-off-by: Mark Salyzyn <salyzyn@google.com>
Test: none
Change-Id: Ie718e264b41763d904e59db74d4e7c9d4b8787f3
2020-04-27 07:41:17 -07:00
David Anderson
171681caf9 liblp: Remove alignment_offset handling.
This code is complex and alignment_offset is not useful for
optimization. Remove it, and add another test that misaligned extents do
not cause overlapping partitions.

Bug: 154646936
Test: liblp_test gtests
Change-Id: I563122282e940e07a7ece97ed1a9846ad1f3253c
2020-04-22 23:44:03 -07:00
David Anderson
9c66e53a82 liblp: Fix tests for linear extent overlap.
The "OwnsSector" tests did not work if one range fit completely inside
another range. The new OverlapsWith() methods address this case.

Bug: 154277287
Bug: 154646936
Test: liblp_test gtests
Change-Id: I1a59069db4ffe4f13c45963c4847cff7b3dd3dfc
2020-04-21 15:43:59 -07:00
Nikita Ioffe
bcaeb70d80 PrepareZramBackingDevice: use loop_control.h
loop_control.h already provides loop device management APIs that we need
here. In addition, this change fixes a subtle race condition between
uevented creating a loop device node in userspace and
PrepareZramBackingDevice accessing it without waiting for it to be
created.

Test: device boots
Test: adb reboot userspace
Bug: 154500256
Change-Id: If80f18c8c337210030a6caf2aec6f7a47472b6fb
Merged-In: If80f18c8c337210030a6caf2aec6f7a47472b6fb
(cherry picked from commit c8313adf88)
2020-04-20 21:08:25 +01:00
Yifan Hong
96174857f2 Merge changes from topics "sm_mock", "sm_stub"
* changes:
  libsnapshot: Add MockSnapshotManager and MockDeviceInfo.
  libsnapshot: Add GetSnapshotMergeStatsInstance
  libsnapshot: Add SnapshotManagerStub.
  libsnapshot: Add ISnapshotManager.
2020-04-20 18:50:01 +00:00
Alessio Balsini
0c27fb8c5d Fix liblp imported both as static and dynamic lib
In vts_libsnapshot_test, liblp was explicitly imported as static
library, but due to the importing of libsnapshot_defaults, it also
inherited the shared importing.
The import in libsnapshot_default, is not required, drop it.

Test: manual inspection with ldd
Bug: 148889015
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I12ba0516a482dc917848b5f34cccc659a60a4803
2020-04-19 18:34:32 +00:00
Yifan Hong
2dcca52457 libsnapshot: Add MockSnapshotManager and MockDeviceInfo.
For testing.

Bug: 153555889
Test: vts_libsnapshot_test
Test: update_engine_unittests
Change-Id: Id92f7372ef408625f2ef1120c99d0b4058ed488c
2020-04-16 13:12:41 -07:00
Yifan Hong
66f0115b05 libsnapshot clients: Add missing dep.
libsnapshot* uses update_metadata-protos. This
used to be optimized out, but now that SnapshotManager is
virtual, CreateUpdateSnapshots can no longer be optimized out.

Bug: 148956645
Test: compiles
Change-Id: Ib67cafd156308bf5a477996ec32eb786f8e896db
2020-04-16 13:12:41 -07:00
Yifan Hong
ee5032a436 libsnapshot: Add GetSnapshotMergeStatsInstance
This is preferred over SnapshotMergeStats::GetInstance because
the latter needs a concrete SnapshotManager, not the ISnapshotManager
interface.

SnapshotManagerStub::GetSnapshotMergeStatsInstance returns
a SnapshotMergeStatsStub instance.

Test: vts_libsnapshot_test
Bug: 148956645
Change-Id: Ife0ad6d3ce85333cbf395d07f74dedc9ca3fe675
2020-04-16 13:12:41 -07:00
Yifan Hong
fedb270908 libsnapshot: Add SnapshotManagerStub.
Avoid crashes in update_engine. When SnapshotManager
should not be used (e.g. Virtual A/B is not enabled),
use the stub instead.

Bug: 148956645
Test: update_engine_unittests
Change-Id: Id524a1dfe5d085d439fc5492d4b7f72ee583c17e
2020-04-16 13:12:41 -07:00
Yifan Hong
8129dda1f9 libsnapshot: Add ISnapshotManager.
This is the public interface of SnapshotManager.
SnapshotManager then inherits from it.

Test: compiles
Test: vts_libsnapshot_test
Test: update_engine_unittests
Bug: 148956645
Bug: 153555889
Change-Id: Ib19c038f9bb41dd8d27f72ff6a24c231cd4c5a76
2020-04-16 13:12:41 -07:00
Treehugger Robot
8c6d5bf83c Merge "Re-enable libsnapshot ImageManagerTest" 2020-04-16 17:20:41 +00:00
Martijn Coenen
f0122aa14d Merge "Rename external storage properties." 2020-04-16 08:06:52 +00:00
Alessio Balsini
42a608162d Re-enable libsnapshot ImageManagerTest
ImageManagerTest had been temporarily disabled because flaky.
This test looks stable now, re-enable it.

Bug: 148889015
Test: atest vts_libsnapshot_test [-- --abi x86]
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I858661fed7f58d1e2857ed88f5d8e0f5220bf8c2
2020-04-16 00:11:55 +00:00
David Anderson
0bd13b7be9 Merge "libsnapshot: Add a simple script and gtest to simulate power failures during snapshot-merge." 2020-04-15 22:51:20 +00:00
David Anderson
f3c8e3036c Merge "fs_mgr: Fix executable path in clean_scratch_files." 2020-04-15 16:35:31 +00:00
Martijn Coenen
ea751d94dd Rename external storage properties.
According to property naming guidelines.

Bug: 152170470
Bug: 153525566
Test: N/A
Change-Id: Ia5ce2a95e43724f8d0a7abf6782bc177dedb18a8
2020-04-15 17:32:28 +02:00
David Anderson
a441612fae fs_mgr: Fix executable path in clean_scratch_files.
Bug: 154071877
Test: no error log on startup
Change-Id: I84c627011992eed6952697e7260051006b1c10d0
2020-04-14 23:47:38 -07:00
David Anderson
f4d58b483e libsnapshot: Add a simple script and gtest to simulate power failures during snapshot-merge.
This test is pretty straight forward: create two large files, then merge
one into the other while injecting kernel crashes. At the end,
block-by-block validation is performed against both the snapshot-merge target
and the file written to disk.

Bug: 139092356
Test: instructions in PowerTest.md
Change-Id: I28cc88160cf824039966abff4e61382090a354c5
2020-04-14 23:32:38 -07:00
Nikita Ioffe
f3504ec58d Add RootTargetPreparer for CtsInitTestCases and CtsFsMgrTestCases
Some of the test cases in CtsInitTestCases and CtsFsMgrTestCases require
root. This CL makes it possible to run such tests cases on userdebug
builds, which in turn means that they will be run on presubmit.

New option was implemented in
https://android-review.googlesource.com/c/platform/tools/tradefederation/+/1283834

Test: atest CtsInitTestCases
Test: atest CtsFsMgrTestCases
Change-Id: I3d29789ddd7ac549e40ac193c58d986670c49285
2020-04-14 18:57:07 +01:00
Jaegeuk Kim
8b8743462c Merge "fstab: support f2fs compression" 2020-04-14 15:54:18 +00:00
Nikita Ioffe
74429fc121 Merge "get_mounted_entry_for_userdata: Realpath block devices from fstabs" 2020-04-07 12:01:29 +00:00
Treehugger Robot
edf8335c72 Merge "Rename vts-core to vts" 2020-04-07 05:11:55 +00:00
Paul Crowley
1b1ec8f36a Merge "Abolish DmTargetDefaultKey::IsLegacy" 2020-04-07 03:23:57 +00:00