Untitled
Never
#include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> void my_handler(int s){ char* h; exit(1); printf("%d\n",s); if (s==2){ printf("Deseja sair do programa? (S/N)"); scanf("%s",&h); } if (h=="s" || h=="S"){ exit(1); } else { return; } } void ALARMhandler(int sig) { signal(SIGALRM, SIG_IGN); /* ignore this signal */ exit(1); } void write_file(pid_t pid, int status, char msg[64]){ char file[64], file_name[64]; if (status == 1){ sprintf(file, "[pass] %s\n", msg); sprintf(file_name, "%d.txt", pid); FILE *file_ptr = fopen(file_name,"w"); fprintf(file_ptr,"%s",file); fclose(file_ptr); } else if (status == 66){ sprintf(file, "%s\n", msg); sprintf(file_name, "%d.txt", getpid()); FILE *file_ptr = fopen(file_name,"w"); fprintf(file_ptr,"%s",file); fclose(file_ptr); } } int main() { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); pid_t filho; int size = sizeof(all_tests)/sizeof(test_data); printf("Running %d tests:\n", size); printf("=====================\n\n"); pid_t *childs = malloc(sizeof(pid_t)*size); int pass_count = 0; for (int i = 0; i < size; i++) { filho = fork(); childs[i] = filho; if (filho==0){ signal(SIGALRM, ALARMhandler); if (all_tests[i].function() >= 0) { write_file(getpid(),1, all_tests[i].name); return 22; }; return 11; } } int i = 0; int *resp = malloc(sizeof(int)*size); int *resp_status = malloc(sizeof(int)*size); while (1){ int status; if ((childs[i] == waitpid(-1, &status, 0))){ printf("processo %d terminou com %d\n", childs[i], status ); if (status == 5632){ pass_count++; } resp[i] = childs[i]; resp_status[i] = status; childs[i] = 0; } int estatus =0; for (int b = 0; b < size; b++) { estatus+=childs[b]; } if (estatus==0){ break; } i++; i%=size; } for (int b = 0; b < size; b++) { char msg[99]; if (resp_status[b] == 5632 && WIFEXITED(resp_status[b])){ printf("(%d)%s: [PASS]\n", resp[b], all_tests[b].name); } else if (resp_status[b] == 2816) { printf("(%d)%s: [FAIL] com o status: %d (test assert)\n", resp[b], all_tests[b].name, resp_status[b]); sprintf(msg,"(%d)%s: [FAIL] com o status: %d (test assert)\n", resp[b], all_tests[b].name, resp_status[b]); //write_file(resp[b], 66, msg); } else if (resp_status[b] == 136){ printf("(%d)%s: [FAIL] com o status: %d (SIGSEGV)\n", resp[b], all_tests[b].name, resp_status[b]); sprintf(msg,"(%d)%s: [FAIL] com o status: %d (SIGSEGV)\n", resp[b], all_tests[b].name, resp_status[b]); //write_file(resp[b], 66, msg); } else { printf("(%d)%s: [FAIL] com o status: %s\n", resp[b], all_tests[b].name, strsignal(WIFSIGNALED(resp_status[b]))); sprintf(msg,"(%d)%s: [FAIL] com o status: %s\n", resp[b], all_tests[b].name, strsignal(WIFSIGNALED(resp_status[b]))); //write_file(resp[b], 66, msg); } } printf("\n\n=====================\n"); printf("%d/%d tests passed\n", pass_count, size); //pause(); return 0; }
Raw Text
-
zdfgzgsd
17 min ago
-
Punk'd Parody - MYLF
21 min ago
-
Valdez vs. Wilson Live Streams Free
32 min ago
-
fdssd dsdf dfsdsf dfs dfsdfsfds
46 min ago
-
Adult Telegram Channels
53 min ago
-
No Deposit Bonus
53 min ago
-
Makers CBD Gummies Reviews
54 min ago
-
MOFOS - Amy Amor Tells Jordi El His Idea Of What She Should Do On Her First Blind Date
1 hour ago
-
Untitled
1 hour ago
-
AllHerLuv - Videos
1 hour ago