]>
git.proxmox.com Git - mirror_spl.git/blob - module/splat/splat-zlib.c
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting LAyer Tests (SPLAT) Zlib Compression Tests.
25 \*****************************************************************************/
28 #include <sys/random.h>
30 #include "splat-internal.h"
32 #define SPLAT_ZLIB_NAME "zlib"
33 #define SPLAT_ZLIB_DESC "Zlib Compression Tests"
35 #define SPLAT_ZLIB_TEST1_ID 0x0f01
36 #define SPLAT_ZLIB_TEST1_NAME "compress/uncompress"
37 #define SPLAT_ZLIB_TEST1_DESC "Compress/Uncompress Test"
39 #define BUFFER_SIZE (128 * 1024)
42 splat_zlib_test1_check(struct file
*file
, void *src
, void *dst
, void *chk
,
45 size_t dst_len
= BUFFER_SIZE
;
46 size_t chk_len
= BUFFER_SIZE
;
49 memset(dst
, 0, BUFFER_SIZE
);
50 memset(chk
, 0, BUFFER_SIZE
);
52 rc
= z_compress_level(dst
, &dst_len
, src
, BUFFER_SIZE
, level
);
54 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
55 "Failed level %d z_compress_level(), %d\n", level
, rc
);
59 rc
= z_uncompress(chk
, &chk_len
, dst
, dst_len
);
61 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
62 "Failed level %d z_uncompress(), %d\n", level
, rc
);
66 rc
= memcmp(src
, chk
, BUFFER_SIZE
);
68 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
69 "Failed level %d memcmp()), %d\n", level
, rc
);
73 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
74 "Passed level %d, compressed %d bytes to %d bytes\n",
75 level
, BUFFER_SIZE
, (int)dst_len
);
81 * Compress a buffer, uncompress the newly compressed buffer, then
82 * compare it to the original. Do this for all 9 compression levels.
85 splat_zlib_test1(struct file
*file
, void *arg
)
87 void *src
= NULL
, *dst
= NULL
, *chk
= NULL
;
90 src
= vmalloc(BUFFER_SIZE
);
96 dst
= vmalloc(BUFFER_SIZE
);
102 chk
= vmalloc(BUFFER_SIZE
);
108 /* Source buffer is a repeating 1024 byte random pattern. */
109 random_get_pseudo_bytes(src
, sizeof(uint8_t) * 1024);
110 for (i
= 1; i
< 128; i
++)
111 memcpy(src
+ (i
* 1024), src
, 1024);
113 for (level
= 1; level
<= 9; level
++)
114 if ((rc
= splat_zlib_test1_check(file
, src
, dst
, chk
, level
)))
130 splat_zlib_init(void)
132 splat_subsystem_t
*sub
;
134 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
138 memset(sub
, 0, sizeof(*sub
));
139 strncpy(sub
->desc
.name
, SPLAT_ZLIB_NAME
, SPLAT_NAME_SIZE
);
140 strncpy(sub
->desc
.desc
, SPLAT_ZLIB_DESC
, SPLAT_DESC_SIZE
);
141 INIT_LIST_HEAD(&sub
->subsystem_list
);
142 INIT_LIST_HEAD(&sub
->test_list
);
143 spin_lock_init(&sub
->test_lock
);
144 sub
->desc
.id
= SPLAT_SUBSYSTEM_ZLIB
;
146 SPLAT_TEST_INIT(sub
, SPLAT_ZLIB_TEST1_NAME
, SPLAT_ZLIB_TEST1_DESC
,
147 SPLAT_ZLIB_TEST1_ID
, splat_zlib_test1
);
153 splat_zlib_fini(splat_subsystem_t
*sub
)
157 SPLAT_TEST_FINI(sub
, SPLAT_ZLIB_TEST1_ID
);
163 splat_zlib_id(void) {
164 return SPLAT_SUBSYSTEM_ZLIB
;