Enable BCJ filters for X86 and ARM ELF binary.
BCJ filter convert relative addresses into absolute addresses to
increase redundancy, but it could make things worse if applied on the
wrong data, so we only enabled it on ELF with supported arch.
Some testing with an ARM system image shows that using the filter could
reduce the compressed size by up to 20% when compressing a single ELF
file using XZ, or increase by up to 1%, on average this will save about
6%.
The saving on final payload size are less significant because bsdiff
will win most of the time in delta payload, and for full payload we
are not splitting the operation by file, so the filter won't apply
most of the time.
Bug: 27878181
Test: generated delta and full payload
Test: update_engine_unittests
Change-Id: I9b6ce1b0b8b0e37cf35a9a6dfb02ebbb8be65109
diff --git a/payload_generator/zip_unittest.cc b/payload_generator/zip_unittest.cc
index 5b0d5da..29f16d3 100644
--- a/payload_generator/zip_unittest.cc
+++ b/payload_generator/zip_unittest.cc
@@ -135,7 +135,7 @@
brillo::Blob decompressed;
EXPECT_TRUE(this->ZipDecompress(out, &decompressed));
EXPECT_EQ(in.size(), decompressed.size());
- EXPECT_TRUE(!memcmp(in.data(), decompressed.data(), in.size()));
+ EXPECT_EQ(0, memcmp(in.data(), decompressed.data(), in.size()));
}
TYPED_TEST(ZipTest, PoorCompressionTest) {
@@ -165,4 +165,18 @@
EXPECT_EQ(0U, out.size());
}
+TYPED_TEST(ZipTest, CompressELFTest) {
+ string path = test_utils::GetBuildArtifactsPath("delta_generator");
+ brillo::Blob in;
+ utils::ReadFile(path, &in);
+ brillo::Blob out;
+ EXPECT_TRUE(this->ZipCompress(in, &out));
+ EXPECT_LT(out.size(), in.size());
+ EXPECT_GT(out.size(), 0U);
+ brillo::Blob decompressed;
+ EXPECT_TRUE(this->ZipDecompress(out, &decompressed));
+ EXPECT_EQ(in.size(), decompressed.size());
+ EXPECT_EQ(0, memcmp(in.data(), decompressed.data(), in.size()));
+}
+
} // namespace chromeos_update_engine