From 3a4a7657ff96840d20470ca88554be3eef98e6ef Mon Sep 17 00:00:00 2001 From: Richard Tucker Date: Thu, 22 Oct 1998 11:09:21 +0100 Subject: [PATCH] New unit new test Copied from Perforce Change: 20267 ServerID: perforce.ravenbrook.com --- mps/qa/function/151.c | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 mps/qa/function/151.c diff --git a/mps/qa/function/151.c b/mps/qa/function/151.c new file mode 100644 index 00000000000..db483a72385 --- /dev/null +++ b/mps/qa/function/151.c @@ -0,0 +1,83 @@ +/* $HopeName: MMQA_test_function!147.c(trunk.1) $ +TEST_HEADER + summary = SNC pop-to-NULL test (request.dylan.170602) + language = c + link = testlib.o rankfmt.o +END_HEADER +*/ + +#include "testlib.h" +#include "mpscsnc.h" +#include "mpsavm.h" +#include "rankfmt.h" + +#define THIRTY_MEG (30uL*1024ul*1024ul) +#define OBJSIZE (1024*1024*1) +#define ITERATIONS (100) + +static void test(void) +{ + int i = 0; + mps_ap_t sap; + mps_arena_t arena; + mps_fmt_t format; + mps_pool_t spool; + mps_thr_t thread; + mps_frame_t frame; + mycell *p; + +/* create an arena that can't grow beyond 30 M */ + + cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)THIRTY_MEG), + "create arena"); + cdie(mps_arena_commit_limit_set(arena, (size_t)THIRTY_MEG), + "commit limit set"); + + cdie(mps_thread_reg(&thread, arena), "register thread"); + + cdie( + mps_fmt_create_A(&format, arena, &fmtA), + "create format"); + + cdie( + mps_pool_create(&spool, arena, mps_class_snc(), format), + "create SNC pool"); + + cdie( + mps_ap_create(&sap, spool, MPS_RANK_EXACT), + "create ap"); + +/* repeatedly push, alloc 1MB object, and pop to first stack frame. + This shouldn't use much more than 1MB of memory. +*/ + + for (i=0; i < ITERATIONS; i++) { + die(mps_ap_frame_push(&frame, sap), "push"); + p = allocdumb(sap, OBJSIZE, MPS_RANK_EXACT); + die(mps_ap_frame_pop(sap, frame), "pop"); + comment("%i of %i", i, ITERATIONS); + } + + mps_ap_destroy(sap); + comment("Destroyed ap."); + + mps_pool_destroy(spool); + comment("Destroyed pool."); + + mps_fmt_destroy(format); + comment("Destroyed format."); + + mps_thread_dereg(thread); + comment("Deregistered thread."); + + mps_arena_destroy(arena); + comment("Destroyed arena."); + +} + +int main(void) +{ + easy_tramp(test); + pass(); + return 0; +}