diff options
| author | Nick Barnes | 2001-10-31 14:40:56 +0000 |
|---|---|---|
| committer | Nick Barnes | 2001-10-31 14:40:56 +0000 |
| commit | 7acfca905d76140f4cc0b09c9a12de237de364cd (patch) | |
| tree | 3ed8babfa3a73d30f29e08ca5d5adcda4ca4e826 /mps/code/finalcv.c | |
| parent | b7ce4893f9902d57cd67ac9a92fa6c3d5a8fc833 (diff) | |
| download | emacs-7acfca905d76140f4cc0b09c9a12de237de364cd.tar.gz emacs-7acfca905d76140f4cc0b09c9a12de237de364cd.zip | |
Branch imports for masters.
Copied from Perforce
Change: 23678
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code/finalcv.c')
| -rw-r--r-- | mps/code/finalcv.c | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/mps/code/finalcv.c b/mps/code/finalcv.c new file mode 100644 index 00000000000..55df9d93beb --- /dev/null +++ b/mps/code/finalcv.c | |||
| @@ -0,0 +1,180 @@ | |||
| 1 | /* impl.c.finalcv: FINALIZATION COVERAGE TEST | ||
| 2 | * | ||
| 3 | * $HopeName: MMsrc!finalcv.c(trunk.12) $ | ||
| 4 | * Copyright (C) 1998 Harlequin Limited. All rights reserved. | ||
| 5 | * | ||
| 6 | * DESIGN | ||
| 7 | * | ||
| 8 | * See design.mps.poolmrg.test. | ||
| 9 | * | ||
| 10 | * DEPENDENCIES | ||
| 11 | * | ||
| 12 | * This test uses the dylan object format, but the reliance on this | ||
| 13 | * particular format is not great and could be removed. | ||
| 14 | * | ||
| 15 | * NOTES | ||
| 16 | * | ||
| 17 | * This code was created by first copying impl.c.weakcv | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include "testlib.h" | ||
| 21 | #include "mps.h" | ||
| 22 | #include "mpscamc.h" | ||
| 23 | #include "mpsavm.h" | ||
| 24 | #include "fmtdy.h" | ||
| 25 | #include "mpstd.h" | ||
| 26 | #ifdef MPS_OS_W3 | ||
| 27 | #include "mpsw3.h" | ||
| 28 | #endif | ||
| 29 | #include <stdlib.h> | ||
| 30 | |||
| 31 | |||
| 32 | #define testArenaSIZE ((size_t)16<<20) | ||
| 33 | #define rootCOUNT 20 | ||
| 34 | #define churnFACTOR 30 | ||
| 35 | #define slotSIZE (3*sizeof(mps_word_t)) | ||
| 36 | #define genCOUNT 2 | ||
| 37 | |||
| 38 | /* testChain -- generation parameters for the test */ | ||
| 39 | |||
| 40 | static mps_gen_param_s testChain[genCOUNT] = { | ||
| 41 | { 150, 0.85 }, { 170, 0.45 } }; | ||
| 42 | |||
| 43 | |||
| 44 | /* tags an integer according to dylan format */ | ||
| 45 | static mps_word_t dylan_int(mps_word_t x) | ||
| 46 | { | ||
| 47 | return (x << 2)|1; | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | /* converts a dylan format int to an int (untags) */ | ||
| 52 | static mps_word_t dylan_int_int(mps_word_t x) | ||
| 53 | { | ||
| 54 | return x >> 2; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | static void *root[rootCOUNT]; | ||
| 59 | |||
| 60 | |||
| 61 | static void churn(mps_ap_t ap) | ||
| 62 | { | ||
| 63 | int i; | ||
| 64 | mps_addr_t p; | ||
| 65 | mps_res_t e; | ||
| 66 | |||
| 67 | for(i = 0; i < churnFACTOR; ++i) { | ||
| 68 | do { | ||
| 69 | MPS_RESERVE_BLOCK(e, p, ap, 4096); | ||
| 70 | die(e, "MPS_RESERVE_BLOCK"); | ||
| 71 | die(dylan_init(p, 4096, root, 1), "dylan_init"); | ||
| 72 | } while(!mps_commit(ap, p, 4096)); | ||
| 73 | } | ||
| 74 | p = NULL; | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | static void *test(void *arg, size_t s) | ||
| 79 | { | ||
| 80 | int i; /* index */ | ||
| 81 | mps_ap_t ap; | ||
| 82 | mps_fmt_t fmt; | ||
| 83 | mps_chain_t chain; | ||
| 84 | mps_pool_t amc; | ||
| 85 | mps_res_t e; | ||
| 86 | mps_root_t mps_root[2]; | ||
| 87 | mps_arena_t arena; | ||
| 88 | void *p = NULL; | ||
| 89 | mps_message_t message; | ||
| 90 | |||
| 91 | arena = (mps_arena_t)arg; | ||
| 92 | (void)s; | ||
| 93 | |||
| 94 | die(mps_fmt_create_A(&fmt, arena, dylan_fmt_A()), "fmt_create\n"); | ||
| 95 | die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); | ||
| 96 | die(mps_pool_create(&amc, arena, mps_class_amc(), fmt, chain), | ||
| 97 | "pool_create amc\n"); | ||
| 98 | die(mps_root_create_table(&mps_root[0], arena, MPS_RANK_EXACT, (mps_rm_t)0, | ||
| 99 | root, (size_t)rootCOUNT), | ||
| 100 | "root_create\n"); | ||
| 101 | die(mps_root_create_table(&mps_root[1], arena, MPS_RANK_EXACT, (mps_rm_t)0, | ||
| 102 | &p, (size_t)1), | ||
| 103 | "root_create\n"); | ||
| 104 | die(mps_ap_create(&ap, amc, MPS_RANK_EXACT), "ap_create\n"); | ||
| 105 | |||
| 106 | /* design.mps.poolmrg.test.promise.ut.alloc */ | ||
| 107 | for(i = 0; i < rootCOUNT; ++i) { | ||
| 108 | do { | ||
| 109 | MPS_RESERVE_BLOCK(e, p, ap, slotSIZE); | ||
| 110 | die(e, "MPS_RES_OK"); | ||
| 111 | die(dylan_init(p, slotSIZE, root, 1), "dylan_init"); | ||
| 112 | } while(!mps_commit(ap, p, slotSIZE)); | ||
| 113 | ((mps_word_t *)p)[2] = dylan_int(i); | ||
| 114 | die(mps_finalize(arena, &p), "finalize\n"); | ||
| 115 | root[i] = p; | ||
| 116 | } | ||
| 117 | p = NULL; | ||
| 118 | |||
| 119 | /* design.mps.poolmrg.test.promise.ut.drop */ | ||
| 120 | for(i = 0; i < rootCOUNT; ++i) { | ||
| 121 | if (rnd() % 2 == 0) | ||
| 122 | root[i] = NULL; | ||
| 123 | } | ||
| 124 | |||
| 125 | mps_message_type_enable(arena, mps_message_type_finalization()); | ||
| 126 | |||
| 127 | /* design.mps.poolmrg.test.promise.ut.churn */ | ||
| 128 | while(mps_collections(arena) < 3) { | ||
| 129 | churn(ap); | ||
| 130 | while(mps_message_poll(arena)) { | ||
| 131 | mps_word_t *obj; | ||
| 132 | mps_word_t objind; | ||
| 133 | mps_addr_t objaddr; | ||
| 134 | |||
| 135 | /* design.mps.poolmrg.test.promise.ut.message */ | ||
| 136 | cdie(mps_message_get(&message, arena, mps_message_type_finalization()), | ||
| 137 | "get"); | ||
| 138 | mps_message_finalization_ref(&objaddr, arena, message); | ||
| 139 | obj = objaddr; | ||
| 140 | objind = dylan_int_int(obj[2]); | ||
| 141 | printf("Finalizing: object %lu at %p\n", objind, objaddr); | ||
| 142 | /* design.mps.poolmrg.test.promise.ut.final.check */ | ||
| 143 | cdie(root[objind] == NULL, "died"); | ||
| 144 | root[objind] = objaddr; | ||
| 145 | mps_message_discard(arena, message); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | /* @@@@ design.mps.poolmrg.test.promise.ut.nofinal.check missing */ | ||
| 150 | |||
| 151 | mps_ap_destroy(ap); | ||
| 152 | mps_root_destroy(mps_root[1]); | ||
| 153 | mps_root_destroy(mps_root[0]); | ||
| 154 | mps_pool_destroy(amc); | ||
| 155 | mps_chain_destroy(chain); | ||
| 156 | mps_fmt_destroy(fmt); | ||
| 157 | |||
| 158 | return NULL; | ||
| 159 | } | ||
| 160 | |||
| 161 | |||
| 162 | int main(int argc, char **argv) | ||
| 163 | { | ||
| 164 | mps_arena_t arena; | ||
| 165 | mps_thr_t thread; | ||
| 166 | void *r; | ||
| 167 | |||
| 168 | randomize(argc, argv); | ||
| 169 | |||
| 170 | die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE), | ||
| 171 | "arena_create\n"); | ||
| 172 | die(mps_thread_reg(&thread, arena), "thread_reg\n"); | ||
| 173 | mps_tramp(&r, test, arena, 0); | ||
| 174 | mps_thread_dereg(thread); | ||
| 175 | mps_arena_destroy(arena); | ||
| 176 | |||
| 177 | fflush(stdout); /* synchronize */ | ||
| 178 | fprintf(stderr, "\nConclusion: Failed to find any defects.\n"); | ||
| 179 | return 0; | ||
| 180 | } | ||