summaryrefslogtreecommitdiff
path: root/src/kernel/testmalloc.c
diff options
context:
space:
mode:
authorBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
committerBrett Weiland <brett_weiland@bpcspace.com>2021-08-24 14:09:29 -0500
commit9b22a6965579ea1867aea291d910c96f386b518b (patch)
treed06dbb9c4708f1cc713bcb115b32ff9bce4cf9b9 /src/kernel/testmalloc.c
parentbad4b0e9bdfee336bfc1c23761408279eaec1558 (diff)
major backup 8.24.21
Diffstat (limited to 'src/kernel/testmalloc.c')
-rw-r--r--src/kernel/testmalloc.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/kernel/testmalloc.c b/src/kernel/testmalloc.c
new file mode 100644
index 0000000..5733c7c
--- /dev/null
+++ b/src/kernel/testmalloc.c
@@ -0,0 +1,35 @@
+#define CHUNK_SIZE_FROM_INDEX(i) ((1 << ((i) + 5)))
+
+#include <printf.h>
+#include <heap.h>
+#include <libc.h>
+#include <random.h>
+
+//will delete later
+
+void test_malloc(unsigned int cnt) {
+ void *testchunks[cnt];
+ unsigned int rindex[cnt], testchunk_size, i, x;
+
+ bzero(rindex, cnt * sizeof(unsigned int));
+ for(x = 0; x < cnt; x++) {
+ testchunk_size = (CHUNK_SIZE_FROM_INDEX(randint() % 7) - 24);
+ testchunks[x] = malloc(testchunk_size);
+ //printf("ALLOCATING CHUNK %p SIZE %i\n", (void *)testchunks[x] - 24, testchunk_size);
+ }
+ for(x = 0; x < cnt;) {
+ i = randint() % cnt;
+ if(rindex[i]) continue;
+ rindex[i] = x;
+ x++;
+ }
+ for(x = 0; x < cnt; x++) {
+ //printf("FREEING CHUNK %p\n", (void *)testchunks[rindex[x]]);
+ free(testchunks[rindex[x]]);
+ }
+ printf("\nmalloc tester:\n");
+ printf("THIS NEEDS TO BE EMPTY______________\n");
+ debug_heap();
+ printf("____________________________________\n");
+
+}