Commit 272595ed authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

Adding a utest for small payloads

One of the optimizations (i.e. chunk_copy) will perform vector stores on
16 bytes chunks instead of the original 3 bytes scalar operations.

It is interesting to validate its safety while operating with small
payloads (i.e. data input smaller than a single load/store).

Even though it is a corner case (i.e. the payload would be smaller than
the wrapper used for the DEFLATE stream for GZIP), it is good to certify
that the optimization works as expected.

This will also add gtest as a dependency as the plan is to write some
tests to stress the optimizations we ship.

Bug: 1032721
Change-Id: Ifc6a81879e3dba6a9c4b7cfde80e7207258b934c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128836
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Reviewed-by: default avatarChris Blume <cblume@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757639}
parent 4df7011a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//build/config/compiler/compiler.gni") import("//build/config/compiler/compiler.gni")
import("//testing/test.gni")
if (current_cpu == "arm" || current_cpu == "arm64") { if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni") import("//build/config/arm.gni")
...@@ -384,3 +385,17 @@ executable("zlib_bench") { ...@@ -384,3 +385,17 @@ executable("zlib_bench") {
deps = [ ":zlib" ] deps = [ ":zlib" ]
} }
test("zlib_unittests") {
sources = [
"contrib/tests/utils_unittest.cc",
"google/compression_utils_portable.cc",
"google/compression_utils_portable.h",
]
deps = [
":zlib",
"//testing/gtest",
"//testing/gtest:gtest_main",
]
}
include_rules = [
"+testing/gtest",
]
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the Chromium source repository LICENSE file.
#include <cstddef>
#include <vector>
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/zlib/google/compression_utils_portable.h"
#include "zlib.h"
void TestPayloads(size_t input_size, zlib_internal::WrapperType type) {
std::vector<unsigned char> input;
input.reserve(input_size);
for (size_t i = 1; i <= input_size; ++i)
input.push_back(i & 0xff);
// If it is big enough for GZIP, will work for other wrappers.
std::vector<unsigned char> compressed(
zlib_internal::GzipExpectedCompressedSize(input.size()));
std::vector<unsigned char> decompressed(input.size());
// Libcores's java/util/zip/Deflater default settings: ZLIB,
// DEFAULT_COMPRESSION and DEFAULT_STRATEGY.
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);
ASSERT_EQ(result, Z_OK);
unsigned long decompressed_size =
static_cast<unsigned long>(decompressed.size());
result = zlib_internal::UncompressHelper(type, decompressed.data(),
&decompressed_size,
compressed.data(), compressed_size);
ASSERT_EQ(result, Z_OK);
EXPECT_EQ(input, decompressed);
}
TEST(ZlibTest, ZlibWrapper) {
// Minimal ZLIB wrapped short stream size is about 8 bytes.
for (size_t i = 1; i < 1024; ++i)
TestPayloads(i, zlib_internal::WrapperType::ZLIB);
}
TEST(ZlibTest, GzipWrapper) {
// GZIP should be 12 bytes bigger than ZLIB wrapper.
for (size_t i = 1; i < 1024; ++i)
TestPayloads(i, zlib_internal::WrapperType::GZIP);
}
TEST(ZlibTest, RawWrapper) {
// RAW has no wrapper (V8 Blobs is a known user), size
// should be payload_size + 2 for short payloads.
for (size_t i = 1; i < 1024; ++i)
TestPayloads(i, zlib_internal::WrapperType::ZRAW);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment