Написал генератор json сейчас информация только по 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555 но это божет не работать без -t

This commit is contained in:
romenskiy 2025-06-26 18:20:25 +03:00
parent cd842d8c05
commit bf32765ea9
8 changed files with 3929 additions and 203 deletions

390
main.c
View file

@ -10,6 +10,18 @@
#include <ctype.h>
#include <getopt.h>
struct args_struct{
int tred;
int iterations;
int json;
size_t words;
};
struct args_struct args;
#include "cJSON/cJSON.h"
#include "args_parser.h"
#define DEBUG 0
#define jemalloc 0
@ -26,9 +38,41 @@
#define BLOCK_SIZE (1024ULL*1024ULL*1024ULL*8)
uint32_t test_patterns[] = {0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555};
char* test_name[] = {"increment", "ones test", "zeros test"};
int pretest_delay = 0;
int test_list[] = {2,3,4};
#define bool unsigned char
struct test_info{
int error;
int number_addresses;
};
struct error_info{
uint32_t error_adres;
uint32_t expected;
uint32_t actual;
struct error_info* error_info_next;
};
struct test_local_stats{
int error_int;
struct error_info* error_info;
struct error_info* error_info_end;
};
struct test_stats{
int len;
struct test_local_stats* test_local_stats[];
};
struct struct_info{
struct test_info* test_info;
struct test_stats* test_stats;
};
struct struct_info info;
struct tred_pizdec{
uint32_t* mem;
size_t words_stop;
@ -36,10 +80,11 @@ struct tred_pizdec{
size_t words_start;
int return_error;
bool test_tip;
struct test_stats* test_stats;
};
#include "multi_tred.h"
#include "single_tred.h"
// Получить доступную память из /proc/meminfo
unsigned long int get_mem_available_mb() {
@ -51,189 +96,270 @@ unsigned long int get_mem_available_mb() {
if (sscanf(line, "MemAvailable: %lu kB", &available) == 1) break;
}
fclose(f);
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;
if (!args.json){
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*20)*1024;
}
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){
printf("\rЗапушен патерн 0x%08X", test_patterns[p]);
fflush(stdout);
void meseng_proses(int test_tipe, int p){
if (args.json != 1){
if (test_tipe == 1){
printf("\rЗапушен патерн 0x%08X", test_patterns[p]);
fflush(stdout);
}
else{
printf("\rЗапушен патерн %s", test_name[test_tipe-2]);
fflush(stdout);
}
}
else if (test_tipe == 2){
printf("\rЗапушен патерн инкрементации");
}
void meseng_test_and_slip(){
if (pretest_delay!= 0){
printf("\rЖду ");
fflush(stdout);
usleep(pretest_delay*1000000);
}
if (args.json != 1){
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));
}
void test_patern(struct tred_pizdec** meta,unsigned long* thread, int tred, int* err, int p, int test_tipe){
meseng_proses(test_tipe, p);
for (bool i = 0;(i != tred); i++){// test
meta[i]->id = p;
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, fill_pattern_multi_tred, (void*)meta[i]);
//pthread_join(thread[i], NULL);
}
for (bool i = 0;(i != tred); i++)
for (bool i = 0;(i != tred); i++) //sink tred
pthread_join(thread[i], NULL);
//fill_pattern(mem, words, test_patterns[p]);
//printf("Жду\n");
//usleep(10000000);
printf("\r-- Проверяю ");
fflush(stdout);
meseng_test_and_slip();
//int err = check_pattern(mem, words, test_patterns[p]);
for (bool i = 0;(i != tred); i++){
meta[i] = malloc(sizeof(struct tred_pizdec));
meta[i]->id = p;
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);
for (bool i = 0;(i != tred); i++){// test
pthread_create(&thread[i], NULL, check_pattern_multi_tred, (void*)meta[i]);
//pthread_join(thread[i], NULL);
}
for (bool i = 0;(i != tred); i++){
for (bool i = 0;(i != tred); i++){ //sink tred
pthread_join(thread[i], NULL);
*err += meta[i]->return_error;
free(meta[i]);
}
if (*err == 0){
printf("\rOK\n");
fflush(stdout);
if (!args.json){
if (*err == 0){
printf("\rOK\n");
fflush(stdout);
}
else printf("Errors: %d\n", *err);
}
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");
void json_create(struct tred_pizdec** meta){
cJSON *main_ob = cJSON_CreateObject();
//cJSON_AddItemToArray(main_Array, main_ob);
cJSON *test_ob = cJSON_CreateObject();
cJSON_AddItemToObject(main_ob, "test", test_ob);
char* putaa = malloc(11);
unsigned int error_int=0;
for (int i = 0;i != sizeof(test_patterns)/sizeof(test_patterns[0]); ++i){
sprintf(putaa, "0x%08X",test_patterns[i]);
cJSON *error_ob = cJSON_CreateObject();
cJSON *error_info_array = cJSON_CreateArray();
unsigned int error_int_local=0;
for (int t=0; t != args.tred; t++){
struct error_info* error_info_A = meta[t]->test_stats->test_local_stats[i]->error_info;
error_int_local += meta[t]->test_stats->test_local_stats[i]->error_int;
while(NULL != error_info_A){
//for(){};
//p += meta[t]->return_error;
cJSON *error_local_info_array = cJSON_CreateObject();
{
char* putaa = malloc(16);
sprintf(putaa, "%p",(void*)&error_info_A->error_adres);
cJSON *error_adres = cJSON_CreateString(putaa);
cJSON_AddItemToObject(error_local_info_array, "error_adres", error_adres);
}
{
char* putaa = malloc(11);
sprintf(putaa, "0x%08X",error_info_A->expected);
cJSON *expected = cJSON_CreateString(putaa);
cJSON_AddItemToObject(error_local_info_array, "expected", expected);
}
{
char* putaa = malloc(11);
sprintf(putaa, "0x%08X",error_info_A->actual);
cJSON *actual = cJSON_CreateString(putaa);
cJSON_AddItemToObject(error_local_info_array, "actual", actual);
}
cJSON_AddItemToArray(error_info_array, error_local_info_array);
error_info_A = error_info_A->error_info_next;
}
}
error_int += error_int_local;
cJSON *error_int_j = cJSON_CreateNumber(error_int_local);
cJSON_AddItemToObject(error_ob, "error", error_int_j);
cJSON_AddItemToObject(error_ob, "error_info", error_info_array);
cJSON_AddItemToObject(test_ob, putaa, error_ob);
}
for (int i = 0;i != sizeof(test_name)/sizeof(test_name[0]); ++i){
int error_int_local=0;
cJSON *error_int_j = cJSON_CreateNumber(error_int_local);
cJSON *error_ob = cJSON_CreateObject();
cJSON *error_info_array = cJSON_CreateArray();
cJSON_AddItemToObject(error_ob, "error", error_int_j);
cJSON_AddItemToObject(error_ob, "error_info", error_info_array);
cJSON_AddItemToObject(test_ob, test_name[i], error_ob);
}
free(putaa);
cJSON *test_info_ob = cJSON_CreateObject();
cJSON_AddItemToObject(main_ob, "test_info", test_info_ob);
cJSON *error_int_j = cJSON_CreateNumber(error_int);
cJSON_AddItemToObject(test_info_ob, "error", error_int_j);
cJSON *message_str;
if (error_int)
message_str = cJSON_CreateString("Тест пройден неудачно!");
else
message_str = cJSON_CreateString("Тест пройден успешно!");
cJSON_AddItemToObject(test_info_ob, "message", message_str);
cJSON *number_addresses_int = cJSON_CreateNumber(args.words);
cJSON_AddItemToObject(test_info_ob, "number_addresses", number_addresses_int);
cJSON *mod_test_str = cJSON_CreateString("user_mod");
cJSON_AddItemToObject(test_info_ob, "mod_test", mod_test_str);
char *string = cJSON_Print(main_ob);
printf("%s", string);
//cJSON *volume_js = cJSON_CreateNumber(volume);
//cJSON_AddItemToObject(main_ob, "volume", volume_js);
//cJSON_AddItemToObject(main_ob, "content", content_Array);
}
int main(int argc, char *argv[]){
if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
perror("mlockall ошибка!\nВозможно недостаточно прав!\n");
return 1;
}
int tred = -1, iterations = 1;
args.tred = -1;
args.iterations = 1;
args.json = 0;
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}
};
aaa(&argc, argv, &pretest_delay);
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);
if (!args.json)
printf("threads: %d\n", args.tred);
unsigned long int mem_size = get_mem_available_mb();
size_t words = mem_size / sizeof(uint32_t);
args.words = words;
uint32_t *mem = malloc(mem_size);
if (!mem) {
perror("Память выделена!");
printf("Память не выделена!");
return 1;
}
//struct tred_pizdec* meta[];
//pthread_t thread[];
int err = 0;
struct tred_pizdec** meta = malloc(sizeof(struct tred_pizdec) * tred);
pthread_t *thread = malloc(sizeof(pthread_t) * tred);
printf("iterations: %i\n", iterations);
int err = 0, iterations = args.iterations;
struct tred_pizdec** meta = malloc(sizeof(struct tred_pizdec) * args.tred);
pthread_t *thread = malloc(sizeof(pthread_t) * args.tred);
if (!args.json)
printf("iterations: %i\n", iterations);
for (;iterations != 0; iterations--){
if (tred != -1){
for (size_t p = 0; p < sizeof(test_patterns)/sizeof(test_patterns[0]); ++p)
test_patern(meta, thread, tred, words, mem, &err, p, 1);// Основные паттерны 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555
for (int test_list_id = 0; test_list_id < sizeof(test_list)/sizeof(test_list[0]); ++test_list_id){
test_patern(meta, thread, tred, words, mem, &err, 0, test_list[test_list_id]);
if (args.tred != -1){
for (bool i = 0;(i != args.tred); i++){// test
meta[i] = malloc(sizeof(struct tred_pizdec));
meta[i]->test_stats = malloc(sizeof(struct test_stats) +
(sizeof(test_list)/sizeof(test_list[0]) + sizeof(test_patterns)/sizeof(test_patterns[0])) * sizeof(struct test_local_stats*)
);
meta[i]->test_stats->len = (sizeof(test_list)/sizeof(test_list[0]) + sizeof(test_patterns)/sizeof(test_patterns[0]));
//meta[i]->test_stats = malloc(meta[i]->test_stats->len);
for (int m=0;m != meta[i]->test_stats->len;m++){
meta[i]->test_stats->test_local_stats[m] = malloc(sizeof(struct test_local_stats));
meta[i]->test_stats->test_local_stats[m]->error_int = 0;
meta[i]->test_stats->test_local_stats[m]->error_info = NULL;
//meta[i]->test_stats->test_local_stats[m]->
}
meta[i]->mem = mem;
meta[i]->words_stop = words/args.tred*(i+1);
meta[i]->words_start = i * words/args.tred;
meta[i]->return_error = 0;
DEBUG_PRINT("words_stop: %zu\n",meta[i]->words_stop);
DEBUG_PRINT("words_start:%zu\n",meta[i]->words_start);
}
for (size_t p = 0; p < sizeof(test_patterns)/sizeof(test_patterns[0]); ++p){
test_patern(meta, thread, args.tred, &err, p, 1);// Основные паттерны 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555
}
for (int test_list_id = 0; test_list_id < sizeof(test_list)/sizeof(test_list[0]); ++test_list_id){
test_patern(meta, thread, args.tred, &err, 0, test_list[test_list_id]);
}
free(mem);
if (args.json)
json_create(meta);
for (bool i = 0;(i != args.tred); i++)
free(meta[i]);
}
else{
struct tred_pizdec meta;
meta.mem = mem;
meta.words_stop = words;
meta.words_start = 0;
meta.test_tip = 1;
// Основные паттерны 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555
for (size_t p = 0; p < sizeof(test_patterns)/sizeof(test_patterns[0]); ++p){
printf("\rЗапушен патерн 0x%08X", test_patterns[p]);
fflush(stdout);
fill_pattern(mem, words, test_patterns[p]);
printf("\r-- Проверяю ");
fflush(stdout);
err += check_pattern(mem, words, test_patterns[p]);
if (err == 0){
printf("\rOK");
fflush(stdout);
}
else printf("\nErrors: %d\n", err);
}
// Инкремент
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("\nОшибка в тесте %zu: должен быть: 0x%08X, фактический: 0x%08X\n", i, (uint32_t)i, mem[i]);
err++;
if (err > 10) break;
//struct tred_pizdec meta = malloc(sizeof(struct tred_pizdec));
meta.id = p;
meseng_proses(meta.test_tip, meta.id);
fill_pattern_multi_tred((void*)&meta);
//fill_pattern(mem, words, test_patterns[p]);
meseng_test_and_slip();
check_pattern_multi_tred((void*)&meta);
err = meta.return_error;
//err += check_pattern(mem, words, test_patterns[p]);
free(mem);
if (!args.json){
if (err == 0){
printf("\rOK\n");
fflush(stdout);
}
else printf("\nErrors: %d\n", err);
}
}
printf("\rЗапушен патерн Walking Ones");
fflush(stdout);
fill_walking_ones(mem, words);
if (0 == fill_walking_ones_test(mem, words)){
printf("\rOK");
fflush(stdout);
for (int test_list_id = 0; test_list_id < sizeof(test_list)/sizeof(test_list[0]); ++test_list_id){
meta.test_tip = test_list[test_list_id];
meseng_proses(meta.test_tip, meta.id);
fill_pattern_multi_tred((void*)&meta);
meseng_test_and_slip();
check_pattern_multi_tred((void*)&meta);
if (!args.json){
if(meta.return_error == 0){
printf("\rOK\n");
fflush(stdout);
}
else printf("Errors: %d\n", meta.return_error);
}
if (!args.json){
if (err == 0){
printf("\rOK");
fflush(stdout);
}
else printf("\nErrors: %d\n", err);
}
}
printf("\rЗапушен патерн Walking Zeros");
fflush(stdout);
fill_walking_zeros(mem, words);
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);
}
}
free(mem);
//if(args.json)
//for (bool i = 0;(args.tred != -1 || i != args.tred); i++)
// free(meta[i]);
return 0;
}