]>
git.proxmox.com Git - mirror_zfs.git/blob - splat/splat-random.c
3 #define KZT_SUBSYSTEM_KRNG 0x0300
4 #define KZT_KRNG_NAME "krng"
5 #define KZT_KRNG_DESC "Kernel Random Number Generator Tests"
7 #define KZT_KRNG_TEST1_ID 0x0301
8 #define KZT_KRNG_TEST1_NAME "freq"
9 #define KZT_KRNG_TEST1_DESC "Frequency Test"
11 #define KRNG_NUM_BITS 1048576
12 #define KRNG_NUM_BYTES (KRNG_NUM_BITS >> 3)
13 #define KRNG_NUM_BITS_DIV2 (KRNG_NUM_BITS >> 1)
14 #define KRNG_ERROR_RANGE 2097
16 /* Random Number Generator Tests
17 There can be meny more tests on quality of the
18 random number generator. For now we are only
19 testing the frequency of particular bits.
20 We could also test consecutive sequences,
21 randomness within a particular block, etc.
22 but is probably not necessary for our purposes */
25 kzt_krng_test1(struct file
*file
, void *arg
)
28 int i
, j
, diff
, num
= 0, rc
= 0;
30 buf
= kmalloc(sizeof(*buf
) * KRNG_NUM_BYTES
, GFP_KERNEL
);
36 memset(buf
, 0, sizeof(*buf
) * KRNG_NUM_BYTES
);
39 random_get_pseudo_bytes(buf
, sizeof(uint8_t) * KRNG_NUM_BYTES
);
41 for (i
= 0; i
< KRNG_NUM_BYTES
; i
++) {
43 for (j
= 0; j
< 8; j
++) {
44 uint8_t tmp2
= ((tmp
>> j
) & 0x01);
53 diff
= KRNG_NUM_BITS_DIV2
- num
;
57 kzt_print(file
, "Test 1 Number of ones: %d\n", num
);
58 kzt_print(file
, "Test 1 Difference from expected: %d Allowed: %d\n",
59 diff
, KRNG_ERROR_RANGE
);
61 if (diff
> KRNG_ERROR_RANGE
)
72 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
76 memset(sub
, 0, sizeof(*sub
));
77 strncpy(sub
->desc
.name
, KZT_KRNG_NAME
, KZT_NAME_SIZE
);
78 strncpy(sub
->desc
.desc
, KZT_KRNG_DESC
, KZT_DESC_SIZE
);
79 INIT_LIST_HEAD(&sub
->subsystem_list
);
80 INIT_LIST_HEAD(&sub
->test_list
);
81 spin_lock_init(&sub
->test_lock
);
82 sub
->desc
.id
= KZT_SUBSYSTEM_KRNG
;
84 KZT_TEST_INIT(sub
, KZT_KRNG_TEST1_NAME
, KZT_KRNG_TEST1_DESC
,
85 KZT_KRNG_TEST1_ID
, kzt_krng_test1
);
91 kzt_krng_fini(kzt_subsystem_t
*sub
)
95 KZT_TEST_FINI(sub
, KZT_KRNG_TEST1_ID
);
102 return KZT_SUBSYSTEM_KRNG
;