diff options
author | Mark Murray <markm@FreeBSD.org> | 1995-11-04 09:50:48 +0000 |
---|---|---|
committer | Mark Murray <markm@FreeBSD.org> | 1995-11-04 09:50:48 +0000 |
commit | d82e286489da73321a47e329d98a98817b0438b6 (patch) | |
tree | 640094f2b9bcef301fc5179c062150e1f6b34b32 /tools/test | |
parent | bc71ecdfc9dfa9f2db237626f5a27d0251b0edb1 (diff) | |
download | src-test2-d82e286489da73321a47e329d98a98817b0438b6.tar.gz src-test2-d82e286489da73321a47e329d98a98817b0438b6.zip |
Notes
Diffstat (limited to 'tools/test')
-rw-r--r-- | tools/test/devrandom/hammer.random | 23 | ||||
-rw-r--r-- | tools/test/devrandom/hammer.urandom | 27 | ||||
-rw-r--r-- | tools/test/devrandom/stat.16bit | 29 | ||||
-rw-r--r-- | tools/test/devrandom/stat.8bit | 29 |
4 files changed, 108 insertions, 0 deletions
diff --git a/tools/test/devrandom/hammer.random b/tools/test/devrandom/hammer.random new file mode 100644 index 000000000000..a619816f2db5 --- /dev/null +++ b/tools/test/devrandom/hammer.random @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +# +# Test program for /dev/random +# Read and display random numbers. +# Try tapping shift/alt/ctrl to get more randomness. +# +# $Id$ +# + +for (;;) { + open(BIN, "/dev/random") || die "Cannot open /dev/random - $!\n"; + $len = sysread(BIN, $a, 128); + close(BIN); + if ($len > 0) { + print "$len bytes read: "; + for ($j = 0; $j < $len; $j++) { + $k = unpack("C", substr($a, $j, 1)); + printf("%.2X ", $k); + } + printf "\n"; + } +} diff --git a/tools/test/devrandom/hammer.urandom b/tools/test/devrandom/hammer.urandom new file mode 100644 index 000000000000..4e434fae5476 --- /dev/null +++ b/tools/test/devrandom/hammer.urandom @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +# +# Test program for /dev/urandom +# Read and display random numbers. +# This also reads /dev/zero to make sure there is no brokenness there. +# +# $Id$ +# + +open(ZERO, "/dev/zero") || die "Cannot open /dev/zero - $!\n"; + +for (;;) { + open(BIN, "/dev/urandom"); + $len = sysread(BIN, $a, 20); + sysread(ZERO, $b, 20); + close(BIN); + if ($len > 0) { + for ($j = 0; $j < $len; $j += 2) { + $k = unpack("S", substr($a, $j, 2)); + $z = unpack("S", substr($b, $j, 2)); + $z == 0 || die "/dev/zero is returning non-zero!\n"; + printf("%.4X ", $k); + } + printf "\n"; + } +} diff --git a/tools/test/devrandom/stat.16bit b/tools/test/devrandom/stat.16bit new file mode 100644 index 000000000000..83398d5d273a --- /dev/null +++ b/tools/test/devrandom/stat.16bit @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# +# Perform primitive binning into 16-bit bins (take 16bits of randomness +# at a time) and see if the distribution is flat. The output should be +# checked by eye - are all the numbers roughly the same? +# +# Redirect the output from this to a file - and go to the movies while +# it runs. This program is a CPU Hog! +# +# $Id$ +# + +for ($i = 0; $i < (1024*64); $i++) { + open(BIN, "/dev/urandom") || die "Cannot open /dev/urandom - $!\n"; + $len = sysread(BIN, $a, 512); + close(BIN); + if ($len > 0) { + for ($j = 0; $j < $len; $j += 2) { + $k = unpack("S", substr($a, $j, 2)); + $bin[$k]++; + } + } +} + +for ($i = 0; $i < 1024*64; $i++) { + printf("%.2X ", $bin[$i]); +} +printf "\n"; diff --git a/tools/test/devrandom/stat.8bit b/tools/test/devrandom/stat.8bit new file mode 100644 index 000000000000..5c304cb2e68e --- /dev/null +++ b/tools/test/devrandom/stat.8bit @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# +# Perform primitive binning into 8-bit bins (take 8 bits of randomness +# at a time) and see if the distribution is flat. The output should be +# checked by eye - are all the numbers roughly the same? +# +# Redirect the output from this to a file - and make a cup of coffee while +# it runs. This program is a CPU Hog! +# +# $Id$ +# + +for ($i = 0; $i < (1024*32); $i++) { + open(BIN, "/dev/urandom") || die "Cannot open /dev/urandom - $!\n"; + $len = sysread(BIN, $a, 256); + close(BIN); + if ($len > 0) { + for ($j = 0; $j < $len; $j++) { + $k = unpack("C", substr($a, $j, 1)); + $bin[$k]++; + } + } +} + +for ($i = 0; $i < 256; $i++) { + printf("%.2X ", $bin[$i]); +} +printf "\n"; |