Compare commits
No commits in common. "memtest" and "master" have entirely different histories.
1 changed files with 25 additions and 48 deletions
|
@ -20,64 +20,41 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
int print_usage() {
|
int print_usage() {
|
||||||
printf("usage: size mb/kb/b [chunks]\n");
|
printf("usage: [size mb/kb/b]");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int multp = 0;
|
int m = 0;
|
||||||
int size = 0;
|
uint32_t size = 0;
|
||||||
int chunks = 1;
|
if(argc <= 2)
|
||||||
|
|
||||||
void **test;
|
|
||||||
|
|
||||||
if (argc <= 2 || argc > 4)
|
|
||||||
print_usage();
|
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]);
|
size = atoi(argv[1]);
|
||||||
if (size <= 0)
|
if(size <= 0)
|
||||||
print_usage();
|
print_usage();
|
||||||
|
|
||||||
if (!strcasecmp(argv[2], "mb"))
|
size *= m;
|
||||||
multp = 1024*1024;
|
uint8_t* test = malloc(size);
|
||||||
else if (!strcasecmp(argv[2], "kb"))
|
printf("malloc(%d) - START: %p END: %p \n", size, test, test + size);
|
||||||
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);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue