mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Use the mps to manage memory in test cases, not malloc!
Copied from Perforce Change: 185474 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
b033a14564
commit
03c4de821b
4 changed files with 58 additions and 21 deletions
|
|
@ -7,16 +7,16 @@
|
|||
#include "abq.h"
|
||||
#include "mps.h"
|
||||
#include "mpsavm.h"
|
||||
#include "mpscmfs.h"
|
||||
#include "mpstd.h"
|
||||
#include "testlib.h"
|
||||
|
||||
#include <stdlib.h> /* free, malloc */
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
|
||||
SRCID(abqtest, "$Id$");
|
||||
|
||||
|
||||
static mps_pool_t pool;
|
||||
static ABQStruct abq; /* the ABQ which we will use */
|
||||
static Size abqSize; /* the size of the current ABQ */
|
||||
|
||||
|
|
@ -51,9 +51,12 @@ static TestBlock testBlocks = NULL;
|
|||
|
||||
static TestBlock CreateTestBlock(unsigned no)
|
||||
{
|
||||
TestBlock b = malloc(sizeof(TestBlockStruct));
|
||||
cdie(b != NULL, "malloc");
|
||||
TestBlock b;
|
||||
mps_addr_t p;
|
||||
|
||||
die(mps_alloc(&p, pool, sizeof(TestBlockStruct)), "alloc");
|
||||
|
||||
b = p;
|
||||
b->next = testBlocks;
|
||||
b->id = no;
|
||||
b->base = 0;
|
||||
|
|
@ -79,7 +82,7 @@ static void DestroyTestBlock(TestBlock b)
|
|||
}
|
||||
}
|
||||
|
||||
free(b);
|
||||
mps_free(pool, b, sizeof(TestBlockStruct));
|
||||
}
|
||||
|
||||
typedef struct TestClosureStruct *TestClosure;
|
||||
|
|
@ -147,9 +150,6 @@ static void step(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#define testArenaSIZE (((size_t)4)<<20)
|
||||
|
||||
extern int main(int argc, char *argv[])
|
||||
{
|
||||
mps_arena_t arena;
|
||||
|
|
@ -159,9 +159,14 @@ extern int main(int argc, char *argv[])
|
|||
|
||||
abqSize = 0;
|
||||
|
||||
die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE),
|
||||
die(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none),
|
||||
"mps_arena_create");
|
||||
|
||||
MPS_ARGS_BEGIN(args) {
|
||||
MPS_ARGS_ADD(args, MPS_KEY_MFS_UNIT_SIZE, sizeof(TestBlockStruct));
|
||||
die(mps_pool_create_k(&pool, arena, mps_class_mfs(), args), "pool_create");
|
||||
} MPS_ARGS_END(args);
|
||||
|
||||
die(ABQInit((Arena)arena, &abq, NULL, ABQ_SIZE, sizeof(TestBlock)),
|
||||
"ABQInit");
|
||||
|
||||
|
|
|
|||
|
|
@ -99,11 +99,7 @@ static void test_main(int interior, int stack)
|
|||
mps_root_t reg_root = NULL;
|
||||
void *marker = ▮
|
||||
|
||||
MPS_ARGS_BEGIN(args) {
|
||||
MPS_ARGS_ADD(args, MPS_KEY_ARENA_SIZE, 1 << 20);
|
||||
MPS_ARGS_DONE(args);
|
||||
res = mps_arena_create_k(&scheme_arena, mps_arena_class_vm(), args);
|
||||
} MPS_ARGS_END(args);
|
||||
res = mps_arena_create_k(&scheme_arena, mps_arena_class_vm(), mps_args_none);
|
||||
if (res != MPS_RES_OK) error("Couldn't create arena");
|
||||
|
||||
res = mps_chain_create(&obj_chain, scheme_arena,
|
||||
|
|
|
|||
|
|
@ -4,21 +4,37 @@
|
|||
* Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
|
||||
*/
|
||||
|
||||
#include "mps.h"
|
||||
#include "mpsavm.h"
|
||||
#include "mpscmfs.h"
|
||||
#include "mpm.h"
|
||||
#include "testlib.h"
|
||||
#include "mpslib.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
#include <stdlib.h> /* free, malloc */
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Lock a = malloc(LockSize());
|
||||
Lock b = malloc(LockSize());
|
||||
mps_arena_t arena;
|
||||
mps_pool_t pool;
|
||||
mps_addr_t p;
|
||||
Lock a, b;
|
||||
|
||||
testlib_init(argc, argv);
|
||||
|
||||
die(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none),
|
||||
"arena_create");
|
||||
MPS_ARGS_BEGIN(args) {
|
||||
MPS_ARGS_ADD(args, MPS_KEY_MFS_UNIT_SIZE, LockSize());
|
||||
die(mps_pool_create_k(&pool, arena, mps_class_mfs(), args), "pool_create");
|
||||
} MPS_ARGS_END(args);
|
||||
|
||||
die(mps_alloc(&p, pool, LockSize()), "alloc a");
|
||||
a = p;
|
||||
die(mps_alloc(&p, pool, LockSize()), "alloc b");
|
||||
b = p;
|
||||
|
||||
Insist(a != NULL);
|
||||
Insist(b != NULL);
|
||||
|
||||
|
|
@ -46,8 +62,11 @@ int main(int argc, char *argv[])
|
|||
LockReleaseMPM(a);
|
||||
LockFinish(a);
|
||||
LockReleaseGlobalRecursive();
|
||||
free(a);
|
||||
free(b);
|
||||
|
||||
mps_free(pool, a, LockSize());
|
||||
mps_free(pool, b, LockSize());
|
||||
mps_pool_destroy(pool);
|
||||
mps_arena_destroy(arena);
|
||||
|
||||
printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@
|
|||
* Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license.
|
||||
*/
|
||||
|
||||
#include "mps.h"
|
||||
#include "mpsavm.h"
|
||||
#include "mpscmfs.h"
|
||||
#include "mpm.h"
|
||||
#include "testlib.h"
|
||||
#include "testthr.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
#include <stdlib.h> /* malloc */
|
||||
|
||||
|
||||
#define nTHREADS 4
|
||||
|
|
@ -63,12 +65,23 @@ static void *thread0(void *p)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
mps_arena_t arena;
|
||||
mps_pool_t pool;
|
||||
mps_addr_t p;
|
||||
testthr_t t[10];
|
||||
unsigned i;
|
||||
|
||||
testlib_init(argc, argv);
|
||||
|
||||
lock = malloc(LockSize());
|
||||
die(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none),
|
||||
"arena_create");
|
||||
MPS_ARGS_BEGIN(args) {
|
||||
MPS_ARGS_ADD(args, MPS_KEY_MFS_UNIT_SIZE, LockSize());
|
||||
die(mps_pool_create_k(&pool, arena, mps_class_mfs(), args), "pool_create");
|
||||
} MPS_ARGS_END(args);
|
||||
|
||||
die(mps_alloc(&p, pool, LockSize()), "alloc");
|
||||
lock = p;
|
||||
Insist(lock != NULL);
|
||||
|
||||
LockInit(lock);
|
||||
|
|
@ -86,6 +99,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
LockFinish(lock);
|
||||
|
||||
mps_free(pool, lock, LockSize());
|
||||
mps_pool_destroy(pool);
|
||||
mps_arena_destroy(arena);
|
||||
|
||||
printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue