summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdenilson Cavalcanti <cavalcantii@chromium.org>2024-04-10 06:31:20 +0000
committerCopybara-Service <copybara-worker@google.com>2024-04-09 23:37:22 -0700
commit7d77fb7fd66d8a5640618ad32c71fdeb7d3e02df (patch)
tree5474f1fdfe7e9933da65e88dde0e95f5d989c730
parent37d9855c8db5a130571971e78fde2740314cd98a (diff)
downloadzlib-7d77fb7fd66d8a5640618ad32c71fdeb7d3e02df.tar.gz
[zlib] Add large payloads and compression levels unit testsupstream-master
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 <hans@chromium.org> Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org> Cr-Commit-Position: refs/heads/main@{#1284921} NOKEYCHECK=True GitOrigin-RevId: 2f4df1ff700345b6e643af224a859f6be5c4fda1
-rw-r--r--contrib/tests/utils_unittest.cc24
1 files 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<unsigned char> 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<unsigned long>(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();