]>
git.proxmox.com Git - mirror_spl-debian.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>
31 #include "splat-internal.h"
33 #define SPLAT_ZLIB_NAME "zlib"
34 #define SPLAT_ZLIB_DESC "Zlib Compression Tests"
36 #define SPLAT_ZLIB_TEST1_ID 0x0f01
37 #define SPLAT_ZLIB_TEST1_NAME "compress/uncompress"
38 #define SPLAT_ZLIB_TEST1_DESC "Compress/Uncompress Test"
40 #define BUFFER_SIZE (128 * 1024)
43 splat_zlib_test1_check(struct file
*file
, void *src
, void *dst
, void *chk
,
46 size_t dst_len
= BUFFER_SIZE
;
47 size_t chk_len
= BUFFER_SIZE
;
50 memset(dst
, 0, BUFFER_SIZE
);
51 memset(chk
, 0, BUFFER_SIZE
);
53 rc
= z_compress_level(dst
, &dst_len
, src
, BUFFER_SIZE
, level
);
55 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
56 "Failed level %d z_compress_level(), %d\n", level
, rc
);
60 rc
= z_uncompress(chk
, &chk_len
, dst
, dst_len
);
62 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
63 "Failed level %d z_uncompress(), %d\n", level
, rc
);
67 rc
= memcmp(src
, chk
, BUFFER_SIZE
);
69 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
70 "Failed level %d memcmp()), %d\n", level
, rc
);
74 splat_vprint(file
, SPLAT_ZLIB_TEST1_NAME
,
75 "Passed level %d, compressed %d bytes to %d bytes\n",
76 level
, BUFFER_SIZE
, (int)dst_len
);
82 * Compress a buffer, uncompress the newly compressed buffer, then
83 * compare it to the original. Do this for all 9 compression levels.
86 splat_zlib_test1(struct file
*file
, void *arg
)
88 void *src
= NULL
, *dst
= NULL
, *chk
= NULL
;
91 src
= vmalloc(BUFFER_SIZE
);
97 dst
= vmalloc(BUFFER_SIZE
);
103 chk
= vmalloc(BUFFER_SIZE
);
109 /* Source buffer is a repeating 1024 byte random pattern. */
110 random_get_pseudo_bytes(src
, sizeof(uint8_t) * 1024);
111 for (i
= 1; i
< 128; i
++)
112 memcpy(src
+ (i
* 1024), src
, 1024);
114 for (level
= 1; level
<= 9; level
++)
115 if ((rc
= splat_zlib_test1_check(file
, src
, dst
, chk
, level
)))
131 splat_zlib_init(void)
133 splat_subsystem_t
*sub
;
135 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
139 memset(sub
, 0, sizeof(*sub
));
140 strncpy(sub
->desc
.name
, SPLAT_ZLIB_NAME
, SPLAT_NAME_SIZE
);
141 strncpy(sub
->desc
.desc
, SPLAT_ZLIB_DESC
, SPLAT_DESC_SIZE
);
142 INIT_LIST_HEAD(&sub
->subsystem_list
);
143 INIT_LIST_HEAD(&sub
->test_list
);
144 spin_lock_init(&sub
->test_lock
);
145 sub
->desc
.id
= SPLAT_SUBSYSTEM_ZLIB
;
147 splat_test_init(sub
, SPLAT_ZLIB_TEST1_NAME
, SPLAT_ZLIB_TEST1_DESC
,
148 SPLAT_ZLIB_TEST1_ID
, splat_zlib_test1
);
154 splat_zlib_fini(splat_subsystem_t
*sub
)
158 splat_test_fini(sub
, SPLAT_ZLIB_TEST1_ID
);
164 splat_zlib_id(void) {
165 return SPLAT_SUBSYSTEM_ZLIB
;