From 7d77fb7fd66d8a5640618ad32c71fdeb7d3e02df Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Wed, 10 Apr 2024 06:31:20 +0000 Subject: [zlib] Add large payloads and compression levels unit tests Larger payloads (i.e. bigger than 500KB) are helpful to detect programming issues in checksums (i.e. overflows) and this patch adds a new unit test to cover bigger payloads (6KB to 20MB). It also adds a new unit test to cover all the 9 compression levels supported by zlib (Z_DEFAULT_COMPRESSION is level 6). The new tests takes near 6s (3300ms + 3200ms) to run in a K230 board, but it is way faster in any decent modern CPU (i.e. 314ms + 320ms on Intel i7 11th gen). Bug: 329282661 Change-Id: I4d851799ae10f98d90b114560bed9ad48896e39d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5436095 Reviewed-by: Hans Wennborg Commit-Queue: Adenilson Cavalcanti Cr-Commit-Position: refs/heads/main@{#1284921} NOKEYCHECK=True GitOrigin-RevId: 2f4df1ff700345b6e643af224a859f6be5c4fda1 --- contrib/tests/utils_unittest.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/contrib/tests/utils_unittest.cc b/contrib/tests/utils_unittest.cc index 0cc1081..f487a06 100644 --- a/contrib/tests/utils_unittest.cc +++ b/contrib/tests/utils_unittest.cc @@ -20,7 +20,8 @@ #include "zlib.h" -void TestPayloads(size_t input_size, zlib_internal::WrapperType type) { +void TestPayloads(size_t input_size, zlib_internal::WrapperType type, + const int compression_level = Z_DEFAULT_COMPRESSION) { std::vector input; input.reserve(input_size); for (size_t i = 1; i <= input_size; ++i) @@ -36,7 +37,7 @@ void TestPayloads(size_t input_size, zlib_internal::WrapperType type) { unsigned long compressed_size = static_cast(compressed.size()); int result = zlib_internal::CompressHelper( type, compressed.data(), &compressed_size, input.data(), input.size(), - Z_DEFAULT_COMPRESSION, nullptr, nullptr); + compression_level, nullptr, nullptr); ASSERT_EQ(result, Z_OK); unsigned long decompressed_size = @@ -67,6 +68,25 @@ TEST(ZlibTest, RawWrapper) { TestPayloads(i, zlib_internal::WrapperType::ZRAW); } +TEST(ZlibTest, LargePayloads) { + static const size_t lengths[] = { 6000, 8000, 10'000, 15'000, 20'000, 30'000, + 50'000, 100'000, 150'000, 2'500'000, + 5'000'000, 10'000'000, 20'000'000 }; + + for (size_t length: lengths) { + TestPayloads(length, zlib_internal::WrapperType::ZLIB); + TestPayloads(length, zlib_internal::WrapperType::GZIP); + } +} + +TEST(ZlibTest, CompressionLevels) { + static const int levels[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + for (int level: levels) { + TestPayloads(5'000'000, zlib_internal::WrapperType::ZLIB, level); + TestPayloads(5'000'000, zlib_internal::WrapperType::GZIP, level); + } +} + TEST(ZlibTest, InflateCover) { cover_support(); cover_wrap(); -- cgit v1.2.3