/usr/src/spl-0.6.5.9/module/splat/splat-zlib.c is in spl-dkms 0.6.5.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | /*****************************************************************************\
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
* Copyright (C) 2007 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
* UCRL-CODE-235197
*
* This file is part of the SPL, Solaris Porting Layer.
* For details, see <http://zfsonlinux.org/>.
*
* The SPL is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The SPL 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 General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************
* Solaris Porting LAyer Tests (SPLAT) Zlib Compression Tests.
\*****************************************************************************/
#include <sys/zmod.h>
#include <sys/random.h>
#include <sys/kmem.h>
#include <sys/vmem.h>
#include "splat-internal.h"
#define SPLAT_ZLIB_NAME "zlib"
#define SPLAT_ZLIB_DESC "Zlib Compression Tests"
#define SPLAT_ZLIB_TEST1_ID 0x0f01
#define SPLAT_ZLIB_TEST1_NAME "compress/uncompress"
#define SPLAT_ZLIB_TEST1_DESC "Compress/Uncompress Test"
#define BUFFER_SIZE (128 * 1024)
static int
splat_zlib_test1_check(struct file *file, void *src, void *dst, void *chk,
int level)
{
size_t dst_len = BUFFER_SIZE;
size_t chk_len = BUFFER_SIZE;
int rc;
memset(dst, 0, BUFFER_SIZE);
memset(chk, 0, BUFFER_SIZE);
rc = z_compress_level(dst, &dst_len, src, BUFFER_SIZE, level);
if (rc != Z_OK) {
splat_vprint(file, SPLAT_ZLIB_TEST1_NAME,
"Failed level %d z_compress_level(), %d\n", level, rc);
return -EINVAL;
}
rc = z_uncompress(chk, &chk_len, dst, dst_len);
if (rc != Z_OK) {
splat_vprint(file, SPLAT_ZLIB_TEST1_NAME,
"Failed level %d z_uncompress(), %d\n", level, rc);
return -EINVAL;
}
rc = memcmp(src, chk, BUFFER_SIZE);
if (rc) {
splat_vprint(file, SPLAT_ZLIB_TEST1_NAME,
"Failed level %d memcmp()), %d\n", level, rc);
return -EINVAL;
}
splat_vprint(file, SPLAT_ZLIB_TEST1_NAME,
"Passed level %d, compressed %d bytes to %d bytes\n",
level, BUFFER_SIZE, (int)dst_len);
return 0;
}
/*
* Compress a buffer, uncompress the newly compressed buffer, then
* compare it to the original. Do this for all 9 compression levels.
*/
static int
splat_zlib_test1(struct file *file, void *arg)
{
void *src = NULL, *dst = NULL, *chk = NULL;
int i, rc, level;
src = vmalloc(BUFFER_SIZE);
if (src == NULL) {
rc = -ENOMEM;
goto out;
}
dst = vmalloc(BUFFER_SIZE);
if (dst == NULL) {
rc = -ENOMEM;
goto out;
}
chk = vmalloc(BUFFER_SIZE);
if (chk == NULL) {
rc = -ENOMEM;
goto out;
}
/* Source buffer is a repeating 1024 byte random pattern. */
random_get_pseudo_bytes(src, sizeof(uint8_t) * 1024);
for (i = 1; i < 128; i++)
memcpy(src + (i * 1024), src, 1024);
for (level = 1; level <= 9; level++)
if ((rc = splat_zlib_test1_check(file, src, dst, chk, level)))
break;
out:
if (src)
vfree(src);
if (dst)
vfree(dst);
if (chk)
vfree(chk);
return rc;
}
splat_subsystem_t *
splat_zlib_init(void)
{
splat_subsystem_t *sub;
sub = kmalloc(sizeof(*sub), GFP_KERNEL);
if (sub == NULL)
return NULL;
memset(sub, 0, sizeof(*sub));
strncpy(sub->desc.name, SPLAT_ZLIB_NAME, SPLAT_NAME_SIZE);
strncpy(sub->desc.desc, SPLAT_ZLIB_DESC, SPLAT_DESC_SIZE);
INIT_LIST_HEAD(&sub->subsystem_list);
INIT_LIST_HEAD(&sub->test_list);
spin_lock_init(&sub->test_lock);
sub->desc.id = SPLAT_SUBSYSTEM_ZLIB;
SPLAT_TEST_INIT(sub, SPLAT_ZLIB_TEST1_NAME, SPLAT_ZLIB_TEST1_DESC,
SPLAT_ZLIB_TEST1_ID, splat_zlib_test1);
return sub;
}
void
splat_zlib_fini(splat_subsystem_t *sub)
{
ASSERT(sub);
SPLAT_TEST_FINI(sub, SPLAT_ZLIB_TEST1_ID);
kfree(sub);
}
int
splat_zlib_id(void) {
return SPLAT_SUBSYSTEM_ZLIB;
}
|