* add simple C++ test to make sure that new/delete trigger the correct
callbacks This commit was SVN r6924.
Этот коммит содержится в:
родитель
331a971b13
Коммит
4da11a4851
@ -18,7 +18,8 @@ include $(top_srcdir)/test/support/Makefile.options
|
||||
|
||||
check_PROGRAMS = \
|
||||
opal_memory_basic \
|
||||
opal_memory_speed
|
||||
opal_memory_speed \
|
||||
opal_memory_cxx
|
||||
|
||||
TESTS = \
|
||||
$(check_PROGRAMS)
|
||||
@ -36,3 +37,10 @@ opal_memory_speed_LDADD = \
|
||||
$(top_builddir)/opal/libopal.la \
|
||||
$(top_builddir)/test/support/libsupport.a
|
||||
opal_memory_speed_DEPENDENCIES = $(opal_memory_speed_LDADD)
|
||||
|
||||
opal_memory_cxx_SOURCES = opal_memory_cxx.cc
|
||||
opal_memory_cxx_LDFLAGS = $(WRAPPER_EXTRA_LDFLAGS)
|
||||
opal_memory_cxx_LDADD = \
|
||||
$(top_builddir)/opal/libopal.la \
|
||||
$(top_builddir)/test/support/libsupport.a
|
||||
opal_memory_cxx_DEPENDENCIES = $(opal_memory_cxx_LDADD)
|
||||
|
78
test/memory/opal_memory_cxx.cc
Обычный файл
78
test/memory/opal_memory_cxx.cc
Обычный файл
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||
* All rights reserved.
|
||||
* 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 <vector>
|
||||
|
||||
#include "ompi/include/constants.h"
|
||||
#include "opal/runtime/opal.h"
|
||||
#include "opal/memory/memory.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int ret = 1;
|
||||
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);
|
||||
ret--;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
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);
|
||||
if (retval != OMPI_SUCCESS) return retval;
|
||||
|
||||
vector<int> *big_vec;
|
||||
|
||||
printf(" - allocating big vector\n");
|
||||
big_vec = new vector<int>;
|
||||
|
||||
big_vec->reserve(10000);
|
||||
/* touch all the locations, just to make sure C++ isn't smarter
|
||||
than I am */
|
||||
for (int i = 0 ; i < 10000 ; ++i) {
|
||||
(*big_vec)[i] = i;
|
||||
}
|
||||
|
||||
printf(" - deleting big vector\n");
|
||||
delete big_vec;
|
||||
|
||||
printf(" - all done\n");
|
||||
|
||||
retval = opal_mem_free_unregister_handler(callback);
|
||||
if (retval != OMPI_SUCCESS) return retval;
|
||||
|
||||
opal_finalize();
|
||||
|
||||
/* some implementations of delete will call free twice */
|
||||
if (ret < 0) ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
Загрузка…
x
Ссылка в новой задаче
Block a user