Fixed broken tests
This commit is contained in:
parent
0b0344be69
commit
5e52de10bd
7 changed files with 29 additions and 98 deletions
|
|
@ -9,21 +9,24 @@ struct Obj {
|
|||
};
|
||||
|
||||
int main() {
|
||||
GC::Heap *heap = GC::Heap::the2();
|
||||
GC::Heap::init();
|
||||
Obj *obj;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
|
||||
obj = static_cast<Obj *>(GC::Heap::alloc(sizeof(Obj)));
|
||||
obj->a = i * i + 1;
|
||||
obj->b = i * i + 2;
|
||||
obj->c = i * i + 3;
|
||||
}
|
||||
|
||||
// heap->force_collect();
|
||||
auto heap = GC::Heap::debug_the();
|
||||
heap->collect(COLLECT_ALL);
|
||||
|
||||
std::cout << obj->a << ", " << obj->b << ", " << obj->c << std::endl;
|
||||
|
||||
//delete heap;
|
||||
GC::Heap::dispose();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -29,8 +29,8 @@ int main() {
|
|||
GC::Heap *singleton_test() {
|
||||
std::cout << "TESTING SINGLETON INSTANCES" << std::endl;
|
||||
std::cout << "===========================" << std::endl;
|
||||
std::cout << "Call 1:\t" << GC::Heap::the() << std::endl; // First call which initializes the singleton instance
|
||||
GC::Heap *heap = GC::Heap::the(); // Second call which should return the initialized instance
|
||||
std::cout << "Call 1:\t" << GC::Heap::debug_the() << std::endl; // First call which initializes the singleton instance
|
||||
GC::Heap *heap = GC::Heap::debug_the(); // Second call which should return the initialized instance
|
||||
std::cout << "Call 2:\t" << heap << std::endl;
|
||||
std::cout << "===========================" << std::endl;
|
||||
return heap;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
#include "../include/heap.hpp"
|
||||
|
||||
GC::Heap *gc = GC::Heap::the();
|
||||
#include "heap.hpp"
|
||||
|
||||
struct Node {
|
||||
int id;
|
||||
|
|
@ -10,12 +8,12 @@ struct Node {
|
|||
Node *create_chain(int depth) {
|
||||
std::vector<Node*> nodes;
|
||||
if (depth > 0) {
|
||||
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
Node *last_node = static_cast<Node *>(GC::Heap::alloc(sizeof(Node)));
|
||||
last_node->id = depth;
|
||||
last_node->child = nullptr;
|
||||
nodes.push_back(last_node);
|
||||
for (int i = 0; i < depth; i++) {
|
||||
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
|
||||
Node *node = static_cast<Node *>(GC::Heap::alloc(sizeof(Node)));
|
||||
node->id = depth-i;
|
||||
node->child = nodes[i-1];
|
||||
nodes.push_back(node);
|
||||
|
|
@ -30,7 +28,7 @@ Node *create_chain(int depth) {
|
|||
}
|
||||
|
||||
void create_array(size_t size) {
|
||||
int *arr = static_cast<int *>(gc->alloc(sizeof(int) * size));
|
||||
int *arr = static_cast<int *>(GC::Heap::alloc(sizeof(int) * size));
|
||||
}
|
||||
|
||||
void detach_pointer(long **ptr) {
|
||||
|
|
@ -54,19 +52,20 @@ void test_some_types() {
|
|||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from test_some_types:\t" << stack_start << std::endl;
|
||||
|
||||
long *l = static_cast<long *>(gc->alloc(sizeof(long)));
|
||||
long *l = static_cast<long *>(GC::Heap::alloc(sizeof(long)));
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
detach_pointer(&l);
|
||||
std::cout << "l points to:\t\t" << l << std::endl;
|
||||
|
||||
// Some more dummy values of different sizes, to test stack pointer alignment
|
||||
int *i = static_cast<int *>(gc->alloc(sizeof(int)));
|
||||
char *c = static_cast<char *>(gc->alloc(sizeof(int)));
|
||||
short *s = static_cast<short *>(gc->alloc(sizeof(short)));
|
||||
int *i = static_cast<int *>(GC::Heap::alloc(sizeof(int)));
|
||||
char *c = static_cast<char *>(GC::Heap::alloc(sizeof(int)));
|
||||
short *s = static_cast<short *>(GC::Heap::alloc(sizeof(short)));
|
||||
}
|
||||
|
||||
int main() {
|
||||
gc->init();
|
||||
GC::Heap::init();
|
||||
GC::Heap *gc = GC::Heap::debug_the();
|
||||
gc->check_init();
|
||||
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
std::cout << "Stack start from main:\t" << stack_start << std::endl;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ struct Obj {
|
|||
};
|
||||
|
||||
int main() {
|
||||
auto heap = GC::Heap::the2();
|
||||
auto heap = GC::Heap::debug_the();
|
||||
|
||||
std::cout << "heap:\t" << heap << std::endl;
|
||||
|
||||
auto obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
|
||||
auto obj = static_cast<Obj *>(GC::Heap::alloc(sizeof(Obj)));
|
||||
|
||||
std::cout << "obj: \t" << obj << std::endl;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue