blob: 14b1a373146eabe4d835b7e501279fba03e93402 [file] [log] [blame]
David Reissfaebedd2007-09-17 23:20:38 +00001/*
David Reissea2cba82009-03-30 21:35:00 +00002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
David Reiss3cc9dab2010-10-06 17:10:21 +000020#define __STDC_LIMIT_MACROS
21#define __STDC_FORMAT_MACROS
22
David Reiss9a961e72010-10-06 17:10:23 +000023#ifndef _GNU_SOURCE
24#define _GNU_SOURCE // needed for getopt_long
25#endif
26
David Reiss3cc9dab2010-10-06 17:10:21 +000027#include <stdint.h>
28#include <inttypes.h>
David Reissfaebedd2007-09-17 23:20:38 +000029#include <cstddef>
David Reissfaebedd2007-09-17 23:20:38 +000030#include <fstream>
31#include <iostream>
Jake Farrell5d02b802014-01-07 21:42:01 -050032#include <thrift/cxxfunctional.h>
David Reiss3cc9dab2010-10-06 17:10:21 +000033
34#include <boost/random.hpp>
David Reiss9a961e72010-10-06 17:10:23 +000035#include <boost/shared_array.hpp>
36#include <boost/test/unit_test.hpp>
David Reiss3cc9dab2010-10-06 17:10:21 +000037
Roger Meier49ff8b12012-04-13 09:12:31 +000038#include <thrift/transport/TBufferTransports.h>
39#include <thrift/transport/TZlibTransport.h>
David Reissfaebedd2007-09-17 23:20:38 +000040
David Reiss9a961e72010-10-06 17:10:23 +000041using namespace std;
David Reiss9a961e72010-10-06 17:10:23 +000042using namespace apache::thrift::transport;
43
David Reissf2abcf92010-10-06 17:10:24 +000044boost::mt19937 rng;
David Reissfaebedd2007-09-17 23:20:38 +000045
David Reissf2abcf92010-10-06 17:10:24 +000046/*
47 * Utility code
48 */
David Reissfaebedd2007-09-17 23:20:38 +000049
David Reissf2abcf92010-10-06 17:10:24 +000050class SizeGenerator {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010051public:
David Reissf2abcf92010-10-06 17:10:24 +000052 virtual ~SizeGenerator() {}
53 virtual unsigned int getSize() = 0;
David Reissfaebedd2007-09-17 23:20:38 +000054};
55
David Reissf2abcf92010-10-06 17:10:24 +000056class ConstantSizeGenerator : public SizeGenerator {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010057public:
David Reissf2abcf92010-10-06 17:10:24 +000058 ConstantSizeGenerator(unsigned int value) : value_(value) {}
Konrad Grochowski16a23a62014-11-13 15:33:38 +010059 virtual unsigned int getSize() { return value_; }
David Reissf2abcf92010-10-06 17:10:24 +000060
Konrad Grochowski16a23a62014-11-13 15:33:38 +010061private:
David Reissf2abcf92010-10-06 17:10:24 +000062 unsigned int value_;
63};
64
65class LogNormalSizeGenerator : public SizeGenerator {
Konrad Grochowski16a23a62014-11-13 15:33:38 +010066public:
67 LogNormalSizeGenerator(double mean, double std_dev)
68 : gen_(rng, boost::lognormal_distribution<double>(mean, std_dev)) {}
David Reissf2abcf92010-10-06 17:10:24 +000069
70 virtual unsigned int getSize() {
71 // Loop until we get a size of 1 or more
72 while (true) {
73 unsigned int value = static_cast<unsigned int>(gen_());
74 if (value >= 1) {
75 return value;
76 }
77 }
78 }
79
Konrad Grochowski16a23a62014-11-13 15:33:38 +010080private:
81 boost::variate_generator<boost::mt19937, boost::lognormal_distribution<double> > gen_;
David Reissf2abcf92010-10-06 17:10:24 +000082};
David Reiss3cc9dab2010-10-06 17:10:21 +000083
84uint8_t* gen_uniform_buffer(uint32_t buf_len, uint8_t c) {
85 uint8_t* buf = new uint8_t[buf_len];
86 memset(buf, c, buf_len);
87 return buf;
88}
89
90uint8_t* gen_compressible_buffer(uint32_t buf_len) {
91 uint8_t* buf = new uint8_t[buf_len];
92
93 // Generate small runs of alternately increasing and decreasing bytes
94 boost::uniform_smallint<uint32_t> run_length_distribution(1, 64);
95 boost::uniform_smallint<uint8_t> byte_distribution(0, UINT8_MAX);
Konrad Grochowski16a23a62014-11-13 15:33:38 +010096 boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint8_t> >
97 byte_generator(rng, byte_distribution);
98 boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint32_t> >
99 run_len_generator(rng, run_length_distribution);
David Reiss3cc9dab2010-10-06 17:10:21 +0000100
101 uint32_t idx = 0;
102 int8_t step = 1;
103 while (idx < buf_len) {
104 uint32_t run_length = run_len_generator();
105 if (idx + run_length > buf_len) {
106 run_length = buf_len - idx;
107 }
108
109 uint8_t byte = byte_generator();
110 for (uint32_t n = 0; n < run_length; ++n) {
111 buf[idx] = byte;
112 ++idx;
113 byte += step;
114 }
115
116 step *= -1;
117 }
118
119 return buf;
120}
121
122uint8_t* gen_random_buffer(uint32_t buf_len) {
123 uint8_t* buf = new uint8_t[buf_len];
124
125 boost::uniform_smallint<uint8_t> distribution(0, UINT8_MAX);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100126 boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint8_t> >
127 generator(rng, distribution);
David Reiss3cc9dab2010-10-06 17:10:21 +0000128
129 for (uint32_t n = 0; n < buf_len; ++n) {
130 buf[n] = generator();
131 }
132
133 return buf;
134}
David Reissfaebedd2007-09-17 23:20:38 +0000135
David Reissf2abcf92010-10-06 17:10:24 +0000136/*
137 * Test functions
138 */
139
David Reiss9a961e72010-10-06 17:10:23 +0000140void test_write_then_read(const uint8_t* buf, uint32_t buf_len) {
Roger Meier611f90c2011-12-11 22:08:51 +0000141 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
142 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reiss9a961e72010-10-06 17:10:23 +0000143 zlib_trans->write(buf, buf_len);
David Reisse94fa332010-10-06 17:10:26 +0000144 zlib_trans->finish();
David Reissfaebedd2007-09-17 23:20:38 +0000145
David Reiss9a961e72010-10-06 17:10:23 +0000146 boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
David Reiss0a2d81e2010-10-06 17:10:40 +0000147 uint32_t got = zlib_trans->readAll(mirror.get(), buf_len);
David Reiss9a961e72010-10-06 17:10:23 +0000148 BOOST_REQUIRE_EQUAL(got, buf_len);
149 BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf, buf_len), 0);
150 zlib_trans->verifyChecksum();
151}
David Reissfaebedd2007-09-17 23:20:38 +0000152
David Reiss9a961e72010-10-06 17:10:23 +0000153void test_separate_checksum(const uint8_t* buf, uint32_t buf_len) {
154 // This one is tricky. I separate the last byte of the stream out
155 // into a separate crbuf_. The last byte is part of the checksum,
156 // so the entire read goes fine, but when I go to verify the checksum
157 // it isn't there. The original implementation complained that
158 // the stream was not complete. I'm about to go fix that.
159 // It worked. Awesome.
Roger Meier611f90c2011-12-11 22:08:51 +0000160 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
161 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reiss9a961e72010-10-06 17:10:23 +0000162 zlib_trans->write(buf, buf_len);
David Reisse94fa332010-10-06 17:10:26 +0000163 zlib_trans->finish();
David Reiss9a961e72010-10-06 17:10:23 +0000164 string tmp_buf;
165 membuf->appendBufferToString(tmp_buf);
David Reissa0e11592010-10-06 17:10:27 +0000166 zlib_trans.reset(new TZlibTransport(membuf,
David Reiss9a961e72010-10-06 17:10:23 +0000167 TZlibTransport::DEFAULT_URBUF_SIZE,
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100168 static_cast<uint32_t>(tmp_buf.length() - 1)));
David Reissfaebedd2007-09-17 23:20:38 +0000169
David Reiss9a961e72010-10-06 17:10:23 +0000170 boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
David Reiss0a2d81e2010-10-06 17:10:40 +0000171 uint32_t got = zlib_trans->readAll(mirror.get(), buf_len);
David Reiss9a961e72010-10-06 17:10:23 +0000172 BOOST_REQUIRE_EQUAL(got, buf_len);
173 BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf, buf_len), 0);
174 zlib_trans->verifyChecksum();
175}
David Reissfaebedd2007-09-17 23:20:38 +0000176
David Reiss9a961e72010-10-06 17:10:23 +0000177void test_incomplete_checksum(const uint8_t* buf, uint32_t buf_len) {
178 // Make sure we still get that "not complete" error if
179 // it really isn't complete.
Roger Meier611f90c2011-12-11 22:08:51 +0000180 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
181 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reiss9a961e72010-10-06 17:10:23 +0000182 zlib_trans->write(buf, buf_len);
David Reisse94fa332010-10-06 17:10:26 +0000183 zlib_trans->finish();
David Reiss9a961e72010-10-06 17:10:23 +0000184 string tmp_buf;
185 membuf->appendBufferToString(tmp_buf);
186 tmp_buf.erase(tmp_buf.length() - 1);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100187 membuf->resetBuffer(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(tmp_buf.data())),
Jake Farrell5d02b802014-01-07 21:42:01 -0500188 static_cast<uint32_t>(tmp_buf.length()));
David Reiss9a961e72010-10-06 17:10:23 +0000189
190 boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
David Reiss0a2d81e2010-10-06 17:10:40 +0000191 uint32_t got = zlib_trans->readAll(mirror.get(), buf_len);
David Reiss9a961e72010-10-06 17:10:23 +0000192 BOOST_REQUIRE_EQUAL(got, buf_len);
193 BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf, buf_len), 0);
194 try {
195 zlib_trans->verifyChecksum();
196 BOOST_ERROR("verifyChecksum() did not report an error");
197 } catch (TTransportException& ex) {
198 BOOST_CHECK_EQUAL(ex.getType(), TTransportException::CORRUPTED_DATA);
199 }
200}
201
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100202void test_read_write_mix(const uint8_t* buf,
203 uint32_t buf_len,
Roger Meier611f90c2011-12-11 22:08:51 +0000204 const boost::shared_ptr<SizeGenerator>& write_gen,
205 const boost::shared_ptr<SizeGenerator>& read_gen) {
David Reiss9a961e72010-10-06 17:10:23 +0000206 // Try it with a mix of read/write sizes.
Roger Meier611f90c2011-12-11 22:08:51 +0000207 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
208 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reiss9a961e72010-10-06 17:10:23 +0000209 unsigned int tot;
210
David Reiss9a961e72010-10-06 17:10:23 +0000211 tot = 0;
212 while (tot < buf_len) {
David Reissf2abcf92010-10-06 17:10:24 +0000213 uint32_t write_len = write_gen->getSize();
David Reiss9a961e72010-10-06 17:10:23 +0000214 if (tot + write_len > buf_len) {
215 write_len = buf_len - tot;
David Reissfaebedd2007-09-17 23:20:38 +0000216 }
David Reiss9a961e72010-10-06 17:10:23 +0000217 zlib_trans->write(buf + tot, write_len);
218 tot += write_len;
David Reiss9a961e72010-10-06 17:10:23 +0000219 }
David Reissfaebedd2007-09-17 23:20:38 +0000220
David Reisse94fa332010-10-06 17:10:26 +0000221 zlib_trans->finish();
David Reiss9a961e72010-10-06 17:10:23 +0000222
David Reiss9a961e72010-10-06 17:10:23 +0000223 tot = 0;
224 boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
225 while (tot < buf_len) {
David Reissf2abcf92010-10-06 17:10:24 +0000226 uint32_t read_len = read_gen->getSize();
David Reiss9a961e72010-10-06 17:10:23 +0000227 uint32_t expected_read_len = read_len;
228 if (tot + read_len > buf_len) {
229 expected_read_len = buf_len - tot;
David Reissfaebedd2007-09-17 23:20:38 +0000230 }
David Reiss9a961e72010-10-06 17:10:23 +0000231 uint32_t got = zlib_trans->read(mirror.get() + tot, read_len);
David Reiss0a2d81e2010-10-06 17:10:40 +0000232 BOOST_REQUIRE_LE(got, expected_read_len);
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100233 BOOST_REQUIRE_NE(got, (uint32_t)0);
David Reiss9a961e72010-10-06 17:10:23 +0000234 tot += got;
David Reiss9a961e72010-10-06 17:10:23 +0000235 }
David Reissfaebedd2007-09-17 23:20:38 +0000236
David Reiss9a961e72010-10-06 17:10:23 +0000237 BOOST_CHECK_EQUAL(memcmp(mirror.get(), buf, buf_len), 0);
238 zlib_trans->verifyChecksum();
239}
David Reissfaebedd2007-09-17 23:20:38 +0000240
David Reiss9a961e72010-10-06 17:10:23 +0000241void test_invalid_checksum(const uint8_t* buf, uint32_t buf_len) {
242 // Verify checksum checking.
Roger Meier611f90c2011-12-11 22:08:51 +0000243 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
244 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reiss9a961e72010-10-06 17:10:23 +0000245 zlib_trans->write(buf, buf_len);
David Reisse94fa332010-10-06 17:10:26 +0000246 zlib_trans->finish();
David Reiss9a961e72010-10-06 17:10:23 +0000247 string tmp_buf;
248 membuf->appendBufferToString(tmp_buf);
249 // Modify a byte at the end of the buffer (part of the checksum).
250 // On rare occasions, modifying a byte in the middle of the buffer
251 // isn't caught by the checksum.
252 //
253 // (This happens especially often for the uniform buffer. The
254 // re-inflated data is correct, however. I suspect in this case that
255 // we're more likely to modify bytes that are part of zlib metadata
256 // instead of the actual compressed data.)
257 //
258 // I've also seen some failure scenarios where a checksum failure isn't
259 // reported, but zlib keeps trying to decode past the end of the data.
260 // (When this occurs, verifyChecksum() throws an exception indicating
261 // that the end of the data hasn't been reached.) I haven't seen this
262 // error when only modifying checksum bytes.
Jake Farrell5d02b802014-01-07 21:42:01 -0500263 int index = static_cast<int>(tmp_buf.size() - 1);
David Reiss9a961e72010-10-06 17:10:23 +0000264 tmp_buf[index]++;
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100265 membuf->resetBuffer(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(tmp_buf.data())),
Jake Farrell5d02b802014-01-07 21:42:01 -0500266 static_cast<uint32_t>(tmp_buf.length()));
David Reissfaebedd2007-09-17 23:20:38 +0000267
David Reiss9a961e72010-10-06 17:10:23 +0000268 boost::shared_array<uint8_t> mirror(new uint8_t[buf_len]);
269 try {
David Reiss0a2d81e2010-10-06 17:10:40 +0000270 zlib_trans->readAll(mirror.get(), buf_len);
David Reiss9a961e72010-10-06 17:10:23 +0000271 zlib_trans->verifyChecksum();
272 BOOST_ERROR("verifyChecksum() did not report an error");
273 } catch (TZlibTransportException& ex) {
274 BOOST_CHECK_EQUAL(ex.getType(), TTransportException::INTERNAL_ERROR);
275 }
276}
David Reissfaebedd2007-09-17 23:20:38 +0000277
David Reisse94fa332010-10-06 17:10:26 +0000278void test_write_after_flush(const uint8_t* buf, uint32_t buf_len) {
279 // write some data
Roger Meier611f90c2011-12-11 22:08:51 +0000280 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
281 boost::shared_ptr<TZlibTransport> zlib_trans(new TZlibTransport(membuf));
David Reisse94fa332010-10-06 17:10:26 +0000282 zlib_trans->write(buf, buf_len);
283
284 // call finish()
285 zlib_trans->finish();
286
287 // make sure write() throws an error
288 try {
289 uint8_t write_buf[] = "a";
290 zlib_trans->write(write_buf, 1);
291 BOOST_ERROR("write() after finish() did not raise an exception");
292 } catch (TTransportException& ex) {
293 BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
294 }
295
296 // make sure flush() throws an error
297 try {
298 zlib_trans->flush();
299 BOOST_ERROR("flush() after finish() did not raise an exception");
300 } catch (TTransportException& ex) {
301 BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
302 }
303
304 // make sure finish() throws an error
305 try {
306 zlib_trans->finish();
307 BOOST_ERROR("finish() after finish() did not raise an exception");
308 } catch (TTransportException& ex) {
309 BOOST_CHECK_EQUAL(ex.getType(), TTransportException::BAD_ARGS);
310 }
311}
312
313void test_no_write() {
314 // Verify that no data is written to the underlying transport if we
315 // never write data to the TZlibTransport.
Roger Meier611f90c2011-12-11 22:08:51 +0000316 boost::shared_ptr<TMemoryBuffer> membuf(new TMemoryBuffer());
David Reisse94fa332010-10-06 17:10:26 +0000317 {
318 // Create a TZlibTransport object, and immediately destroy it
319 // when it goes out of scope.
David Reissa0e11592010-10-06 17:10:27 +0000320 TZlibTransport w_zlib_trans(membuf);
David Reisse94fa332010-10-06 17:10:26 +0000321 }
322
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100323 BOOST_CHECK_EQUAL(membuf->available_read(), (uint32_t)0);
David Reisse94fa332010-10-06 17:10:26 +0000324}
325
David Reissf2abcf92010-10-06 17:10:24 +0000326/*
327 * Initialization
328 */
329
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100330#define ADD_TEST_CASE(suite, name, function, ...) \
331 do { \
332 ::std::ostringstream name_ss; \
333 name_ss << name << "-" << BOOST_STRINGIZE(function); \
334 ::boost::unit_test::test_case* tc \
335 = ::boost::unit_test::make_test_case(::apache::thrift::stdcxx::bind(function, \
336 ##__VA_ARGS__), \
337 name_ss.str()); \
338 (suite)->add(tc); \
David Reiss9a961e72010-10-06 17:10:23 +0000339 } while (0)
David Reissfaebedd2007-09-17 23:20:38 +0000340
Jake Farrell5d02b802014-01-07 21:42:01 -0500341void add_tests(boost::unit_test::test_suite* suite,
David Reiss9a961e72010-10-06 17:10:23 +0000342 const uint8_t* buf,
343 uint32_t buf_len,
344 const char* name) {
345 ADD_TEST_CASE(suite, name, test_write_then_read, buf, buf_len);
346 ADD_TEST_CASE(suite, name, test_separate_checksum, buf, buf_len);
347 ADD_TEST_CASE(suite, name, test_incomplete_checksum, buf, buf_len);
David Reiss9a961e72010-10-06 17:10:23 +0000348 ADD_TEST_CASE(suite, name, test_invalid_checksum, buf, buf_len);
David Reisse94fa332010-10-06 17:10:26 +0000349 ADD_TEST_CASE(suite, name, test_write_after_flush, buf, buf_len);
David Reissf2abcf92010-10-06 17:10:24 +0000350
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100351 boost::shared_ptr<SizeGenerator> size_32k(new ConstantSizeGenerator(1 << 15));
Roger Meier611f90c2011-12-11 22:08:51 +0000352 boost::shared_ptr<SizeGenerator> size_lognormal(new LogNormalSizeGenerator(20, 30));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100353 ADD_TEST_CASE(suite, name << "-constant", test_read_write_mix, buf, buf_len, size_32k, size_32k);
354 ADD_TEST_CASE(suite,
355 name << "-lognormal-write",
356 test_read_write_mix,
357 buf,
358 buf_len,
359 size_lognormal,
360 size_32k);
361 ADD_TEST_CASE(suite,
362 name << "-lognormal-read",
363 test_read_write_mix,
364 buf,
365 buf_len,
366 size_32k,
367 size_lognormal);
368 ADD_TEST_CASE(suite,
369 name << "-lognormal-both",
370 test_read_write_mix,
371 buf,
372 buf_len,
373 size_lognormal,
374 size_lognormal);
David Reissf2abcf92010-10-06 17:10:24 +0000375
376 // Test with a random size distribution,
377 // but use the exact same distribution for reading as for writing.
378 //
379 // Because the SizeGenerator makes a copy of the random number generator,
380 // both SizeGenerators should return the exact same set of values, since they
381 // both start with random number generators in the same state.
Roger Meier611f90c2011-12-11 22:08:51 +0000382 boost::shared_ptr<SizeGenerator> write_size_gen(new LogNormalSizeGenerator(20, 30));
383 boost::shared_ptr<SizeGenerator> read_size_gen(new LogNormalSizeGenerator(20, 30));
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100384 ADD_TEST_CASE(suite,
385 name << "-lognormal-same-distribution",
386 test_read_write_mix,
387 buf,
388 buf_len,
389 write_size_gen,
390 read_size_gen);
David Reiss9a961e72010-10-06 17:10:23 +0000391}
392
393void print_usage(FILE* f, const char* argv0) {
394 fprintf(f, "Usage: %s [boost_options] [options]\n", argv0);
395 fprintf(f, "Options:\n");
396 fprintf(f, " --seed=<N>, -s <N>\n");
397 fprintf(f, " --help\n");
398}
399
Jake Farrell5d02b802014-01-07 21:42:01 -0500400boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) {
Konrad Grochowskib3f5ffc2014-11-06 19:32:59 +0100401 THRIFT_UNUSED_VARIABLE(argc);
402 THRIFT_UNUSED_VARIABLE(argv);
Jake Farrell5d02b802014-01-07 21:42:01 -0500403 uint32_t seed = static_cast<uint32_t>(time(NULL));
David Reiss9a961e72010-10-06 17:10:23 +0000404 printf("seed: %" PRIu32 "\n", seed);
405 rng.seed(seed);
David Reiss9a961e72010-10-06 17:10:23 +0000406
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100407 boost::unit_test::test_suite* suite = &boost::unit_test::framework::master_test_suite();
David Reiss109693c2010-10-06 17:10:42 +0000408 suite->p_name.value = "ZlibTest";
David Reiss9a961e72010-10-06 17:10:23 +0000409
Konrad Grochowski16a23a62014-11-13 15:33:38 +0100410 uint32_t buf_len = 1024 * 32;
David Reiss9a961e72010-10-06 17:10:23 +0000411 add_tests(suite, gen_uniform_buffer(buf_len, 'a'), buf_len, "uniform");
412 add_tests(suite, gen_compressible_buffer(buf_len), buf_len, "compressible");
413 add_tests(suite, gen_random_buffer(buf_len), buf_len, "random");
414
David Reisse94fa332010-10-06 17:10:26 +0000415 suite->add(BOOST_TEST_CASE(test_no_write));
416
David Reiss109693c2010-10-06 17:10:42 +0000417 return NULL;
David Reissfaebedd2007-09-17 23:20:38 +0000418}