Skip to content
Snippets Groups Projects
Commit f7be9896 authored by Dragoș-Iulian ARGINT (94922)'s avatar Dragoș-Iulian ARGINT (94922)
Browse files

Add support for cancelation in checker


Signed-off-by: default avatarDragoș Iulian ARGINT <dragos.argint@stud.acs.upb.ro>
parent 4618891b
No related branches found
No related tags found
No related merge requests found
Pipeline #17977 passed
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h>
#include "uart16550.h" #include "uart16550.h"
...@@ -46,6 +47,15 @@ ...@@ -46,6 +47,15 @@
#define not_test(d, v, e, p) do_test((d), (v), (e), 1, 0, (p)) #define not_test(d, v, e, p) do_test((d), (v), (e), 1, 0, (p))
#define fatal_test(d, v, e,p) do_test((d), (v), (e), 0, 1, (p)) #define fatal_test(d, v, e,p) do_test((d), (v), (e), 0, 1, (p))
#define GENERIC_TEST_TIMEOUT 3
void sig_handler(int signum) {
fprintf(stderr, "Child process pid=%d of checker (that issues read/write syscalls to the driver) got killed after TIMEOUT=%ds\n", getpid(), GENERIC_TEST_TIMEOUT);
fprintf(stderr, "\tThis might be because you didn't implement read/write or there is a bug in the implementation\n");
exit(EXIT_FAILURE);
}
/* /*
* if the test passes it will return 0 * if the test passes it will return 0
* if it fails it returns the number of points given as argument * if it fails it returns the number of points given as argument
...@@ -328,8 +338,10 @@ copy_file(int fdr, int fdw, int len) ...@@ -328,8 +338,10 @@ copy_file(int fdr, int fdw, int len)
static int static int
copy_test(int fd0, int fd1, int speed_set) copy_test(int fd0, int fd1, int speed_set)
{ {
pid_t rpid, wpid; pid_t rpid, wpid, kpid;
int len, status, rc, fd; int len, status, fd;
int rc1, rc2, rc3, exit_status1, exit_status2, exit_status3;
int i;
len = gen_test_file(INFILE, speed_set); len = gen_test_file(INFILE, speed_set);
rpid = fork(); rpid = fork();
...@@ -360,17 +372,46 @@ copy_test(int fd0, int fd1, int speed_set) ...@@ -360,17 +372,46 @@ copy_test(int fd0, int fd1, int speed_set)
break; break;
} }
rc = waitpid(rpid, &status, 0); kpid = fork();
if (rc < 0) switch (kpid) {
return rc; case 0:
if (WEXITSTATUS(status)) for (i = 0; i < GENERIC_TEST_TIMEOUT; i++) {
return WEXITSTATUS(status); /*
* check if procs still exist. kill with arg 0
* will succed (ret 0) if the pid exists
*/
if (!kill(rpid, 0)) {
sleep(1);
continue;
} else if (!kill(wpid, 0)) {
sleep(1);
continue;
} else
break;
}
kill(rpid, SIGTERM);
kill(wpid, SIGTERM);
exit(EXIT_SUCCESS);
break;
default:
break;
}
rc1 = waitpid(rpid, &status, 0);
exit_status1 = WEXITSTATUS(status);
rc2 = waitpid(wpid, &status, 0);
exit_status2 = WEXITSTATUS(status);
rc3 = waitpid(kpid, &status, 0);
exit_status3 = WEXITSTATUS(status);
rc = waitpid(wpid, &status, 0); if (rc1 < 0 || rc2 < 0 || rc3 < 0 ||
if (rc < 0) exit_status1 || exit_status2 || exit_status3)
return rc; return -1;
if (WEXITSTATUS(status))
return WEXITSTATUS(status);
return system("diff " INFILE " " OUTFILE "> /dev/null 2> /dev/null"); return system("diff " INFILE " " OUTFILE "> /dev/null 2> /dev/null");
} }
...@@ -524,6 +565,7 @@ main(void) ...@@ -524,6 +565,7 @@ main(void)
float num_passed = 0; float num_passed = 0;
const int total = 92; const int total = 92;
signal(SIGTERM, sig_handler);
srand(time(NULL)); srand(time(NULL));
make_nodes(); make_nodes();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment