diff --git a/mps/qa/function/12p.c b/mps/qa/function/12p.c new file mode 100644 index 00000000000..c02e2e83d16 --- /dev/null +++ b/mps/qa/function/12p.c @@ -0,0 +1,213 @@ +/* TEST_HEADER + summary = lots of APs with interleaved reserve and 2-stage commit + language = c + link = testlib.o newfmt.o +END_HEADER +*/ + +/* + This test needs some explanation. The object 'cells' contains + NCELL references to other objects. NAPS allocation points + are created. At each step, we choose one and nudge it on + a little. Each allocation point goes through the following + cycle of steps: reserve, init, begin commit, end commit. + At the init step, each reference in the reserved object is + set to point randomly to one of the objects referenced by + cells or (with probability PNULL) to NULL. If commit fails, + the object is thrown away. If it succeeds, it is written into + a random reference in cells. Repeat. + + Because it has to deal directly with reserve and commit, + this test can't use the nice functions provided by newfmt + all the time. +*/ + +#include "testlib.h" +#include "mpscamc.h" +#include "newfmt.h" + +void *stackpointer; + +#define NCELLS 100 +#define NAPS 100 +#define PNULL (ranint(100)<25) +#define NUMREFS (ranint(20)) +#define BLAH 0 + +mps_ap_t ap[NAPS]; +size_t s[NAPS]; +int nrefs[NAPS]; +int ap_state[NAPS]; + +static void test(void) +{ + mps_space_t space; + mps_pool_t pool; + mps_thr_t thread; + mps_root_t root; + + mps_fmt_t format; + mycell *cells; + + int h,i,j,k,l; + mycell *p[NAPS]; + mycell *pobj; + size_t bytes; + size_t alignment; + mps_addr_t q; + int nextid = 0x1000000; + +/* turn on comments about copying and scanning */ + formatcomments = BLAH; + fixcomments = BLAH; + + cdie(mps_space_create(&space), "create space"); + + cdie(mps_thread_reg(&thread, space), "register thread"); + + cdie( + mps_root_create_reg(&root, space, MPS_RANK_AMBIG, 0, thread, + mps_stack_scan_ambig, stackpointer, 0), + "create root"); + + cdie( + mps_fmt_create_A(&format, space, &fmtA), + "create format"); + + cdie( + mps_pool_create(&pool, space, mps_class_amc(), format), + "create pool"); + + for (i=0; idata.tag = 0xD033E2A6; + p[i]->data.id = nextid; + ap_state[i] = 1; + commentif(BLAH, "%i: reserve %li at %p", i, nextid, q); + nextid +=1; + break; + case 1: + commentif(BLAH, "%i: init %li", i, p[i]->data.id); + p[i]->data.tag = MCdata; + p[i]->data.numrefs = nrefs[i]; + p[i]->data.size = s[i]; + ap_state[i] = 2; + for (k=0; kdata.ref[k].addr = NULL; + p[i]->data.ref[k].id = 0; + } + else + { + l = ranint(NCELLS); + pobj = getref(cells, l); + p[i]->data.ref[k].addr = pobj; + p[i]->data.ref[k].id = (pobj==NULL ? 0 : pobj->data.id); + } + commentif(BLAH, " ref %i -> %li", k, p[i]->data.ref[k].id); + } + break; + case 2: + commentif(BLAH, "%i: begin commit %li", i, p[i]->data.id); + ap[i]->init = ap[i]->alloc; + ap_state[i] = 3; + break; + case 3: case 4: case 5: case 6: case 7: case 8: case 9: + ap_state[i]+=1; + break; + case 10: + commentif(BLAH, "%i: end commit %li", i, p[i]->data.id); + q=p[i]; + if (ap[i]->limit != 0 || mps_ap_trip(ap[i], p[i], s[i])) + { + l = ranint(NCELLS); + setref(cells, l, q); + commentif(BLAH, "%i -> %i", i, l); + } + ap_state[i] = 0; + break; + } + } + checkfrom(cells); + } + + comment("Finished main loop"); + + for (i=0; idata.tag = MCdata; + p[i]->data.numrefs = 0; + p[i]->data.size = s[i]; + case 2: + commentif(BLAH, "%i begin commit", i); + ap[i]->init = ap[i]->alloc; + case 3: + commentif(BLAH, "% end commit", i); + (void) (ap[i]->limit != 0 || mps_ap_trip(ap[i], p[i], s[i])); + } + mps_ap_destroy(ap[i]); + } + + mps_pool_destroy(pool); + comment("Destroyed pool."); + + mps_fmt_destroy(format); + comment("Destroyed format."); + + mps_root_destroy(root); + comment("Destroyed root."); + + mps_thread_dereg(thread); + comment("Deregistered thread."); + + mps_space_destroy(space); + comment("Destroyed space."); +} + +int main(void) +{ + void *m; + stackpointer=&m; /* hack to get stack pointer */ + + easy_tramp(test); + pass(); + return 0; +} diff --git a/mps/qa/function/26.c b/mps/qa/function/26.c new file mode 100644 index 00000000000..c41c043dbba --- /dev/null +++ b/mps/qa/function/26.c @@ -0,0 +1,56 @@ +/* TEST_HEADER + summary = try to allocate as large an object as will succeed + language = c + link = testlib.o +END_HEADER +*/ + +#include "testlib.h" +#include "mpscmv.h" + +mps_space_t space; +mps_pool_t pool; +mps_addr_t q; + +static mps_res_t trysize(size_t try) { + mps_res_t res; + + die(mps_pool_create(&pool, space, mps_class_mv(), + 1024*32, 1024*16, 1024*256), "pool"); + + comment("Trying %x", try); + + res = mps_alloc(&q, pool, try); + mps_pool_destroy(pool); + + comment("%s", err_text(res)); + + return res; +} + +static void test(void) { + size_t inf, sup, try; + + die(mps_space_create(&space), "create"); + + inf = 0; + sup = 1024*1024*1000; /* i.e. 1 gigabyte */ + + while (sup-inf > 1) { + try = inf + (sup-inf)/2; + if (trysize(try) == MPS_RES_OK) { + inf = try; + } else { + sup = try; + } + } + + for (try = inf-4; try < inf+4; try++) + (void) trysize(try); +} + +int main(void) { + easy_tramp(test); + pass(); + return 0; +}