-/* Copyright (c) 2012-2021. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2012-2023. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/Exception.hpp"
+#include "simgrid/engine.h"
+#include "src/xbt/mmalloc/mmalloc.h"
#include "xbt.h"
-#include "xbt/mmalloc.h"
#include <array>
#include <cassert>
{
xbt_mheap_t heapA = nullptr;
std::array<void*, TESTSIZE> pointers;
- xbt_init(&argc,argv);
+ simgrid_init(&argc, argv);
XBT_INFO("Allocating a new heap");
unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
auto* addr = reinterpret_cast<void*>(((unsigned long)sbrk(0) + BUFFSIZE) & mask);
- heapA = xbt_mheap_new(-1, addr);
+ heapA = xbt_mheap_new(addr, 0);
if (heapA == nullptr) {
perror("attach 1 failed");
fprintf(stderr, "bye\n");
pointers[i] = mmalloc(heapA, size);
}
- XBT_INFO("free all blocks (each one twice, to check that double free are correctly caught)");
- for (i = 0; i < TESTSIZE; i++) {
- bool gotit = false;
+ XBT_INFO("free all blocks");
+ for (i = 0; i < TESTSIZE; i++)
mfree(heapA, pointers[i]);
- try {
- mfree(heapA, pointers[i]);
- } catch (const simgrid::Exception&) {
- gotit = true;
- }
- xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
- }
-
- XBT_INFO("free again all blocks (to really check that double free are correctly caught)");
- for (i = 0; i < TESTSIZE; i++) {
- bool gotit = false;
- try {
- mfree(heapA, pointers[i]);
- } catch (const simgrid::Exception&) {
- gotit = true;
- }
- xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
- }
XBT_INFO("Let's try different codepaths for mrealloc");
for (i = 0; i < TESTSIZE; i++) {