CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
115 lines
4.1 KiB
C++
115 lines
4.1 KiB
C++
//===- llvm/unittest/Support/CompressionTest.cpp - Compression tests ------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements unit tests for the Compression functions.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Support/Compression.h"
|
|
#include "llvm/ADT/StringExtras.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Config/config.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::compression;
|
|
|
|
namespace {
|
|
|
|
#if LLVM_ENABLE_ZLIB
|
|
static void testZlibCompression(StringRef Input, int Level) {
|
|
SmallVector<uint8_t, 0> Compressed;
|
|
SmallVector<uint8_t, 0> Uncompressed;
|
|
zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
|
|
|
|
// Check that uncompressed buffer is the same as original.
|
|
Error E = zlib::decompress(Compressed, Uncompressed, Input.size());
|
|
EXPECT_FALSE(std::move(E));
|
|
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
|
|
|
// decompress with Z dispatches to zlib::decompress.
|
|
E = compression::decompress(DebugCompressionType::Zlib, Compressed,
|
|
Uncompressed, Input.size());
|
|
EXPECT_FALSE(std::move(E));
|
|
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
|
|
|
if (Input.size() > 0) {
|
|
// Decompression fails if expected length is too short.
|
|
E = zlib::decompress(Compressed, Uncompressed, Input.size() - 1);
|
|
EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
|
|
}
|
|
}
|
|
|
|
TEST(CompressionTest, Zlib) {
|
|
testZlibCompression("", zlib::DefaultCompression);
|
|
|
|
testZlibCompression("hello, world!", zlib::NoCompression);
|
|
testZlibCompression("hello, world!", zlib::BestSizeCompression);
|
|
testZlibCompression("hello, world!", zlib::BestSpeedCompression);
|
|
testZlibCompression("hello, world!", zlib::DefaultCompression);
|
|
|
|
const size_t kSize = 1024;
|
|
char BinaryData[kSize];
|
|
for (size_t i = 0; i < kSize; ++i)
|
|
BinaryData[i] = i & 255;
|
|
StringRef BinaryDataStr(BinaryData, kSize);
|
|
|
|
testZlibCompression(BinaryDataStr, zlib::NoCompression);
|
|
testZlibCompression(BinaryDataStr, zlib::BestSizeCompression);
|
|
testZlibCompression(BinaryDataStr, zlib::BestSpeedCompression);
|
|
testZlibCompression(BinaryDataStr, zlib::DefaultCompression);
|
|
}
|
|
#endif
|
|
|
|
#if LLVM_ENABLE_ZSTD
|
|
static void testZstdCompression(StringRef Input, int Level) {
|
|
SmallVector<uint8_t, 0> Compressed;
|
|
SmallVector<uint8_t, 0> Uncompressed;
|
|
zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
|
|
|
|
// Check that uncompressed buffer is the same as original.
|
|
Error E = zstd::decompress(Compressed, Uncompressed, Input.size());
|
|
EXPECT_FALSE(std::move(E));
|
|
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
|
|
|
// decompress with Zstd dispatches to zstd::decompress.
|
|
E = compression::decompress(DebugCompressionType::Zstd, Compressed,
|
|
Uncompressed, Input.size());
|
|
EXPECT_FALSE(std::move(E));
|
|
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
|
|
|
if (Input.size() > 0) {
|
|
// Decompression fails if expected length is too short.
|
|
E = zstd::decompress(Compressed, Uncompressed, Input.size() - 1);
|
|
EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
|
|
}
|
|
}
|
|
|
|
TEST(CompressionTest, Zstd) {
|
|
testZstdCompression("", zstd::DefaultCompression);
|
|
|
|
testZstdCompression("hello, world!", zstd::NoCompression);
|
|
testZstdCompression("hello, world!", zstd::BestSizeCompression);
|
|
testZstdCompression("hello, world!", zstd::BestSpeedCompression);
|
|
testZstdCompression("hello, world!", zstd::DefaultCompression);
|
|
|
|
const size_t kSize = 1024;
|
|
char BinaryData[kSize];
|
|
for (size_t i = 0; i < kSize; ++i)
|
|
BinaryData[i] = i & 255;
|
|
StringRef BinaryDataStr(BinaryData, kSize);
|
|
|
|
testZstdCompression(BinaryDataStr, zstd::NoCompression);
|
|
testZstdCompression(BinaryDataStr, zstd::BestSizeCompression);
|
|
testZstdCompression(BinaryDataStr, zstd::BestSpeedCompression);
|
|
testZstdCompression(BinaryDataStr, zstd::DefaultCompression);
|
|
}
|
|
#endif
|
|
}
|