16#define BLOCK_SIZE 1500
34#define SUPPORT_SWAP false
55 constexpr size_t headroom = 512;
56 constexpr size_t tailroom = 512;
57 constexpr size_t align_block = 16;
75 void error(
const size_t err_type,
const std::string *text = NULL)
override
94 ASSERT_EQ(b1, b2) <<
"decompressed data doesn't match original data";
97void test(
const std::string &filename,
101 const size_t block_size,
102 const size_t n_compress,
103 const size_t n_expand_per_compress,
105 size_t &compress_bytes)
108 for (
size_t offset = 0; offset < source_data->size(); offset += block_size)
110 const size_t length = std::min(block_size, source_data->size() - offset);
113 data_seg.
write(source_data->data_raw() + offset, length);
114 for (
size_t compress_iter = 0; compress_iter < n_compress; ++compress_iter)
117 bytes += data1.
size();
119 compress_bytes += data1.
size();
120 if (n_expand_per_compress == 1)
127 for (
size_t decompress_iter = 0; decompress_iter < n_expand_per_compress; ++decompress_iter)
141 const size_t block_size,
142 const size_t n_compress,
143 const size_t n_expand_per_compress,
145 size_t &compress_bytes)
147 static const std::vector<std::string> filenames = {
148 "comp-testdata/alice29.txt",
149 "comp-testdata/asyoulik.txt",
150 "comp-testdata/cp.html",
151 "comp-testdata/fields.c",
152 "comp-testdata/geo.protodata",
153 "comp-testdata/grammar.lsp",
154 "comp-testdata/house.jpg",
155 "comp-testdata/html",
156 "comp-testdata/html_x_4",
157 "comp-testdata/kennedy.xls",
158 "comp-testdata/kppkn.gtb",
159 "comp-testdata/lcet10.txt",
160 "comp-testdata/mapreduce-osdi-1.pdf",
161 "comp-testdata/plrabn12.txt",
162 "comp-testdata/ptt5",
164 "comp-testdata/urls.10K",
165 "comp-testdata/xargs.1",
167 for (
const auto &fn : filenames)
169 test(std::string(UNITTEST_SOURCE_DIR) +
'/' + fn,
175 n_expand_per_compress,
209 decompress = compress;
216 decompress = compress;
222 decompress = compress;
226 ASSERT_TRUE(
false) <<
"compressor/decompressor pair not supported";
229 size_t compress_bytes = 0;
233 std::cout <<
"comp=" << compress->name() <<
'[' <<
N_COMPRESS <<
']'
234 <<
" decomp=" << decompress->name() <<
'[' <<
N_EXPAND <<
']'
236 <<
" bytes=" << bytes
237 <<
" comp-bytes=" << compress_bytes
238 <<
" comp-ratio=" << (bytes ?
static_cast<float>(compress_bytes) /
static_cast<float>(bytes) : 0.0)
244TEST(Compression, Snappy)
250TEST(Compression, Lzo)
255TEST(Compression, Lzoasym)
261TEST(Compression, Lz4)
void error(const size_t err_type, const std::string *text=NULL) override
count_t errors[Error::N_ERRORS]
count_t get_error_count(const Error::Type type) const
static void init_static()
virtual void decompress(BufferAllocated &buf)=0
virtual void compress(BufferAllocated &buf, const bool hint)=0
size_t size() const
Returns the size of the buffer in T objects.
void write(const T *data, const size_t size)
Write data to the buffer.
size_t prepare(const unsigned int context, Buffer &buf) const
void standardize_capacity(const unsigned int context_mask)
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
constexpr BufferFlags NO_FLAGS(0U)
no flags set
BufferPtr read_binary(const std::string &filename, const std::uint64_t max_size=0, const BufferFlags buffer_flags=BufAllocFlags::NO_FLAGS)
Frame::Ptr frame_init(const bool align_adjust_3_1, const size_t tun_mtu_max, const size_t control_channel_payload, const bool verbose)
TEST(CPUTime, CpuTimePid)
void test_with_corpus(Compress &compressor, Compress &decompressor, const Frame &frame, const size_t block_size, const size_t n_compress, const size_t n_expand_per_compress, size_t &bytes, size_t &compress_bytes)
void verify_eq(const Buffer &b1, const Buffer &b2)
void runTest(comppair alg, bool verbose=false)