Минимальный тест с 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555 и инкрементацией
This commit is contained in:
parent
13d1a2de0a
commit
988630f985
2 changed files with 81 additions and 3 deletions
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
build/
|
||||||
|
.kdev4/
|
||||||
|
*~
|
||||||
|
*.kdev4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
77
main.c
77
main.c
|
|
@ -1,8 +1,79 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
#define BLOCK_SIZE (1024ULL*1024ULL*1024ULL*8)
|
||||||
{
|
|
||||||
puts("Hello, World!");
|
uint32_t test_patterns[] = {0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555};
|
||||||
|
|
||||||
|
void fill_pattern(uint32_t *buf, size_t words, uint32_t pattern) {
|
||||||
|
for (size_t i = 0; i < words; i++) {
|
||||||
|
buf[i] = pattern;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_increment(uint32_t *buf, size_t words) {
|
||||||
|
for (size_t i = 0; i < words; i++) {
|
||||||
|
buf[i] = (uint32_t)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_pattern(uint32_t *buf, size_t words, uint32_t pattern) {
|
||||||
|
int errors = 0;
|
||||||
|
for (size_t i = 0; i < words; i++) {
|
||||||
|
if (buf[i] != pattern) {
|
||||||
|
printf("Ошибка в тесте %zu: должен быть: 0x%08X, фактический: 0x%08X\n", i, pattern, buf[i]);
|
||||||
|
errors++;
|
||||||
|
if (errors > 10) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
|
||||||
|
perror("mlockall ошибка!\nВозможно недостаточно прав!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
size_t words = BLOCK_SIZE / sizeof(uint32_t);
|
||||||
|
uint32_t *mem = malloc(BLOCK_SIZE);
|
||||||
|
if (!mem) {
|
||||||
|
perror("Память выделена!");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Основные паттерны 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555
|
||||||
|
for (size_t p = 0; p < sizeof(test_patterns)/sizeof(test_patterns[0]); ++p) {
|
||||||
|
printf("Запушен патерн 0x%08X\n", test_patterns[p]);
|
||||||
|
fill_pattern(mem, words, test_patterns[p]);
|
||||||
|
printf("Жду\n");
|
||||||
|
usleep(10000000);
|
||||||
|
printf("Проверяю\n");
|
||||||
|
int err = check_pattern(mem, words, test_patterns[p]);
|
||||||
|
if (err == 0) printf("OK\n");
|
||||||
|
else printf("Errors: %d\n", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Инкремент
|
||||||
|
printf("Запушен патерн инкрементации\n");
|
||||||
|
fill_increment(mem, words);
|
||||||
|
usleep(10000000);
|
||||||
|
int err = 0;
|
||||||
|
for (size_t i = 0; i < words; i++) {
|
||||||
|
if (mem[i] != (uint32_t)i) {
|
||||||
|
printf("Ошибка в тесте %zu: должен быть: 0x%08X, фактический: 0x%08X\n", i, (uint32_t)i, mem[i]);
|
||||||
|
err++;
|
||||||
|
if (err > 10) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (err == 0) printf("OK\n");
|
||||||
|
else printf("Errors: %d\n", err);
|
||||||
|
|
||||||
|
free(mem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue