2005-08-10 02:40:42 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-08-10 02:40:42 +04:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2005-08-12 17:29:26 +04:00
|
|
|
#include <sys/mman.h>
|
2005-08-10 02:40:42 +04:00
|
|
|
|
|
|
|
#include "ompi/include/constants.h"
|
|
|
|
#include "opal/runtime/opal.h"
|
2005-11-11 03:26:27 +03:00
|
|
|
#include "opal/memoryhooks/memory.h"
|
2005-08-10 02:40:42 +04:00
|
|
|
|
2005-08-13 05:08:34 +04:00
|
|
|
int ret = 2;
|
2005-08-10 02:40:42 +04:00
|
|
|
int size = 10 * 1024 * 1024;
|
|
|
|
|
|
|
|
static void
|
|
|
|
callback(void *buf, size_t length, void *cbdata)
|
|
|
|
{
|
|
|
|
printf("\tcallback with %lx, %d\n", (unsigned long) buf, (int) length);
|
2005-08-13 05:08:34 +04:00
|
|
|
ret--;
|
2005-08-10 02:40:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2005-08-13 05:08:34 +04:00
|
|
|
void * foo, *bar;
|
2005-08-10 02:40:42 +04:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
opal_init();
|
|
|
|
if (!opal_mem_free_is_supported()) {
|
|
|
|
printf("no memory registration supported. skipping\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
retval = opal_mem_free_register_handler(callback, NULL);
|
2005-08-18 06:59:02 +04:00
|
|
|
if (retval != OMPI_SUCCESS) {
|
|
|
|
printf("handler registration failed\n");
|
|
|
|
return retval;
|
|
|
|
}
|
2005-08-10 02:40:42 +04:00
|
|
|
|
|
|
|
/* make some big malloc that should trip an unmap */
|
|
|
|
foo = malloc(size);
|
2005-08-14 07:10:51 +04:00
|
|
|
printf(" - free of first big buffer\n");
|
2005-08-10 02:40:42 +04:00
|
|
|
free(foo);
|
|
|
|
|
2005-08-12 17:29:26 +04:00
|
|
|
/* and check munmap directly */
|
2005-08-14 07:10:51 +04:00
|
|
|
printf(" - munmap of small buffer\n");
|
2005-08-12 17:29:26 +04:00
|
|
|
munmap(NULL, 0);
|
|
|
|
|
2005-08-13 05:08:34 +04:00
|
|
|
/* see if realloc works. This is kind of a huristic (that going
|
|
|
|
from a small block to a big one will fail), so don't make this
|
|
|
|
an error */
|
|
|
|
if (ret == 0) {
|
2005-08-14 07:10:51 +04:00
|
|
|
ret = 2;
|
|
|
|
printf(" - realloc\n");
|
|
|
|
foo = malloc(size);
|
2005-08-13 05:08:34 +04:00
|
|
|
bar = malloc(10);
|
2005-08-14 07:10:51 +04:00
|
|
|
foo = realloc(foo, size * 2);
|
2005-08-13 05:08:34 +04:00
|
|
|
free(bar);
|
|
|
|
free(foo);
|
2005-08-14 07:10:51 +04:00
|
|
|
if (ret > 0) {
|
2005-08-13 05:08:34 +04:00
|
|
|
printf("WARNING - It appears that realloc does not trigger a callback\n");
|
|
|
|
printf("WARNING - this may be a problem or it may be a sign that your\n");
|
|
|
|
printf("WARNING - memory manager is better than mine\n");
|
|
|
|
printf("ret: %d\n", ret);
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2005-08-10 02:40:42 +04:00
|
|
|
retval = opal_mem_free_unregister_handler(callback);
|
|
|
|
if (retval != OMPI_SUCCESS) return retval;
|
|
|
|
|
|
|
|
opal_finalize();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|