Skip to content

Instantly share code, notes, and snippets.

@inoremap
Created February 6, 2021 07:50
Show Gist options
  • Save inoremap/1d512a80cb8db7390bfefdabb37fbc2d to your computer and use it in GitHub Desktop.
Save inoremap/1d512a80cb8db7390bfefdabb37fbc2d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define MBYTE 1048576
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "usage: mtest SIZE_IN_MBYTES\n");
return 0;
}
char* end;
size_t size_mb = strtoul(argv[1], &end, 10);
printf("test memory for %d Mbytes\n", size_mb);
size_t size = size_mb * MBYTE;
char* mem = malloc(size);
if (mem == NULL) {
fprintf(stderr, "memory allocation failed\n");
return 0;
}
srand(42);
for (size_t i = 0; i < size; ++i) {
if ((i % MBYTE) == 0)
printf("write %dM\n", i / MBYTE);
mem[i] = rand() % 256;
}
printf("fill memory success\n");
srand(42);
for (size_t i = 0; i < size; ++i) {
if (mem[i] != (rand() % 256)) {
fprintf(stderr, "memory content not match\n");
return 1;
}
if ((i % MBYTE) == 0)
printf("verify %dM\n", i / MBYTE);
}
printf("test success\n");
return 0;
}
@inoremap
Copy link
Author

inoremap commented Feb 6, 2021

Build command:
gcc -O2 -static -Wall -Wextra -pedantic mtest.c -o mtest

armhf binary - https://drive.google.com/file/d/153oHN84rXl00vUYPQrdvilcuchb66TWw/view?usp=sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment