]>
git.proxmox.com Git - mirror_spl.git/blob - module/splat/splat-random.c
ed8f694c30c7d6b20323d91c82b4961de1f4734b
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_KRNG_NAME "krng"
30 #define SPLAT_KRNG_DESC "Kernel Random Number Generator Tests"
32 #define SPLAT_KRNG_TEST1_ID 0x0301
33 #define SPLAT_KRNG_TEST1_NAME "freq"
34 #define SPLAT_KRNG_TEST1_DESC "Frequency Test"
36 #define KRNG_NUM_BITS 1048576
37 #define KRNG_NUM_BYTES (KRNG_NUM_BITS >> 3)
38 #define KRNG_NUM_BITS_DIV2 (KRNG_NUM_BITS >> 1)
39 #define KRNG_ERROR_RANGE 2097
41 /* Random Number Generator Tests
42 There can be meny more tests on quality of the
43 random number generator. For now we are only
44 testing the frequency of particular bits.
45 We could also test consecutive sequences,
46 randomness within a particular block, etc.
47 but is probably not necessary for our purposes */
50 splat_krng_test1(struct file
*file
, void *arg
)
53 int i
, j
, diff
, num
= 0, rc
= 0;
55 buf
= kmalloc(sizeof(*buf
) * KRNG_NUM_BYTES
, GFP_KERNEL
);
61 memset(buf
, 0, sizeof(*buf
) * KRNG_NUM_BYTES
);
64 random_get_pseudo_bytes(buf
, sizeof(uint8_t) * KRNG_NUM_BYTES
);
66 for (i
= 0; i
< KRNG_NUM_BYTES
; i
++) {
68 for (j
= 0; j
< 8; j
++) {
69 uint8_t tmp2
= ((tmp
>> j
) & 0x01);
78 diff
= KRNG_NUM_BITS_DIV2
- num
;
82 splat_print(file
, "Test 1 Number of ones: %d\n", num
);
83 splat_print(file
, "Test 1 Difference from expected: %d Allowed: %d\n",
84 diff
, KRNG_ERROR_RANGE
);
86 if (diff
> KRNG_ERROR_RANGE
)
95 splat_subsystem_t
*sub
;
97 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
101 memset(sub
, 0, sizeof(*sub
));
102 strncpy(sub
->desc
.name
, SPLAT_KRNG_NAME
, SPLAT_NAME_SIZE
);
103 strncpy(sub
->desc
.desc
, SPLAT_KRNG_DESC
, SPLAT_DESC_SIZE
);
104 INIT_LIST_HEAD(&sub
->subsystem_list
);
105 INIT_LIST_HEAD(&sub
->test_list
);
106 spin_lock_init(&sub
->test_lock
);
107 sub
->desc
.id
= SPLAT_SUBSYSTEM_KRNG
;
109 SPLAT_TEST_INIT(sub
, SPLAT_KRNG_TEST1_NAME
, SPLAT_KRNG_TEST1_DESC
,
110 SPLAT_KRNG_TEST1_ID
, splat_krng_test1
);
116 splat_krng_fini(splat_subsystem_t
*sub
)
120 SPLAT_TEST_FINI(sub
, SPLAT_KRNG_TEST1_ID
);
126 splat_krng_id(void) {
127 return SPLAT_SUBSYSTEM_KRNG
;