From 988630f985f426954fd6cfa8b176873e1d716d09 Mon Sep 17 00:00:00 2001 From: romenskiy Date: Thu, 19 Jun 2025 11:59:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B8=D0=BD=D0=B8=D0=BC=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=82=D0=B5=D1=81=D1=82=20=D1=81=20?= =?UTF-8?q?0x00000000,=200xFFFFFFFF,=200xAAAAAAAA,=200x55555555=20=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=BD=D0=BA=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++++ main.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5392cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +build/ +.kdev4/ +*~ +*.kdev4 + + + diff --git a/main.c b/main.c index 66f31f8..e14d33f 100644 --- a/main.c +++ b/main.c @@ -1,8 +1,79 @@ #include #include +#include +#include +#include +#include +#include +#include -int main(int argc, char *argv[]) -{ - puts("Hello, World!"); +#define BLOCK_SIZE (1024ULL*1024ULL*1024ULL*8) + +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; }