2006-07-01 21:26:01 +00:00
|
|
|
char buf[2048];
|
2006-06-27 14:35:53 +00:00
|
|
|
|
2006-07-11 17:39:45 +00:00
|
|
|
// simple fork and pipe read/write
|
|
|
|
|
2006-06-27 14:35:53 +00:00
|
|
|
void
|
|
|
|
pipe1()
|
|
|
|
{
|
|
|
|
int fds[2], pid;
|
2006-07-01 21:26:01 +00:00
|
|
|
int seq = 0, i, n, cc, total;
|
2006-06-27 14:35:53 +00:00
|
|
|
|
|
|
|
pipe(fds);
|
2006-07-01 21:26:01 +00:00
|
|
|
pid = fork();
|
2006-06-27 14:35:53 +00:00
|
|
|
if(pid == 0){
|
2006-07-01 21:26:01 +00:00
|
|
|
close(fds[0]);
|
|
|
|
for(n = 0; n < 5; n++){
|
|
|
|
for(i = 0; i < 1033; i++)
|
|
|
|
buf[i] = seq++;
|
|
|
|
if(write(fds[1], buf, 1033) != 1033){
|
|
|
|
puts("pipe1 oops 1\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(0);
|
2006-06-27 14:35:53 +00:00
|
|
|
} else {
|
2006-07-01 21:26:01 +00:00
|
|
|
close(fds[1]);
|
|
|
|
total = 0;
|
|
|
|
cc = 1;
|
|
|
|
while(1){
|
|
|
|
n = read(fds[0], buf, cc);
|
|
|
|
if(n < 1)
|
|
|
|
break;
|
|
|
|
for(i = 0; i < n; i++){
|
|
|
|
if((buf[i] & 0xff) != (seq++ & 0xff)){
|
|
|
|
puts("pipe1 oops 2\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
total += n;
|
|
|
|
cc = cc * 2;
|
|
|
|
if(cc > sizeof(buf))
|
|
|
|
cc = sizeof(buf);
|
2006-06-27 14:35:53 +00:00
|
|
|
}
|
2006-07-01 21:26:01 +00:00
|
|
|
if(total != 5 * 1033)
|
|
|
|
puts("pipe1 oops 3\n");
|
|
|
|
close(fds[0]);
|
2006-06-27 14:35:53 +00:00
|
|
|
}
|
|
|
|
puts("pipe1 ok\n");
|
|
|
|
}
|
|
|
|
|
2006-07-11 17:39:45 +00:00
|
|
|
// meant to be run w/ at most two CPUs
|
|
|
|
void
|
|
|
|
preempt()
|
|
|
|
{
|
|
|
|
int pid1, pid2, pid3;
|
|
|
|
int pfds[2];
|
|
|
|
|
|
|
|
pid1 = fork();
|
|
|
|
if(pid1 == 0)
|
|
|
|
while(1)
|
|
|
|
;
|
|
|
|
|
|
|
|
pid2 = fork();
|
|
|
|
if(pid2 == 0)
|
|
|
|
while(1)
|
|
|
|
;
|
|
|
|
|
|
|
|
pipe(pfds);
|
|
|
|
pid3 = fork();
|
|
|
|
if(pid3 == 0){
|
|
|
|
close(pfds[0]);
|
|
|
|
if(write(pfds[1], "x", 1) != 1)
|
|
|
|
puts("preempt write error");
|
|
|
|
close(pfds[1]);
|
|
|
|
while(1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(pfds[1]);
|
|
|
|
if(read(pfds[0], buf, sizeof(buf)) != 1){
|
|
|
|
puts("preempt read error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
close(pfds[0]);
|
|
|
|
kill(pid1);
|
|
|
|
kill(pid2);
|
|
|
|
kill(pid3);
|
|
|
|
wait();
|
|
|
|
wait();
|
|
|
|
wait();
|
|
|
|
puts("preempt ok\n");
|
|
|
|
}
|
|
|
|
|
2006-06-27 14:35:53 +00:00
|
|
|
main()
|
|
|
|
{
|
2006-07-11 17:39:45 +00:00
|
|
|
puts("usertests starting\n");
|
2006-07-12 09:10:25 +00:00
|
|
|
//pipe1();
|
|
|
|
preempt();
|
2006-06-27 14:35:53 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
;
|
|
|
|
}
|