diff options
| author | Nick Barnes | 2002-06-18 14:14:55 +0100 |
|---|---|---|
| committer | Nick Barnes | 2002-06-18 14:14:55 +0100 |
| commit | 6a1a360814506ddbcf856f41c089a10550f31ae5 (patch) | |
| tree | 732fc720ec58b9badf2ce1eef392ada522130a03 /mps/code/testlib.c | |
| parent | 63e5f529159927bb42b58a97507f4467d6413973 (diff) | |
| download | emacs-6a1a360814506ddbcf856f41c089a10550f31ae5.tar.gz emacs-6a1a360814506ddbcf856f41c089a10550f31ae5.zip | |
Integrate changes from global graphics.
Copied from Perforce
Change: 30250
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code/testlib.c')
| -rw-r--r-- | mps/code/testlib.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/mps/code/testlib.c b/mps/code/testlib.c index c59d3fa717a..e747e2cc7f4 100644 --- a/mps/code/testlib.c +++ b/mps/code/testlib.c | |||
| @@ -2,15 +2,17 @@ | |||
| 2 | * | 2 | * |
| 3 | * $Id$ | 3 | * $Id$ |
| 4 | * Copyright (c) 2001 Ravenbrook Limited. | 4 | * Copyright (c) 2001 Ravenbrook Limited. |
| 5 | * Copyright (C) 2002 Global Graphics Software. | ||
| 5 | * | 6 | * |
| 6 | * .purpose: A library of functions that may be of use to unit tests. | 7 | * .purpose: A library of functions that may be of use to unit tests. |
| 7 | */ | 8 | */ |
| 8 | 9 | ||
| 9 | #include "testlib.h" | 10 | #include "testlib.h" |
| 10 | #include "mps.h" | 11 | #include "mps.h" |
| 11 | #include "mpm.h" | 12 | #include "misc.h" /* for NOOP */ |
| 12 | #include <math.h> | 13 | #include <math.h> |
| 13 | #include <stdlib.h> | 14 | #include <stdlib.h> |
| 15 | #include <limits.h> | ||
| 14 | #ifdef MPS_OS_IA | 16 | #ifdef MPS_OS_IA |
| 15 | struct itimerspec; /* stop complaints from time.h */ | 17 | struct itimerspec; /* stop complaints from time.h */ |
| 16 | #endif | 18 | #endif |
| @@ -19,16 +21,16 @@ struct itimerspec; /* stop complaints from time.h */ | |||
| 19 | 21 | ||
| 20 | /* rnd -- a random number generator | 22 | /* rnd -- a random number generator |
| 21 | * | 23 | * |
| 22 | * I nabbed it from "ML for the Working Programmer" | 24 | * I nabbed it from "ML for the Working Programmer", originally from: |
| 23 | * Originally from: | ||
| 24 | * Stephen K Park & Keith W Miller (1988). Random number generators: | 25 | * Stephen K Park & Keith W Miller (1988). Random number generators: |
| 25 | * good one are to find. Communications of the ACM, 31:1192-1201 | 26 | * good one are to find. Communications of the ACM, 31:1192-1201. |
| 26 | */ | 27 | */ |
| 27 | 28 | ||
| 28 | unsigned long rnd(void) | 29 | unsigned long rnd(void) |
| 29 | { | 30 | { |
| 30 | static unsigned long seed = 1; | 31 | static unsigned long seed = 1; |
| 31 | double s; | 32 | double s; |
| 33 | |||
| 32 | s = seed; | 34 | s = seed; |
| 33 | s *= 16807.0; | 35 | s *= 16807.0; |
| 34 | s = fmod(s, 2147483647.0); /* 2^31 - 1 */ | 36 | s = fmod(s, 2147483647.0); /* 2^31 - 1 */ |
| @@ -37,13 +39,32 @@ unsigned long rnd(void) | |||
| 37 | } | 39 | } |
| 38 | 40 | ||
| 39 | 41 | ||
| 42 | /* rnd_addr -- a random address generator | ||
| 43 | * | ||
| 44 | * rnd gives 31 random bits, we run it repeatedly to get enough bits. | ||
| 45 | */ | ||
| 46 | |||
| 47 | #define ADDR_BITS (sizeof(mps_addr_t) * CHAR_BIT) | ||
| 48 | |||
| 49 | mps_addr_t rnd_addr(void) | ||
| 50 | { | ||
| 51 | mps_word_t res; | ||
| 52 | unsigned bits; | ||
| 53 | |||
| 54 | for (bits = 0, res = 0; bits < ADDR_BITS; | ||
| 55 | bits += 31, res = res << 31 | (mps_word_t)rnd()) | ||
| 56 | NOOP; | ||
| 57 | return (mps_addr_t)res; | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 40 | /* randomize -- randomize the generator, or initialize to replay */ | 61 | /* randomize -- randomize the generator, or initialize to replay */ |
| 41 | 62 | ||
| 42 | void randomize(int argc, char **argv) | 63 | void randomize(int argc, char **argv) |
| 43 | { | 64 | { |
| 44 | int i, k, n; | 65 | int i, k, n; |
| 45 | 66 | ||
| 46 | if(argc > 1) { | 67 | if (argc > 1) { |
| 47 | n = sscanf(argv[1], "%d", &k); | 68 | n = sscanf(argv[1], "%d", &k); |
| 48 | die((n == 1) ? MPS_RES_OK : MPS_RES_FAIL, "randomize"); | 69 | die((n == 1) ? MPS_RES_OK : MPS_RES_FAIL, "randomize"); |
| 49 | } else { | 70 | } else { |