]>
git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-random.c
2 * This file is part of the SPL: Solaris Porting Layer.
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "splat-internal.h"
29 #define SPLAT_SUBSYSTEM_KRNG 0x0300
30 #define SPLAT_KRNG_NAME "krng"
31 #define SPLAT_KRNG_DESC "Kernel Random Number Generator Tests"
33 #define SPLAT_KRNG_TEST1_ID 0x0301
34 #define SPLAT_KRNG_TEST1_NAME "freq"
35 #define SPLAT_KRNG_TEST1_DESC "Frequency Test"
37 #define KRNG_NUM_BITS 1048576
38 #define KRNG_NUM_BYTES (KRNG_NUM_BITS >> 3)
39 #define KRNG_NUM_BITS_DIV2 (KRNG_NUM_BITS >> 1)
40 #define KRNG_ERROR_RANGE 2097
42 /* Random Number Generator Tests
43 There can be meny more tests on quality of the
44 random number generator. For now we are only
45 testing the frequency of particular bits.
46 We could also test consecutive sequences,
47 randomness within a particular block, etc.
48 but is probably not necessary for our purposes */
51 splat_krng_test1(struct file
*file
, void *arg
)
54 int i
, j
, diff
, num
= 0, rc
= 0;
56 buf
= kmalloc(sizeof(*buf
) * KRNG_NUM_BYTES
, GFP_KERNEL
);
62 memset(buf
, 0, sizeof(*buf
) * KRNG_NUM_BYTES
);
65 random_get_pseudo_bytes(buf
, sizeof(uint8_t) * KRNG_NUM_BYTES
);
67 for (i
= 0; i
< KRNG_NUM_BYTES
; i
++) {
69 for (j
= 0; j
< 8; j
++) {
70 uint8_t tmp2
= ((tmp
>> j
) & 0x01);
79 diff
= KRNG_NUM_BITS_DIV2
- num
;
83 splat_print(file
, "Test 1 Number of ones: %d\n", num
);
84 splat_print(file
, "Test 1 Difference from expected: %d Allowed: %d\n",
85 diff
, KRNG_ERROR_RANGE
);
87 if (diff
> KRNG_ERROR_RANGE
)
96 splat_subsystem_t
*sub
;
98 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
102 memset(sub
, 0, sizeof(*sub
));
103 strncpy(sub
->desc
.name
, SPLAT_KRNG_NAME
, SPLAT_NAME_SIZE
);
104 strncpy(sub
->desc
.desc
, SPLAT_KRNG_DESC
, SPLAT_DESC_SIZE
);
105 INIT_LIST_HEAD(&sub
->subsystem_list
);
106 INIT_LIST_HEAD(&sub
->test_list
);
107 spin_lock_init(&sub
->test_lock
);
108 sub
->desc
.id
= SPLAT_SUBSYSTEM_KRNG
;
110 SPLAT_TEST_INIT(sub
, SPLAT_KRNG_TEST1_NAME
, SPLAT_KRNG_TEST1_DESC
,
111 SPLAT_KRNG_TEST1_ID
, splat_krng_test1
);
117 splat_krng_fini(splat_subsystem_t
*sub
)
121 SPLAT_TEST_FINI(sub
, SPLAT_KRNG_TEST1_ID
);
127 splat_krng_id(void) {
128 return SPLAT_SUBSYSTEM_KRNG
;