more grind

This commit is contained in:
Robert Morris 2019-11-07 06:44:23 -05:00
parent 16b3b63f06
commit 20f1dd9409
2 changed files with 50 additions and 4 deletions

View file

@ -41,7 +41,7 @@ TOOLPREFIX := $(shell if riscv64-unknown-elf-objdump -i 2>&1 | grep 'elf64-big'
elif riscv64-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
then echo 'riscv64-linux-gnu-'; \
else echo "***" 1>&2; \
echo "*** Error: Couldn't find an riscv64 version of GCC/binutils." 1>&2; \
echo "*** Error: Couldn't find a riscv64 version of GCC/binutils." 1>&2; \
echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
echo "***" 1>&2; exit 1; fi)
endif

View file

@ -48,13 +48,17 @@ rand(void)
}
void
go()
go(int which_child)
{
int fd = -1;
static char buf[999];
char *break0 = sbrk(0);
uint64 iters = 0;
while(1){
iters++;
if((iters % 500) == 0)
write(1, which_child?"B":"A", 1);
int what = rand() % 20;
if(what == 1){
close(open("a", O_CREATE|O_RDWR));
@ -76,8 +80,12 @@ go()
read(fd, buf, sizeof(buf));
} else if(what == 9){
mkdir("a");
close(open("a/a", O_CREATE|O_RDWR));
unlink("a/a");
} else if(what == 10){
mkdir("b");
close(open("b/b", O_CREATE|O_RDWR));
unlink("b/b");
} else if(what == 11){
unlink("b");
link("a", "b");
@ -88,6 +96,9 @@ go()
int pid = fork();
if(pid == 0){
exit(0);
} else if(pid < 0){
printf("grind: fork failed\n");
exit(1);
}
wait(0);
} else if(what == 14){
@ -96,6 +107,9 @@ go()
fork();
fork();
exit(0);
} else if(pid < 0){
printf("grind: fork failed\n");
exit(1);
}
wait(0);
} else if(what == 15){
@ -108,6 +122,9 @@ go()
if(pid == 0){
close(open("a", O_CREATE|O_RDWR));
exit(0);
} else if(pid < 0){
printf("grind: fork failed\n");
exit(1);
}
kill(pid);
wait(0);
@ -116,8 +133,34 @@ go()
if(pid == 0){
kill(getpid());
exit(0);
} else if(pid < 0){
printf("grind: fork failed\n");
exit(1);
}
wait(0);
} else if(what == 19){
int fds[2];
if(pipe(fds) < 0){
printf("grind: pipe failed\n");
exit(1);
}
int pid = fork();
if(pid == 0){
fork();
fork();
if(write(fds[1], "x", 1) != 1)
printf("grind: pipe write failed\n");
char c;
if(read(fds[0], &c, 1) != 1)
printf("grind: pipe read failed\n");
exit(0);
} else if(pid < 0){
printf("grind: fork failed\n");
exit(1);
}
close(fds[0]);
close(fds[1]);
wait(0);
}
}
}
@ -125,6 +168,9 @@ go()
int
main()
{
unlink("a");
unlink("b");
int pid1 = fork();
if(pid1 < 0){
printf("grind: fork failed\n");
@ -132,7 +178,7 @@ main()
}
if(pid1 == 0){
rand_next = 31;
go();
go(0);
exit(0);
}
@ -143,7 +189,7 @@ main()
}
if(pid2 == 0){
rand_next = 7177;
go();
go(1);
exit(0);
}