Skip to content

Commit

Permalink
Merge pull request #30 from ZhengjunXing/fix_context_switch1
Browse files Browse the repository at this point in the history
Fix "Assertion `ret == 1' failed" in context_switch1.c
  • Loading branch information
antonblanchard authored Jan 6, 2021
2 parents 566ada2 + e795898 commit 6b6f1f6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/context_switch1.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@ static void *child(void *arg)

void testcase(unsigned long long *iterations, unsigned long nr)
{
struct args a;
struct args *a;
char c;
int ret;
a = malloc(sizeof(struct args));
assert(pipe(a->fd1) == 0);
assert(pipe(a->fd2) == 0);

assert(pipe(a.fd1) == 0);
assert(pipe(a.fd2) == 0);

new_task(child, &a);
new_task(child, a);

while (1) {
do {
ret = write(a.fd1[WRITE], &c, 1);
ret = write(a->fd1[WRITE], &c, 1);
} while (ret != 1 && errno == EINTR);
assert(ret == 1);

do {
ret = read(a.fd2[READ], &c, 1);
ret = read(a->fd2[READ], &c, 1);
} while (ret != 1 && errno == EINTR);
assert(ret == 1);

(*iterations) += 2;
}

free(a);
}

0 comments on commit 6b6f1f6

Please sign in to comment.