test-compress.c revision e3cc7fc45b395416462200e61af6877966488ea0
/***
This file is part of systemd
Copyright 2014 Ronny Chevalier
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_LZ4
#include <lz4.h>
#endif
#include "alloc-util.h"
#include "compress.h"
#include "fd-util.h"
#include "fileio.h"
#include "macro.h"
#include "random-util.h"
#include "util.h"
#ifdef HAVE_XZ
# define XZ_OK 0
#else
# define XZ_OK -EPROTONOSUPPORT
#endif
#ifdef HAVE_LZ4
# define LZ4_OK 0
#else
# define LZ4_OK -EPROTONOSUPPORT
#endif
static void test_compress_decompress(int compression,
const char *data,
bool may_fail) {
char compressed[512];
int r;
log_info("/* testing %s %s blob compression/decompression */",
if (r == -ENOBUFS) {
log_info_errno(r, "compression failed: %m");
} else {
assert_se(r == 0);
assert_se(r == 0);
}
assert_se(r < 0);
/* make sure to have the minimal lz4 compressed size */
assert_se(r < 0);
assert_se(r < 0);
}
static void test_decompress_startswith(int compression,
const char *data,
bool may_fail) {
char compressed[512];
int r;
log_info("/* testing decompress_startswith with %s on %s text*/",
if (r == -ENOBUFS) {
log_info_errno(r, "compression failed: %m");
return;
}
assert_se(r == 0);
(void **) &decompressed,
&usize,
(void **) &decompressed,
&usize,
(void **) &decompressed,
&usize,
"barbarbar", 9, ' ') == 0);
(void **) &decompressed,
&usize,
}
static void test_compress_stream(int compression,
const char* cat,
const char *srcfile) {
char pattern[] = "/tmp/systemd-test.compressed.XXXXXX",
int r;
log_debug("/* testing %s compression */",
log_debug("/* test compression */");
if (cat) {
}
log_debug("/* test decompression */");
assert_se(r == 0);
log_debug("/* test faulty decompression */");
}
#ifdef HAVE_LZ4
static void test_lz4_decompress_partial(void) {
char buf[20000];
int r;
assert_se(r >= 0);
compressed = r;
assert_se(r >= 0);
log_info("Decompressed → %i", r);
12, (int) sizeof(huge));
assert_se(r >= 0);
/* We expect this to fail, because that's how current lz4 works. If this
* call succeeds, then lz4 has been fixed, and we need to change our code.
*/
assert_se(r < 0);
}
#endif
const char text[] =
"text\0foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF"
"foofoofoofoo AAAA aaaaaaaaa ghost busters barbarbar FFF";
#ifdef HAVE_XZ
#else
log_info("/* XZ test skipped */");
#endif
#ifdef HAVE_LZ4
#else
log_info("/* LZ4 test skipped */");
#endif
return 0;
}