Check correctness of the kheap split and merge. Update memory test.
This commit is contained in:
+35
-8
@@ -3,6 +3,8 @@
|
||||
/// @copyright (c) 2014-2023 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
#include "io/debug.h"
|
||||
#include "time.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/unistd.h>
|
||||
@@ -10,16 +12,41 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
if (argc != 3) {
|
||||
printf("%s: You must provide 2 dimensions.\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
char *ptr;
|
||||
int N = strtol(argv[1], &ptr, 10), *V;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
for (int j = 1; j < N; ++j) {
|
||||
V = (int *)malloc(j * sizeof(int));
|
||||
free(V);
|
||||
}
|
||||
}
|
||||
int rows = strtol(argv[1], &ptr, 10);
|
||||
int cols = strtol(argv[2], &ptr, 10);
|
||||
|
||||
printf("Allocating memory!\n");
|
||||
pr_warning("Allocating memory!\n");
|
||||
int **M = (int **)malloc(rows * sizeof(int *));
|
||||
for (int i = 0; i < rows; ++i)
|
||||
M[i] = (int *)malloc(cols * sizeof(int));
|
||||
|
||||
sleep(5);
|
||||
printf("Writing memory!\n");
|
||||
pr_warning("Writing memory!\n");
|
||||
for (int i = 0; i < rows; ++i)
|
||||
for (int j = 0; j < cols; ++j)
|
||||
M[i][j] = i + j;
|
||||
|
||||
sleep(5);
|
||||
printf("Freeing memory (1)!\n");
|
||||
pr_warning("Freeing memory (1)!\n");
|
||||
for (int i = 0; i < rows; ++i)
|
||||
if (i % 2 != 0)
|
||||
free(M[i]);
|
||||
printf("Freeing memory (2)!\n");
|
||||
pr_warning("Freeing memory (2)!\n");
|
||||
for (int i = 0; i < rows; ++i)
|
||||
if (i % 2 == 0)
|
||||
free(M[i]);
|
||||
free(M);
|
||||
|
||||
sleep(5);
|
||||
pr_warning("Exiting!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user