Исправлена многопоточность, в многопоточность добавлены все доступные тесты, переделана лггика флогов, сделан флаг htlp и json, сам json ещё не сделан.
This commit is contained in:
parent
f6c6846430
commit
cd842d8c05
1 changed files with 82 additions and 47 deletions
129
main.c
129
main.c
|
|
@ -8,6 +8,7 @@
|
|||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#define jemalloc 0
|
||||
|
|
@ -25,7 +26,7 @@
|
|||
#define BLOCK_SIZE (1024ULL*1024ULL*1024ULL*8)
|
||||
|
||||
uint32_t test_patterns[] = {0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555};
|
||||
int test_list[] = {2};
|
||||
int test_list[] = {2,3,4};
|
||||
#define bool unsigned char
|
||||
|
||||
struct tred_pizdec{
|
||||
|
|
@ -38,7 +39,7 @@ struct tred_pizdec{
|
|||
};
|
||||
|
||||
#include "multi_tred.h"
|
||||
|
||||
#include "single_tred.h"
|
||||
|
||||
// Получить доступную память из /proc/meminfo
|
||||
unsigned long int get_mem_available_mb() {
|
||||
|
|
@ -50,37 +51,11 @@ unsigned long int get_mem_available_mb() {
|
|||
if (sscanf(line, "MemAvailable: %lu kB", &available) == 1) break;
|
||||
}
|
||||
fclose(f);
|
||||
printf("mem Gb: %lu\n",(available-1024*500)/1024/1024);
|
||||
printf("mem MB: %lu\n",(available-1024*500)/1024);
|
||||
printf("mem Gb: %lu\n",(available-available/100*10)/1024/1024);
|
||||
printf("mem MB: %lu\n",(available-available/100*10)/1024);
|
||||
return (available - available/100*10)*1024;
|
||||
}
|
||||
|
||||
int parse_ti_flags(int argc, char *argv[], int *t, int *i) {
|
||||
*t = -1;
|
||||
*i = 1;
|
||||
for (int idx = 1; idx < argc; ++idx) {
|
||||
// -tN или -t N
|
||||
if (strncmp(argv[idx], "-t", 2) == 0) {
|
||||
if (strlen(argv[idx]) > 2 && isdigit(argv[idx][2])) {
|
||||
*t = atoi(argv[idx] + 2);
|
||||
} else if (idx + 1 < argc && isdigit(argv[idx + 1][0])) {
|
||||
*t = atoi(argv[idx + 1]);
|
||||
idx++; // пропускаем это число
|
||||
}
|
||||
}
|
||||
// -iN или -i N
|
||||
else if (strncmp(argv[idx], "-i", 2) == 0) {
|
||||
if (strlen(argv[idx]) > 2 && isdigit(argv[idx][2])) {
|
||||
*i = atoi(argv[idx] + 2);
|
||||
} else if (idx + 1 < argc && isdigit(argv[idx + 1][0])) {
|
||||
*i = atoi(argv[idx + 1]);
|
||||
idx++; // пропускаем это число
|
||||
}
|
||||
}
|
||||
}
|
||||
return (*t != -1 || *i != -1) ? 0 : -1;
|
||||
}
|
||||
|
||||
|
||||
void test_patern(struct tred_pizdec** meta,unsigned long* thread, int tred, size_t words, uint32_t * mem, int* err, int p, int test_tipe){
|
||||
if (test_tipe == 1){
|
||||
|
|
@ -91,6 +66,14 @@ void test_patern(struct tred_pizdec** meta,unsigned long* thread, int tred, size
|
|||
printf("\rЗапушен патерн инкрементации");
|
||||
fflush(stdout);
|
||||
}
|
||||
else if (test_tipe == 3){
|
||||
printf("\rЗапушен патерн ones test");
|
||||
fflush(stdout);
|
||||
}
|
||||
else if (test_tipe == 4){
|
||||
printf("\rЗапушен патерн zeros test");
|
||||
fflush(stdout);
|
||||
}
|
||||
for (bool i = 0;(i != tred); i++){
|
||||
meta[i] = malloc(sizeof(struct tred_pizdec));
|
||||
meta[i]->id = p;
|
||||
|
|
@ -118,6 +101,7 @@ void test_patern(struct tred_pizdec** meta,unsigned long* thread, int tred, size
|
|||
meta[i]->mem = mem;
|
||||
meta[i]->words_stop = words/tred*(i+1);
|
||||
meta[i]->words_start = i * words/tred;
|
||||
meta[i]->test_tip = test_tipe;
|
||||
DEBUG_PRINT("words_stop: %zu\n",meta[i]->words_stop);
|
||||
DEBUG_PRINT("words_start:%zu\n",meta[i]->words_start);
|
||||
pthread_create(&thread[i], NULL, check_pattern_multi_tred, (void*)meta[i]);
|
||||
|
|
@ -134,12 +118,50 @@ void test_patern(struct tred_pizdec** meta,unsigned long* thread, int tred, size
|
|||
}
|
||||
else printf("Errors: %d\n", *err);
|
||||
}
|
||||
void print_help(const char *progname) {
|
||||
printf("Использование: %s [опции]\n", progname);
|
||||
printf(" -h, --help показать это сообщение\n");
|
||||
printf(" -t, --threads N указать число потоков\n");
|
||||
printf(" -i, --iterations N указать число повторения тестов\n");
|
||||
printf(" -j, --json вывод в виде json\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[]){
|
||||
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
|
||||
perror("mlockall ошибка!\nВозможно недостаточно прав!\n");
|
||||
return 1;
|
||||
}
|
||||
int tred = -1, iterations = 1;
|
||||
|
||||
const struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"threads", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"iterations", required_argument, 0, 'i'},
|
||||
{"json", no_argument, 0, 'j'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt_long(argc, argv, "ht:i:j", long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'h':
|
||||
print_help(argv[0]);
|
||||
exit(0);
|
||||
case 't':
|
||||
tred = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
iterations = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
print_help(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("threads: %d\n", tred);
|
||||
|
||||
unsigned long int mem_size = get_mem_available_mb();
|
||||
size_t words = mem_size / sizeof(uint32_t);
|
||||
uint32_t *mem = malloc(mem_size);
|
||||
|
|
@ -150,8 +172,6 @@ int main(int argc, char *argv[]) {
|
|||
//struct tred_pizdec* meta[];
|
||||
//pthread_t thread[];
|
||||
int err = 0;
|
||||
int tred, iterations;
|
||||
parse_ti_flags(argc, argv, &tred, &iterations);
|
||||
struct tred_pizdec** meta = malloc(sizeof(struct tred_pizdec) * tred);
|
||||
pthread_t *thread = malloc(sizeof(pthread_t) * tred);
|
||||
printf("iterations: %i\n", iterations);
|
||||
|
|
@ -166,34 +186,49 @@ int main(int argc, char *argv[]) {
|
|||
else{
|
||||
// Основные паттерны 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555
|
||||
for (size_t p = 0; p < sizeof(test_patterns)/sizeof(test_patterns[0]); ++p){
|
||||
printf("Запушен патерн 0x%08X", test_patterns[p]);
|
||||
printf("\rЗапушен патерн 0x%08X", test_patterns[p]);
|
||||
fflush(stdout);
|
||||
fill_pattern(mem, words, test_patterns[p]);
|
||||
printf("Жду\n");
|
||||
printf("\r-- Проверяю ");
|
||||
fflush(stdout);
|
||||
err += check_pattern(mem, words, test_patterns[p]);
|
||||
if (err == 0) printf("OK\n");
|
||||
else printf("Errors: %d\n", err);
|
||||
if (err == 0){
|
||||
printf("\rOK");
|
||||
fflush(stdout);
|
||||
}
|
||||
else printf("\nErrors: %d\n", err);
|
||||
}
|
||||
// Инкремент
|
||||
printf("Запушен патерн инкрементации\n");
|
||||
printf("\rЗапушен патерн инкрементации");
|
||||
fflush(stdout);
|
||||
fill_increment(mem, words);
|
||||
//usleep(10000000);
|
||||
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]);
|
||||
printf("\nОшибка в тесте %zu: должен быть: 0x%08X, фактический: 0x%08X\n", i, (uint32_t)i, mem[i]);
|
||||
err++;
|
||||
if (err > 10) break;
|
||||
}
|
||||
}
|
||||
printf("Запушен патерн Walking Ones\n");
|
||||
printf("\rЗапушен патерн Walking Ones");
|
||||
fflush(stdout);
|
||||
fill_walking_ones(mem, words);
|
||||
if (0 == fill_walking_ones_test(mem, words))
|
||||
printf("OK\n");
|
||||
printf("Запушен патерн Walking Zeros\n");
|
||||
if (0 == fill_walking_ones_test(mem, words)){
|
||||
printf("\rOK");
|
||||
fflush(stdout);
|
||||
}
|
||||
printf("\rЗапушен патерн Walking Zeros");
|
||||
fflush(stdout);
|
||||
fill_walking_zeros(mem, words);
|
||||
if (0 == fill_walking_zeros_test(mem, words))
|
||||
printf("OK\n");
|
||||
if (err == 0) printf("OK\n");
|
||||
else printf("Errors: %d\n", err);
|
||||
if (0 == fill_walking_zeros_test(mem, words)){
|
||||
printf("\rOK");
|
||||
fflush(stdout);
|
||||
}
|
||||
if (err == 0){
|
||||
printf("\rOK");
|
||||
fflush(stdout);
|
||||
}
|
||||
else printf("\nErrors: %d\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue