Fix Result Report Race Condition in Pipe-based Context Switching Test (#42)

* Fix Result Report Race Condition in Pipe-based Context Switching Test

Ensure all report() calls yield correct information.

* Simplify code in Pipe-based Context Switching Test

Remove un-needed iter1 variable
This commit is contained in:
Clark Wierda 2016-10-07 00:56:46 -04:00 committed by Glenn Strauss
parent 34ecf4ec6a
commit 35efe5e575

View File

@ -94,9 +94,6 @@ char *argv[];
} }
} }
else { /* child process */ else { /* child process */
unsigned long iter1;
iter1 = 0;
/* slave, read p1 & write p2 */ /* slave, read p1 & write p2 */
close(p1[1]); close(p2[0]); close(p1[1]); close(p2[0]);
while (1) { while (1) {
@ -109,12 +106,12 @@ char *argv[];
perror("slave read failed"); perror("slave read failed");
exit(1); exit(1);
} }
if (check != iter1) { if (check != iter) {
fprintf(stderr, "Slave sync error: expect %lu, got %lu\n", fprintf(stderr, "Slave sync error: expect %lu, got %lu\n",
iter, check); iter, check);
exit(2); exit(2);
} }
if ((ret = write(p2[1], (char *)&iter1, sizeof(iter1))) != sizeof(check)) { if ((ret = write(p2[1], (char *)&iter, sizeof(iter))) != sizeof(check)) {
if ((ret == -1) && (errno == EPIPE)) { if ((ret == -1) && (errno == EPIPE)) {
alarm(0); alarm(0);
report(); /* does not return */ report(); /* does not return */
@ -123,7 +120,7 @@ char *argv[];
perror("slave write failed"); perror("slave write failed");
exit(1); exit(1);
} }
iter1++; iter++;
} }
} }
} }