summaryrefslogtreecommitdiffstats
path: root/old-tests/device
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2001-11-09 08:48:22 +0000
committerJoe Thornber <thornber@redhat.com>2001-11-09 08:48:22 +0000
commit4f0a4a6a7a13e3c24360a54813208397fbb6c218 (patch)
treed21ba584f714a819d086fcbc48fa1d6772cf51bc /old-tests/device
parent94b8220f6a33738fab26544936b3e40b3448fa29 (diff)
downloadlvm2-4f0a4a6a7a13e3c24360a54813208397fbb6c218.tar.gz
lvm2-4f0a4a6a7a13e3c24360a54813208397fbb6c218.tar.xz
lvm2-4f0a4a6a7a13e3c24360a54813208397fbb6c218.zip
sync only, not ready yet
Diffstat (limited to 'old-tests/device')
-rw-r--r--old-tests/device/fill_device.c18
-rw-r--r--old-tests/device/random.c107
-rw-r--r--old-tests/device/random.h25
3 files changed, 150 insertions, 0 deletions
diff --git a/old-tests/device/fill_device.c b/old-tests/device/fill_device.c
new file mode 100644
index 00000000..65ad966e
--- /dev/null
+++ b/old-tests/device/fill_device.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited
+ *
+ * This file is released under the GPL.
+ */
+
+#include "device.h"
+#include "random.h"
+
+#include <stdio.h>
+
+
+
+
+int main(int argc, char **argv)
+{
+
+}
diff --git a/old-tests/device/random.c b/old-tests/device/random.c
new file mode 100644
index 00000000..04594c62
--- /dev/null
+++ b/old-tests/device/random.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited
+ *
+ * This file is released under the GPL.
+ */
+
+#include "random.h"
+#include "log.h"
+
+int32_t _a[56];
+int32_t *_r;
+
+static inline int32_t _mod_diff(int32_t x, int32_t y)
+{
+ return (x - y) & 0x7fffffff;
+}
+
+static int32_t _flip_cycle(void)
+{
+ int32_t *ii, *jj;
+ for (ii = _a + 1, jj = _a + 32; jj <= _a + 55; ii++, jj++)
+ *ii = _mod_diff(*ii, *jj);
+
+ for (jj = _a + 1; ii <= _a + 55; ii++, jj++)
+ *ii = _mod_diff(*ii, *jj);
+
+ _r = _a + 54;
+ return _a[55];
+}
+
+static void rand_init(int32_t seed)
+{
+ int64_t i;
+ int64_t prev = seed, next = 1;
+
+ seed = prev = _mod_diff(prev, 0); /* strip the sign */
+ _a[55] = prev;
+ for (i = 21; i; i = (i + 21) % 55) {
+ _a[i] = next;
+ next = _mod_diff(prev, next);
+ if(seed & 1)
+ seed = 0x40000000L + (seed >> 1);
+ else
+ seed >>= 1;
+
+ next = _mod_diff(next, seed);
+ prev = _a[i];
+ }
+
+ _flip_cycle();
+ _flip_cycle();
+ _flip_cycle();
+ _flip_cycle();
+ _flip_cycle();
+}
+
+/*
+ * FIXME: move this to be an inline in the
+ * header.
+ */
+int32_t rand_get(void)
+{
+ return (*_r >= 0) ? *_r-- : _flip_cycle();
+}
+
+
+/*
+ * just used by rand_check
+ */
+#define t31 0x80000000
+static int32_t _uniform(int32_t m)
+{
+ uint32_t t = t31 - (t31 % m);
+ int32_t r;
+
+ do
+ r = next_rand(sc);
+
+ while (t <= (uint32_t) r);
+
+ return r % m;
+}
+
+/*
+ * Checks I've copied the code correctly.
+ */
+int rand_check(void)
+{
+ int j;
+
+ rand_init(-314159L);
+
+ if (next_rand(sc) != 119318998) {
+ log_err("Random number generator failed check 1");
+ return 0;
+ }
+
+ for(j = 1; j <= 133; j++)
+ rand_get();
+
+ if (_uniform(0x55555555L) != 748103812) {
+ log_err("Random number generator failed check 2");
+ return 0;
+ }
+
+ return 1;
+}
diff --git a/old-tests/device/random.h b/old-tests/device/random.h
new file mode 100644
index 00000000..5be2c48e
--- /dev/null
+++ b/old-tests/device/random.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited
+ *
+ * This file is released under the GPL.
+ */
+
+/*
+ * Random number generator snarfed from the
+ * Stanford Graphbase.
+ */
+
+#ifndef _LVM_RANDOM_H
+#define _LVM_RANDOM_H
+
+#include "lvm-types.h"
+
+void rand_init(int32_t seed);
+int32_t rand_get(void);
+
+/*
+ * Note this will reset the seed.
+ */
+int rand_check(void);
+
+#endif