#include #include #include #include #include #include "common.h" #include "uart.h" #include "test_bbs.h" static void bbs_module(){ struct prng *s_prng = {0}; int status = 0; int fd; int totalSuccess = 0; int totalFailed = 0; if ((fd = open("./reports", O_CREAT | O_RDWR, 00660)) < 0){ printf("Failed to create the report\n"); exit(-1); } //printf("%d %d %llu %llu\n", s_prng->p, s_prng->q, s_prng->seed, s_prng->output); for (int i = 0; i < 100; i++){ char tmp[32]; snprintf(tmp, 32, "*** Test: %d ***\n", i); write(fd, "***************\n", 16); write(fd, tmp, strlen(tmp)); write(fd, "***************\n", 16); status = send_uart(&s_prng); int result = test_bbs(fd, s_prng->p, s_prng->q, s_prng->seed, s_prng->output); if (!result){ printf("Test %d: success\n", i); totalSuccess += 1; } else{ printf("Test %d: failed\n", i); totalFailed += 1; } memset(s_prng, 0, sizeof(struct prng)); } close(fd); printf("Summary: \n"); printf("\tSuccess: %d\n", totalSuccess); printf("\tFailed: %d\n", totalFailed); } static void stats_module(){ struct prng *s_prng = {0}; int status = 0; int fd; if ((fd = open("stats_stm32", O_CREAT | O_TRUNC | O_RDWR, 00760)) < 0){ printf("Failed to open the file\n"); perror("open()"); exit(-1); } printf("Retrieving random values...\n"); for (size_t i = 0; i < 100; i++){ status = send_uart(&s_prng); //printf("%d %d %llu %llu\n", s_prng->p, s_prng->q, s_prng->seed, s_prng->output); char str[32]; memset(str, 0, 32); snprintf(str, 32, "%llu", s_prng->output); write(fd, str, strlen(str)); write(fd, "\n", 1); } printf("finish to get random values\n"); close(fd); } int main(int argc, char *argv[]){ if (argc < 2){ printf("Please, specify the module to use: bbs or stats\n"); return -1; } if (strncmp(argv[1], "bbs", 5) == 0){ bbs_module(); } else if (strncmp(argv[1], "stats", 5) == 0){ stats_module(); } return 0; }