Compare commits

..

No commits in common. "memtest" and "master" have entirely different histories.

View file

@ -20,64 +20,41 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
int print_usage() {
printf("usage: size mb/kb/b [chunks]\n");
printf("usage: [size mb/kb/b]");
exit(0);
}
int main(int argc, char** argv)
{
int multp = 0;
int size = 0;
int chunks = 1;
void **test;
if (argc <= 2 || argc > 4)
int m = 0;
uint32_t size = 0;
if(argc <= 2)
print_usage();
if(argc == 3) {
if(!strcmp(argv[2], "mb"))
m = 1024*1024;
else if(!strcmp(argv[2], "kb"))
m = 1024;
else if(!strcmp(argv[2], "b"))
m = 0;
else
print_usage();
}
if(argc > 3)
print_usage();
size = atoi(argv[1]);
if (size <= 0)
if(size <= 0)
print_usage();
if (!strcasecmp(argv[2], "mb"))
multp = 1024*1024;
else if (!strcasecmp(argv[2], "kb"))
multp = 1024;
else if (!strcasecmp(argv[2], "b"))
multp = 1;
else
print_usage();
size *= multp;
if (argc == 4)
chunks = atoi(argv[3]);
test = malloc(chunks * sizeof(void *));
if (!test)
printf("malloc(%d) - FAILED!\n", chunks * sizeof(void *));
// allocate...
int i;
for (i = 0; i < chunks; i++) {
test[i] = malloc(size);
if (test[i])
printf("malloc(%d)\tCHUNK: %d START: %p END: %p\n", size, i, test[i], test[i] + size);
else {
printf("malloc(%d)\tFAILED! Abort allocation, start with freeing memory\n", size);
break;
}
}
// and release again
for (i = 0; i < chunks; i++) {
if (test[i]) {
free(test[i]);
printf("free(%p)\tCHUNK: %d\n", test[i], i);
}
}
free(test);
size *= m;
uint8_t* test = malloc(size);
printf("malloc(%d) - START: %p END: %p \n", size, test, test + size);
return 0;
}