aboutsummaryrefslogtreecommitdiff
path: root/patch_read_write_unittest.cc
diff options
context:
space:
mode:
authorCalder Kitagawa <ckitagawa@google.com>2018-04-24 13:54:46 +0000
committerEdward Lesmes <ehmaldonado@google.com>2021-07-23 22:09:53 +0000
commit05b1b6a1d8cfe2960959ff0ea3ecf96c4f198c54 (patch)
treec73343189a18e17ada847085bd27d0053e49d3ab /patch_read_write_unittest.cc
parent451ff5de400706acdfcfdb9bf28ca6d4c0670b81 (diff)
downloadzucchini-05b1b6a1d8cfe2960959ff0ea3ecf96c4f198c54.tar.gz
[Zucchini] Update ExecutableType values.
This change has some pros and some cons: Pros: - Human readable ExecType in patch/hex dumps as the ASCII is meaningful. - Can be done at next to no cost at compile time. - Assigning new values regardless of order of appearance in the enum is more flexible. No more concern over invalidating old patches as values will be more or less permanent once this change goes in. Cons: - Checking if an ExecutableType is valid requires O(n) time where n is the number of supported Exec types using a cast. Alternatively, we could maintain a sorted list of these types in memory to check against in O(log(n)) or could use a set but this is more memory. Overall not a huge deal since we only support ~9 types but it is worth understanding the tradeoffs. - Enums don't enforce value reuse so it is possible although highly unlikely we introduce a repeated value. However, given the use of the switch case casting requiring unique values this is very unlikely. Bug: 834932 Change-Id: I7bc14ea7b4434e60bb0dafa47178fb2c2c12dc7f Reviewed-on: https://chromium-review.googlesource.com/1020446 Commit-Queue: Calder Kitagawa <ckitagawa@google.com> Reviewed-by: Samuel Huang <huangs@chromium.org> Cr-Commit-Position: refs/heads/master@{#553083} NOKEYCHECK=True GitOrigin-RevId: da4335f0d27c7fa14f6897ffeb0833d424860f7e
Diffstat (limited to 'patch_read_write_unittest.cc')
-rw-r--r--patch_read_write_unittest.cc100
1 files changed, 50 insertions, 50 deletions
diff --git a/patch_read_write_unittest.cc b/patch_read_write_unittest.cc
index b701df8..f6396d6 100644
--- a/patch_read_write_unittest.cc
+++ b/patch_read_write_unittest.cc
@@ -63,11 +63,11 @@ bool operator==(const ByteVector& a, ConstBufferView b) {
TEST(PatchTest, ParseSerializeElementMatch) {
ByteVector data = {
- 0x01, 0, 0, 0, // old_offset
- 0x03, 0, 0, 0, // new_offset
- 0x02, 0, 0, 0, // old_length
- 0x04, 0, 0, 0, // new_length
- 7, 0, 0, 0, // kExeTypeDex
+ 0x01, 0, 0, 0, // old_offset
+ 0x03, 0, 0, 0, // new_offset
+ 0x02, 0, 0, 0, // old_length
+ 0x04, 0, 0, 0, // new_length
+ 'D', 'E', 'X', ' ', // kExeTypeDex
};
BufferSource buffer_source(data.data(), data.size());
ElementMatch element_match = {};
@@ -392,37 +392,37 @@ TEST(TargetSourceSinkTest, Normal) {
TEST(PatchElementTest, Normal) {
ByteVector data = {
- 0x01, 0, 0, 0, // old_offset
- 0x03, 0, 0, 0, // new_offset
- 0x02, 0, 0, 0, // old_length
- 0x04, 0, 0, 0, // new_length
- 1, 0, 0, 0, // EXE_TYPE_WIN32_X86
-
- 1, 0, 0, 0, // src_skip size
- 0x10, // src_skip content
- 1, 0, 0, 0, // dst_skip size
- 0x11, // dst_skip content
- 1, 0, 0, 0, // copy_count size
- 0x12, // copy_count content
-
- 1, 0, 0, 0, // extra_data size
- 0x13, // extra_data content
-
- 1, 0, 0, 0, // raw_delta_skip size
- 0x14, // raw_delta_skip content
- 1, 0, 0, 0, // raw_delta_diff size
- 0x15, // raw_delta_diff content
-
- 1, 0, 0, 0, // reference_delta size
- 0x16, // reference_delta content
-
- 2, 0, 0, 0, // pool count
- 0, // pool_tag
- 1, 0, 0, 0, // extra_targets size
- 0x17, // extra_targets content
- 2, // pool_tag
- 1, 0, 0, 0, // extra_targets size
- 0x18, // extra_targets content
+ 0x01, 0, 0, 0, // old_offset
+ 0x03, 0, 0, 0, // new_offset
+ 0x02, 0, 0, 0, // old_length
+ 0x04, 0, 0, 0, // new_length
+ 'P', 'x', '8', '6', // EXE_TYPE_WIN32_X86
+
+ 1, 0, 0, 0, // src_skip size
+ 0x10, // src_skip content
+ 1, 0, 0, 0, // dst_skip size
+ 0x11, // dst_skip content
+ 1, 0, 0, 0, // copy_count size
+ 0x12, // copy_count content
+
+ 1, 0, 0, 0, // extra_data size
+ 0x13, // extra_data content
+
+ 1, 0, 0, 0, // raw_delta_skip size
+ 0x14, // raw_delta_skip content
+ 1, 0, 0, 0, // raw_delta_diff size
+ 0x15, // raw_delta_diff content
+
+ 1, 0, 0, 0, // reference_delta size
+ 0x16, // reference_delta content
+
+ 2, 0, 0, 0, // pool count
+ 0, // pool_tag
+ 1, 0, 0, 0, // extra_targets size
+ 0x17, // extra_targets content
+ 2, // pool_tag
+ 1, 0, 0, 0, // extra_targets size
+ 0x18, // extra_targets content
};
PatchElementReader patch_element_reader =
@@ -490,7 +490,7 @@ TEST(EnsemblePatchTest, RawPatch) {
0x00, 0, 0, 0, // new_offset
0x02, 0, 0, 0, // old_length
0x98, 0xBA, 0xDC, 0xFE, // new_length
- 1, 0, 0, 0, // EXE_TYPE_WIN32_X86
+ 'P', 'x', '8', '6', // EXE_TYPE_WIN32_X86
0, 0, 0, 0, // src_skip size
0, 0, 0, 0, // dst_skip size
0, 0, 0, 0, // copy_count size
@@ -536,19 +536,19 @@ TEST(EnsemblePatchTest, CheckFile) {
1, 0, 0, 0, // number of element
- 0x01, 0, 0, 0, // old_offset
- 0x00, 0, 0, 0, // new_offset
- 0x02, 0, 0, 0, // old_length
- 0x03, 0, 0, 0, // new_length
- 1, 0, 0, 0, // EXE_TYPE_WIN32_X86
- 0, 0, 0, 0, // src_skip size
- 0, 0, 0, 0, // dst_skip size
- 0, 0, 0, 0, // copy_count size
- 0, 0, 0, 0, // extra_data size
- 0, 0, 0, 0, // raw_delta_skip size
- 0, 0, 0, 0, // raw_delta_diff size
- 0, 0, 0, 0, // reference_delta size
- 0, 0, 0, 0, // pool count
+ 0x01, 0, 0, 0, // old_offset
+ 0x00, 0, 0, 0, // new_offset
+ 0x02, 0, 0, 0, // old_length
+ 0x03, 0, 0, 0, // new_length
+ 'P', 'x', '8', '6', // EXE_TYPE_WIN32_X86
+ 0, 0, 0, 0, // src_skip size
+ 0, 0, 0, 0, // dst_skip size
+ 0, 0, 0, 0, // copy_count size
+ 0, 0, 0, 0, // extra_data size
+ 0, 0, 0, 0, // raw_delta_skip size
+ 0, 0, 0, 0, // raw_delta_diff size
+ 0, 0, 0, 0, // reference_delta size
+ 0, 0, 0, 0, // pool count
};
EnsemblePatchReader ensemble_patch_reader =